Guides / Famous CVEs

Shellshock (CVE-2014-6271 and follow-ups): bash runs code from environment variables

beginnerUpdated 26 Nov 2026842 words

In September 2014 it became public that bash, the default shell on most Linux systems, executed commands it found after a function definition in an environment variable. Any program that put untrusted text into an environment variable and then started bash handed that text to the shell. Web servers running CGI scripts did this for every request.

What broke

Bash can pass functions to child processes through the environment. In 2014 it did this with a plain variable whose value started with () {. When a new bash started, it scanned its environment for such values and evaluated them to recreate the functions.

The evaluation did not stop at the end of the function. Text after the closing brace ran as a command:

env x='() { :;}; echo vulnerable' bash -c 'echo this is a test'

A vulnerable bash prints vulnerable before this is a test. The CVE record of CVE-2014-6271 describes it as processing "trailing strings after function definitions in the values of environment variables".

Who was affected

Every system with GNU Bash through 4.3, which in 2014 meant nearly every Linux distribution and macOS. An attack needed a path from the attacker to an environment variable to bash. The CVE record names three:

Path How
CGI scripts under Apache mod_cgi and mod_cgid The web server passes request headers as environment variables (HTTP_USER_AGENT, HTTP_COOKIE). A CGI script written in bash, or one that called system() on a system where /bin/sh is bash, ran the attacker command with one HTTP request.
OpenSSH ForceCommand Restricted accounts, such as Git hosting accounts, could escape their forced command through SSH_ORIGINAL_COMMAND.
DHCP clients that pass server options to a shell script A rogue DHCP server on the local network could run commands as root.

Debian and Ubuntu use dash as /bin/sh, which limited the system() path there; RHEL-family systems use bash as /bin/sh.

Sudo and cron also pass data to programs through the environment. Code that reads environment variables has to treat them as input from whoever set them.

Six CVEs in one week

The first patch blocked the published input but left the parser behind it as it was. Researchers who read that parser found more:

CVE Problem KEV
CVE-2014-6271 commands after a function definition run added 2022-01-28
CVE-2014-7169 the first fix (bash43-025) was incomplete added 2022-01-28
CVE-2014-6277 parser flaw in function import, memory corruption
CVE-2014-6278 parser flaw in function import, command execution added 2025-10-02
CVE-2014-7186 out-of-bounds access with many here documents ("redir_stack")
CVE-2014-7187 off-by-one with deeply nested loops ("word_lineno")

The CVE records date the publications from 2014-09-24 to 2014-09-30. The last four affect bash through patch bash43-026.

CISA added CVE-2014-6278 to the KEV list in October 2025, eleven years after disclosure. A scanner can therefore report a CVE from 2014 as new on KEV.

An attack request

One request to a CGI script was enough:

GET /cgi-bin/status.cgi HTTP/1.1
User-Agent: () { :;}; /bin/bash -c 'id > /tmp/pwned'

Apache set HTTP_USER_AGENT to that string and started the script, and bash ran the command while starting up, before the script did anything.

How to check a system

Run the test above as a normal user. On a fixed bash (Debian 12, bash 5.2.15) it prints only:

this is a test

Older patched versions may also print warnings such as bash: warning: x: ignoring function definition attempt. A line that says vulnerable means the bash on that system needs an update.

Check the version as well with bash --version | head -1.

Unpatched bash still turns up on:

  • old appliances, NAS boxes and routers with their own firmware;
  • containers built from very old base images.

CGI scripts written in shell, and system() calls with strings built from requests, are risky even with a fixed bash. Find the CGI scripts that still exist with ls /usr/lib/cgi-bin /var/www/cgi-bin 2>/dev/null.

How it was fixed

Bash maintainer Chet Ramey published a series of patches for bash 4.3 and older branches. The fix that lasted changed how functions travel through the environment: bash exports a function under a special name with a prefix and suffix, and imports only those names:

x() { echo hi; }; export -f x; env | grep -A1 BASH_FUNC
BASH_FUNC_x%%=() {  echo hi
}

Bash never parses an ordinary variable such as HTTP_USER_AGENT as a function, whatever it contains. That closed the whole class of bugs, where the earlier patches had closed one parser flaw at a time.

Sources

Check your servers every day

The Vulnpocalypse agent reports the packages and settings of a server once a day, and the digest lists what to fix, most urgent first.

Start free