题目来源:BUUCTF [网鼎杯 2020 青龙组]AreUSerialz
目录
一、打开靶机,整理信息
直接得到一串php代码,根据题目可以看到还有序列化
二、解题思路
step 1:代码审计
<?php
include("flag.php");
highlight_file(__FILE__);
class FileHandler { //创建FileHandler类
//定义了三个受保护的属性
protected $op;
protected $filename;
protected $content;
//构造函数,对三个受保护的属性进行初始化,然后调用process()方法
function __construct() {
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
$this->process();
}
//定义公共的成员方法,并根据$this->op的值来执行不同的操作
public function process() {
if($this->op == "1") {
$this->write(); //值为1,则调用write方法进行文件写入操作
} else if($this->op == "2") {
$res = $this->read(); //值为2,则调用read方法读取文件内容,并将结果传递给output方法输出
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}
//定义公共的成员方法
private function write() {
if(isset($this->filename) && isset($this->content)) { //检查二者是否都已设置
if(strlen((string)$this->content) > 100) { //经检查$thie->content的长度
$this->output("Too long!&