Shellshock

On this page 7

Shellshock is the name given to a family of remote code execution flaws in GNU Bash, disclosed in September 2014, in which the shell executed commands that followed a function definition stored in an environment variable. Among the best-known vulnerabilities in cybersecurity, it is tracked primarily as CVE-2014-6271, with follow-up identifiers CVE-2014-7169, CVE-2014-7186, CVE-2014-7187, CVE-2014-6277 and CVE-2014-6278.

The flaw had existed in Bash for roughly 25 years before discovery, and it became dangerous because many network services passed attacker-controlled input into environment variables before invoking a shell. Its maximum CVSS base score of 10.0 reflected trivial exploitation, no authentication and complete system compromise.

How Shellshock abuses Bash function export

Shellshock arises from the way Bash exports shell functions to child processes. Bash allowed a function to be passed to a subshell by placing its body in an environment variable whose value began with the characters () {, and the child Bash process parsed every such variable at startup to recreate the function.

The parser did not stop at the closing brace of the function. Any trailing commands after the definition were executed immediately while the new shell initialized, before any script logic ran. A variable such as X='() { :; }; /bin/id' therefore caused the command /bin/id to run in every Bash process that inherited it.

The essential precondition is a trust boundary crossing: a remote party controls the value of an environment variable, and some component later starts Bash with that environment. The variable name is irrelevant, which is why HTTP headers, DHCP options and SSH parameters all became viable injection channels.

The following table summarizes the stages of a typical exploitation chain.

StageWhat happensExample
Input captureA service receives attacker-supplied dataHTTP User-Agent header
Environment mappingThe data is copied into an environment variableCGI sets HTTP_USER_AGENT
Shell invocationA Bash process starts with that environmentCGI script or system() call
Function importBash parses the () { prefix as a functionDefinition is recreated
Trailing executionCommands after the definition runReverse shell or downloader
Stages of a Shellshock exploitation chain

The CVE identifiers in the Shellshock family

Shellshock is not one bug but a cluster of related parser flaws. The first patch for CVE-2014-6271 was incomplete, and researchers quickly found further ways to reach dangerous behavior in the same function-import code, which produced several additional CVE entries within days.

The table lists the main identifiers and their nature. Severity scores were revised over time, so the values describe the general class rather than a fixed rating.

IdentifierNature of the flawImpact class
CVE-2014-6271Commands after a function definition are executedRemote code execution
CVE-2014-7169Incomplete fix allowed file writes and command runsRemote code execution
CVE-2014-7186Out-of-bounds access with nested here-documentsCrash, possible corruption
CVE-2014-7187Off-by-one error in nested loop parsingCrash, possible corruption
CVE-2014-6277Uninitialized memory use in function parsingPotential code execution
CVE-2014-6278Parser accepted further crafted definitionsRemote code execution
Main identifiers in the Shellshock family

The durable fix changed the design rather than the parser alone. Patched Bash versions only import functions from variables with a distinctive name prefix and suffix, such as BASH_FUNC_name%%, so arbitrary variables such as HTTP headers can no longer be interpreted as function definitions.

Attack vectors and exposed systems

Exposure depended on whether a reachable service passed remote data into a Bash environment. A vulnerable Bash binary alone was not remotely exploitable; the risk came from the surrounding software and its configuration.

The most exploited vector was CGI on web servers, because the CGI specification maps request headers directly into environment variables. Embedded devices were heavily affected as well, since many routers, network-attached storage units and industrial controllers used shell-based CGI scripts and were rarely patched.

VectorPreconditionTypical exposure
Web CGI scriptsScript or helper runs under BashHigh, widely scanned
DHCP clientsClient hook scripts use BashLocal network attacker
OpenSSH forced commandsForceCommand with Bash as login shellAuthenticated users only
Mail serversDelivery filters invoke Bash with header dataConfiguration dependent
Embedded web panelsFirmware uses Bash for CGIHigh, slow patching
Common Shellshock attack vectors

Attackers began mass internet scanning within hours of disclosure. Payloads ranged from simple probes that requested a callback to droppers that installed botnet malware for DDoS attacks and cryptocurrency mining.

Shellshock compared with other landmark vulnerabilities

Shellshock is often discussed alongside Heartbleed and Log4Shell because all three affected ubiquitous components that defenders did not inventory well. Their mechanisms and consequences differ significantly.

VulnerabilityComponentWeakness typePrimary impact
ShellshockGNU BashCommand injection via parserRemote code execution
HeartbleedOpenSSLMissing bounds checkMemory disclosure
Log4ShellApache Log4jUnsafe lookup and JNDI loadingRemote code execution
EternalBlueWindows SMBv1Buffer overflowRemote code execution, worms
Shellshock versus related high-profile flaws

In CWE terms, Shellshock is usually mapped to CWE-78, OS command injection, because data crosses into command execution without neutralization. Unlike a memory-safety bug such as a buffer overflow, it requires no exploit engineering, which explains its rapid weaponization.

Detection, remediation and lasting lessons

The primary remediation is to upgrade Bash to a patched release supplied by the operating system vendor. A widely used local test sets a crafted variable and starts Bash: env x='() { :;}; echo vulnerable' bash -c 'echo test' prints the word vulnerable only on an unpatched shell.

  • Inventory every Bash instance, including firmware, containers and appliance images, not only general-purpose servers.
  • Remove or disable unused CGI scripts and avoid /bin/sh links to Bash where a minimal shell such as dash is sufficient.
  • Deploy web application firewall rules that block the () { pattern as a temporary compensating control, not a fix.
  • Review logs for probe signatures in headers such as User-Agent, Referer and Cookie to identify past compromise.

A common mistake was treating the first patch as final. Teams that stopped after CVE-2014-6271 remained exposed to the follow-up identifiers, which shows why vulnerability management must track advisories until vendors declare the issue closed. Shellshock still appears in scans of neglected embedded devices, making it a frequent example of a long-lived N-day vulnerability.

Put simply

Bash is a program that reads and carries out text commands on many Linux and Unix computers. Shellshock was a mistake in how Bash read certain settings handed to it when it started. If someone hid an extra command at the end of one of those settings, Bash simply ran it.

Many websites and devices copied visitor details, such as the browser name, into those settings. An attacker could therefore send a single web request and take control of the machine. The fix was to update Bash so that it no longer trusts such settings.

In practice

A regional internet provider ran an older monitoring portal on a Linux server, and the portal used a Bash-based CGI script to display network status. Two days after the September 2014 disclosure, the security team saw web log entries with User-Agent values beginning with () { :; }; followed by wget commands that tried to download a botnet client.

The team confirmed the server was vulnerable with the standard env test, then blocked the pattern at the reverse proxy while the operating system package was updated. Because the first update covered only CVE-2014-6271, they repeated the upgrade when fixes for CVE-2014-7169 and later identifiers appeared. A file integrity review found no successful compromise, and the provider then retired the CGI portal and audited 40 customer routers that shipped with the same shell.