导航

心动吧黑客BLOG

自发研究:须要多维思想而且要想不可能为可能的人才能做到

« sql注入 盲注 union select注入数据库语句大全之联合语句UNION »

union select IN MSSQL

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 如:



upload/200902251338582042.gif" target="_blank">

原创文章如转载,请注明:转载自心动吧黑客BLOG [ http://www.abcxd.com/abcxd/ ]

本文链接地址:http://www.abcxd.com/abcxd/abcxdArticle/SQLoday/union-select1.html

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

黑客榜之热文排行

黑客榜之本年排行

黑客榜之本月排行

黑客榜之随机文章

网站分类

搜索内容

最新评论及回复

最近发表

所属分类下的文章

日历

Copyright ⊙ 2004-2009 心动吧 UrL:ABCXD.CoM All RiGhts Reserved