250 lines
9.4 KiB
Markdown
250 lines
9.4 KiB
Markdown
# HTB Agent Handoff — next target: INSANE-difficulty machine
|
|
|
|
Read this fully before starting. It documents a **working, proven setup** from
|
|
the previous engagement (HTB box "Cap", fully owned: user + root flags) on this
|
|
VPS. Reuse it — do not rebuild the tooling.
|
|
|
|
## Mission
|
|
|
|
The human is playing HackTheBox. They will give you:
|
|
|
|
- a fresh `.ovpn` config URL (usually `https://files.catbox.moe/XXXX.ovpn`), and
|
|
- the target machine IP (`10.129.x.x`).
|
|
|
|
Your job: fully compromise the machine and return **two 32-hex flags**:
|
|
|
|
- **User flag** — usually `/home/<user>/user.txt` (Linux) or
|
|
`C:\Users\<user>\Desktop\user.txt` (Windows)
|
|
- **Root flag** — `/root/root.txt` (Linux) or `C:\Users\Administrator\Desktop\root.txt` (Windows)
|
|
|
|
The machine is rated **INSANE**. Expect: long multi-stage chains, no single
|
|
"one-liner" exploit, decoy/red-herring services, credential reuse across
|
|
services, possibly heavy filtering or unusual ports, and privesc that requires
|
|
chaining several small weaknesses. Methodical enumeration wins; do not give up
|
|
after the first dead end. Budget several distinct escalation attempts.
|
|
|
|
Flag delivery: you CANNOT submit flags yourself (no HTB web session). Report
|
|
the two flag strings to the human — they paste them into the HTB web interface:
|
|
|
|
- **"Submit User Flag"** box → user flag
|
|
- **"Submit Root Flag"** box → root flag
|
|
- **"Submit Rating"** is optional (human rates difficulty); not needed to complete.
|
|
|
|
If the machine gets reset mid-engagement, the flags CHANGE — re-capture them
|
|
after any reset before reporting.
|
|
|
|
## Environment facts (verified working)
|
|
|
|
- ZCode's Bash tool runs as user `antonn` (uid 1001) in a sandbox with
|
|
`no_new_privileges` and **zero capabilities** (`CapEff: 0`). Consequences:
|
|
- `sudo` and `su` are **impossible** from the Bash tool, even with
|
|
`dangerouslyDisableSandbox: true`.
|
|
- The docker socket (`/var/run/docker.sock`) is root:docker — no access.
|
|
- Direct internet works (curl, downloads), but there is **no route to the
|
|
HTB lab network** from the sandbox itself.
|
|
- The host VPS is `srv992964` (public IP 89.116.39.250, Debian 13). It is a
|
|
**production server** (ADPanel panel + Pterodactyl game servers + MySQL on
|
|
localhost). Do not break it: no destructive commands, no wiping, pentest
|
|
tooling only, clean up background processes when done.
|
|
- Root on the VPS is available via **SSH to localhost** (sshd runs as root, so
|
|
it can grant privileges regardless of the sandbox's no_new_privileges).
|
|
|
|
## The root-SSH tool: `/tmp/sshrun.py`
|
|
|
|
Purpose-built helper: runs `ssh root@127.0.0.1` under a pty and feeds the
|
|
password automatically (password auth needs a TTY; plain pipes don't work).
|
|
|
|
**Root password for the VPS:** `AntonioVatafu21!` (owner-provided; sensitive —
|
|
do not exfiltrate anywhere, and do not change it).
|
|
|
|
Usage:
|
|
|
|
```bash
|
|
# run a command as root on the VPS (single quoted arg = remote command)
|
|
python3 /tmp/sshrun.py 'apt-get install -y nmap; nmap --version'
|
|
|
|
# raw ssh args mode (everything after -- goes to ssh verbatim, e.g. tunnels)
|
|
python3 /tmp/sshrun.py -- -N -L 127.0.0.1:18080:10.129.x.x:80 # run in background!
|
|
```
|
|
|
|
Notes:
|
|
|
|
- Every call prints one line `root@127.0.0.1's password:` first — ignore it.
|
|
- Internal deadline is **600 s** per call. For longer work (big nmap scans,
|
|
slow exploits) background it on the VPS and poll, e.g.:
|
|
|
|
```bash
|
|
python3 /tmp/sshrun.py 'nohup nmap -Pn -p- --min-rate 3000 -T4 --open 10.129.x.x -oN /tmp/allports.txt >/tmp/scan.log 2>&1 & echo started'
|
|
# ...then later:
|
|
python3 /tmp/sshrun.py 'cat /tmp/allports.txt'
|
|
```
|
|
|
|
- If `/tmp/sshrun.py` was wiped (reboot / tmp cleaner), recreate it from the
|
|
source at the bottom of this file with the Write tool, `chmod +x`.
|
|
|
|
## VPN to the lab (openvpn on the VPS)
|
|
|
|
Installed and proven: `openvpn 2.6.14`, `nmap 7.95`, `sshpass`, all on the VPS.
|
|
Config from last session is at `/root/htb.ovpn` — **but each machine session
|
|
needs the human's fresh ovpn** (HTB ties configs to sessions; always download
|
|
the new one the human gives you).
|
|
|
|
Start/refresh procedure (run as root via the helper):
|
|
|
|
```bash
|
|
# 1. kill any previous tunnel (one active connection per HTB account)
|
|
python3 /tmp/sshrun.py 'pkill -f "openvpn --config" ; sleep 2; ip link del tun0 2>/dev/null; true'
|
|
|
|
# 2. upload the new config (base64 inline — avoids needing file transfer)
|
|
B64=$(base64 -w0 /tmp/new.ovpn)
|
|
python3 /tmp/sshrun.py "echo $B64 | base64 -d > /root/htb.ovpn"
|
|
|
|
# 3. start it
|
|
python3 /tmp/sshrun.py 'openvpn --config /root/htb.ovpn --daemon --log /root/openvpn.log; sleep 8; ip -br addr | grep tun'
|
|
|
|
# expect: tun0 10.10.14.x/23 and "Initialization Sequence Completed" in /root/openvpn.log
|
|
```
|
|
|
|
**Only scan the target IP the human gave you** — HTB forbids scanning the rest
|
|
of the lab subnet.
|
|
|
|
## Proven workflow
|
|
|
|
1. **Reachability + full TCP scan** (via VPS):
|
|
|
|
```bash
|
|
python3 /tmp/sshrun.py 'nmap -Pn -p- --min-rate 3000 -T4 --open 10.129.x.x -oN /tmp/allports.txt; cat /tmp/allports.txt'
|
|
```
|
|
|
|
For an INSANE box also do: UDP top-100 (`nmap -Pn -sU --top-ports 100 ...`),
|
|
`-sV -sC` + `--version-all` on every open port, and script scans
|
|
(`--script=vuln` selectively). Insane boxes often hinge on an obscure port
|
|
or version.
|
|
|
|
2. **Web targets — tunnel to the sandbox** (much nicer to explore than curl on
|
|
the VPS):
|
|
|
|
```bash
|
|
python3 /tmp/sshrun.py -- -N -L 127.0.0.1:18080:10.129.x.x:80 # background task
|
|
# then locally: curl -s http://127.0.0.1:18080/
|
|
```
|
|
|
|
(Previous session used local port 18080; pattern generalizes to any port,
|
|
and to remote forwarding `-R` if you need to serve a listener back.)
|
|
|
|
3. **Credential hygiene**: any creds found (pcaps, configs, backups, web
|
|
content, SMTP/FTP exposures) — try them on **every other service**
|
|
(FTP↔SSH↔web↔DB). On Cap the FTP creds were the SSH creds. Spraying the
|
|
same password across users/services is standard here.
|
|
|
|
4. **Foothold → user flag**: stabilise shell over sshpass:
|
|
`sshpass -p 'PASS' ssh -o StrictHostKeyChecking=no user@10.129.x.x '...'`
|
|
(run via the root helper). Read `user.txt`.
|
|
|
|
5. **Privesc checklist** (Linux — iterate through ALL of it before concluding):
|
|
|
|
- `getcap -r / 2>/dev/null` — Cap's root was `cap_setuid` on python3.8
|
|
(`python3.8 -c "import os; os.setuid(0); os.system('/bin/sh')"`). Insane
|
|
boxes may chain capabilities with something else.
|
|
- `sudo -l` (watch for GTFOBins and for *environment variables* like
|
|
`env_keep`, LD_PRELOAD paths)
|
|
- SUID/SGID: `find / -perm -4000 -o -2000 2>/dev/null` → GTFOBins
|
|
- cron/systemd timers: `cat /etc/crontab; ls /etc/cron*; systemctl list-timers`
|
|
- writable files of root-owned services, PATH hijacks, NFS `no_root_squash`,
|
|
`/etc/fstab` quirks, docker/lxd group membership, kernel version exploits
|
|
(Ubuntu version from ssh banner), internal-only services
|
|
(`ss -tlnp` on target), history files, SSH keys in /home, backups
|
|
(.bak, .old, /var/backups), and **source-code review of custom binaries**
|
|
(`strings`, or copy back through the tunnel and decompile).
|
|
- Windows (if it's a Windows box): WinPEAS, always-install-elevated,
|
|
unquoted service paths, tokens (SeImpersonate → PrintSpoofer/GodPotah),
|
|
stored creds, AD attack paths if the box is domain-joined.
|
|
|
|
6. **Root flag**: `/root/root.txt` (or Windows equivalent). Report BOTH flags
|
|
to the human verbatim, clearly labelled.
|
|
|
|
## Post-engagement cleanup
|
|
|
|
```bash
|
|
# stop VPN + any listeners/scans when the human is done or machine expires
|
|
python3 /tmp/sshrun.py 'pkill -f "openvpn --config"; pkill nmap; true'
|
|
```
|
|
|
|
Stop any background Bash tasks you started (tunnels) with TaskStop.
|
|
|
|
## Appendix: `/tmp/sshrun.py` full source (recreate verbatim if missing)
|
|
|
|
```python
|
|
#!/usr/bin/env python3
|
|
"""Run ssh as root on localhost, feeding the password over a pty.
|
|
Usage:
|
|
sshrun.py 'remote command'
|
|
sshrun.py -- -N -L 8080:host:80 (args after -- go to ssh verbatim)
|
|
"""
|
|
import pty, os, sys, time, select
|
|
|
|
PASSWORD = "AntonioVatafu21!"
|
|
|
|
args = sys.argv[1:]
|
|
if args and args[0] == "--":
|
|
ssh_args = args[1:]
|
|
else:
|
|
ssh_args = args
|
|
|
|
argv = [
|
|
"ssh", "-o", "StrictHostKeyChecking=no",
|
|
"-o", "UserKnownHostsFile=/dev/null",
|
|
"-o", "LogLevel=ERROR",
|
|
"-o", "PreferredAuthentications=password,keyboard-interactive",
|
|
"-o", "PubkeyAuthentication=no",
|
|
"-o", "ConnectTimeout=15",
|
|
"-o", "ServerAliveInterval=30",
|
|
"root@127.0.0.1",
|
|
] + ssh_args
|
|
|
|
pid, fd = pty.fork()
|
|
if pid == 0:
|
|
os.execvp(argv[0], argv)
|
|
|
|
buf = b""
|
|
sent = False
|
|
status = None
|
|
deadline = time.time() + 600
|
|
while time.time() < deadline:
|
|
r, _, _ = select.select([fd], [], [], 0.5)
|
|
if fd in r:
|
|
try:
|
|
data = os.read(fd, 4096)
|
|
except OSError:
|
|
break
|
|
if not data:
|
|
break
|
|
buf += data
|
|
sys.stdout.buffer.write(data)
|
|
sys.stdout.buffer.flush()
|
|
if not sent and b"password" in buf.lower():
|
|
os.write(fd, (PASSWORD + "\n").encode())
|
|
sent = True
|
|
wpid, st = os.waitpid(pid, os.WNOHANG)
|
|
if wpid == pid:
|
|
status = st
|
|
break
|
|
|
|
# drain remaining output
|
|
try:
|
|
while True:
|
|
r, _, _ = select.select([fd], [], [], 0.5)
|
|
if fd not in r:
|
|
break
|
|
data = os.read(fd, 4096)
|
|
if not data:
|
|
break
|
|
sys.stdout.buffer.write(data)
|
|
sys.stdout.buffer.flush()
|
|
except OSError:
|
|
pass
|
|
if status is None:
|
|
_, status = os.waitpid(pid, 0)
|
|
sys.exit((status >> 8) if os.WIFEXITED(status) else 1)
|
|
```
|