Shellshock (CVE-2014-6271 and follow-ups): bash runs code from environment variables
In September 2014 it turned out 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 was nearly every Linux distribution and macOS. The bug needed a path from an attacker to an environment variable to bash. The CVE record names three:
- CGI scripts under Apache
mod_cgiandmod_cgid. The web server passes request headers as environment variables (HTTP_USER_AGENT,HTTP_COOKIE). A CGI script written in bash, or one that calledsystem()on a system where/bin/shis bash, ran the attacker command with one HTTP request. - OpenSSH
ForceCommand: restricted accounts, such as Git hosting accounts, could escape their forced command throughSSH_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.
Six CVEs in one week
The first patch was incomplete, and researchers who now read the parser closely 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.
CVE-2014-6278 shows that old bugs stay relevant: CISA added it to the KEV list eleven years after disclosure.
How the attack worked, in plain terms
A web request to a CGI script like this 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, started the script, and bash ran the command while starting up, before the script did anything.
How to check a system today
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. Any line that says vulnerable means the bash on that system needs an update.
Check the version as well:
bash --version | head -1
Where to look today:
- old appliances, NAS boxes and routers with their own firmware;
- containers built from very old base images;
- CGI scripts that still exist:
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 lasting fix changed how functions travel through the environment: bash now exports a function under a special name with a prefix and suffix, and only those names are imported:
x() { echo hi; }; export -f x; env | grep -A1 BASH_FUNC
BASH_FUNC_x%%=() { echo hi
}
An ordinary variable such as HTTP_USER_AGENT is never parsed as a function, whatever it contains. That closed the whole class of bugs instead of each parser flaw one by one.
What to take from it
- Environment variables cross trust boundaries. CGI, SSH forced commands, sudo, cron and DHCP all pass data through the environment. Code that reads it must treat it as input.
- Do not run shells on untrusted input. CGI scripts in shell, and
system()with strings built from requests, are risky even without a bash bug. - Expect follow-up CVEs after a fix in a parser. A first patch that blocks one input rarely fixes the parser behind it.
- KEV adds old CVEs. A CVE from 2014 can appear as "new on KEV" in 2025. Keep old systems patched or replace them.
Sources
- CVE records: CVE-2014-6271, CVE-2014-7169, CVE-2014-6277, CVE-2014-6278, CVE-2014-7186, CVE-2014-7187 (descriptions, affected patch levels, attack vectors, dates, CISA ADP scores)
- CISA KEV catalog, version 2026.11.25 (dates added)
- GNU Bash patches for 4.3
- Test command and
BASH_FUNC_output from bash 5.2.15 in adebian:bookworm-20261027-slimcontainer on 2026-11-26
Check your servers every day
The agent of Patchbrief reports the packages and settings of a server once a day; the digest names what to fix first.