UNION SELECT IN MSSQL
点击次数:29 次 发布日期:2008-11-29 17:48:03 作者:源代码网
|
源代码网推荐
文/ 安全天使·SuperHei[BST]
union查询可以说给了sql注射的一片新的天空,mysql和acc里都可以发挥很大的作用,那么在mssql里会是怎样呢? 其实我很早就开始测试mssql里的union,不过我犯了个很大的错误,以为在mssql里的union会受"数据类型转换错误"的影响,而不可以很好的完成替换工作,实际上是我错了。这里感谢xiaolu的提醒,THX。
以知 数据表master.dbo.spt_values的列如下: name (nvarchar(35).null) number(int,not null) type(nchar(3),not Null) low(int, Null) high(int,Null) status(int, Null)
我们查询语句: select type from dbo.spt_values where name="rpc";
返回: type A 查询: select type from dbo.spt_values where name="rpc" union select 111;
返回:
服务器: 消息 245,级别 16,状态 1,行 1 将 nvarchar 值 "A " 转换为数据类型为 int 的列时发生语法错误。
看到了没?这个就是"数据类型转换错误",我就是看到这个才犯错误的:( 我们看看什么语句union前面的部分 select type from dbo.spt_values where name="rpc" 由于name="rpc"存在 返回的type的类型为nchar 而union后面的 select 111返回的是数据类型为int,所以在union查询时就出现了上面的错误。
如果我们union前面的那个selet查询的记录不存在,将会怎么样呢。 我们查询语句: select type from dbo.spt_values where name="rpcssdfsdfsdfds" union select 111; 或select type from dbo.spt_values where name="rpc" and 1=2 union select 111;
上面的语句里name="rpcssdfsdfsdfds"根本不存在 呵呵 这下就没有错误了 成功得到结果:
type 111
下面我们在测试一个语句:select type,name from dbo.spt_values where name="rpc" union select 111;(union前面的查询输出type和name 2个字段) 得到错误: 服务器: 消息 205,级别 16,状态 1,行 1 包含 UNION 运算符的 SQL 语句中的所有查询都必须在目标列表中具有相同数目的表达式。
哈哈~~ 大家对这个应该错误很熟悉了把。union查询前后字段不对。什么的语句我们改为: select type,name from dbo.spt_values where name="rpc" union select 111,111; (使前后2个查询字段一样) 成功得到结果: type name 111 111
同样语句 select * from dbo.spt_values where name="rpc" union select 1,1,1,1,1,1; 因为在表spt_values里有6个字段,所以union后面的查询必须要有6个字段。
呵呵,其实这个问题在mysql注射文章里写union查询的时候已经提过的,这里只是重新拿出来说明下。
小结下: 对于语句select A union select B (A和B不同数据表查询) 1.union查询必修是B里的字段要和A一样。 2.在mssq里的union查询如果前面查询A如果数据存在 那么不会象mysql里一样输出 前面查询A的数据,而是出现"将 nvarchar 值 "A " 转换为数据类型为 int 的列时发生语法错误"这样的错误。 其实在注射中,我们的目的是要求得到语句B的返回结果,使用union查询替换输出必需保证语句A得到的结果为空,这个不管是mysql,access还是mssql都是一样的。 所以我们采用 在注射的id后面加个 and 1=2 如: _blank>http://www.xxx.netVideoPlay.asp?VideoID=1995 and 1=2 union select 1,1,1,1.........这样的形式,这个和mysql和acc的使用union语句是一样的,这样如果我们精心构造我们的语句就可以使注射通用于acc,mysql>4.0,mssql或所有支持union的数据类型。
那么我们的注射工具的编写将有一个新的开始,幸运的死casi本来就是采用union的 在实际测试用他也可以用与access,mssql,mysql的注射。如下图:
_17.jpg" target=_blank>
源代码网整理以下 |
源代码网供稿.