反序列化[CISCN2019 华北赛区 Day1 Web1]Dropbox
1.注册登录后页面如下
2.猜测是文件上传,多测尝试以后发现后端直接讲我们的文件后缀进行了改写,无法执行脚本
3.题目提示了一个phar,应该是利用phar协议读取文件,触发反序列化读写flag文件。然而,想用phar协议读写文件需要满足这几个条件。
phar文件要能够上传到服务器端。
要有可用的魔术方法作为“跳板”。
文件操作函数的参数可控,且:、/、phar等特殊字符没有被过滤。
注意: 所指的phar文件不一定需要文件后缀名必须是.phar。而是文件的结构必须满足phar文件的结构
4.需要可用的魔术方法 做跳板就必须白盒测试,看源代码写payload。题目应该是有什么隐藏的链接,或者需要目录扫描。
5.到处查看一遍后发现存在任意文件下载
6.使用filename=…/…/index.php这个文件名可以查看源码文件
7.找到源码就找高危函数和可以触发phar协议的函数
8.class.php文件中发现这两个函数
class User {
public $db;
public function __construct() {
global $db;
$this->db = $db;
}
public function user_exist($username) {
$stmt = $this->db->prepare("SELECT `username` FROM `users` WHERE `username` = ? LIMIT 1;");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
$count = $stmt->num_rows;
if ($count === 0) {
return false;
}
return true;
}
public function add_user($username, $password) {
if ($this->user_exist($username)) {
return false;
}
$password = sha1($password . "SiAchGHmFx");
$stmt = $this->db->prepare("INSERT INTO `users` (`id`, `username`, `password`) VALUES (NULL, ?, ?);");
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
return true;
}
public function verify_user($username, $password) {
if (!$this->user_exist($username)) {
return false;
}
$password = sha1($password . "SiAchGHmFx");
$stmt = $this->db