Five months after Heartbleed, on 24 September 2014, the distributions published fixes for a bug in bash, the default shell on almost every Linux machine. The bug let anyone who could get a string of their choosing into the environment of a process that then started bash run commands as that process — and web servers, SSH servers and DHCP clients all did exactly that as a matter of routine. The flaw had been in bash since 1989. Within a day it was being used by botnets; within a week it had been followed by four more CVEs as the first fix, then the second, turned out to be incomplete. It was named Shellshock, and it was in several ways the opposite of Heartbleed: trivial to exploit, trivial to fix, and a lesson about a different kind of boundary.
This is the second page in a series on the vulnerabilities that changed how Linux is built and defended; Heartbleed was the first. Each tells the story from the project’s own records, says what it taught, and ends with what to check on your machine today.
What happened
Bash has a feature almost nobody uses on purpose: a shell function can be exported, so that a child bash inherits it. The mechanism is an environment variable whose value begins with () {, which a starting bash recognises and parses as a function definition. On 12 September 2014 Stéphane Chazelas, a Unix specialist working in the UK, noticed that bash did not stop parsing at the end of the function. Whatever followed the closing brace was executed, immediately, as part of starting up. He reported it privately to Chet Ramey, bash’s maintainer, and to the distributions, and a coordinated release was arranged for 24 September at 14:00 UTC, with patches for every bash from 3.0 to 4.3 and the identifier CVE-2014-6271.
The disclosure held, but the fix did not. Within hours Tavis Ormandy showed that the patched parser could still be made to misbehave, and a second identifier, CVE-2014-7169, was assigned; Red Hat’s advisory records the incomplete-fix notice at 05:15 UTC on 26 September. Florian Weimer at Red Hat then proposed the change that actually closed the class of problem: instead of treating any variable whose value starts with () { as a function, bash would only import functions from variables with a distinctive name, first BASH_FUNC_name() and, in the form upstream adopted, BASH_FUNC_name%%. Michal Zalewski, fuzzing the parser with his then-new tool afl, found two more ways in (CVE-2014-6277 and 6278), and two further parser crashes were fixed alongside (CVE-2014-7186 and 7187). By 30 September Red Hat was reporting malware in circulation and a complete set of packages; a bug that took a week to fully close had been in the code for twenty-five years, since the change of 5 August 1989 that shipped in bash 1.03.
The flaw, in one paragraph
An environment variable is supposed to be data. Bash treated one particular shape of value as code, and then ran the part of it that was not even the function. The danger was not bash itself but everything that put strings from strangers into the environment and then started a shell. A web server running a CGI script copies the request’s headers into variables — the browser’s User-Agent becomes HTTP_USER_AGENT — and if the script is a shell script, or calls one, a header beginning () { :;}; followed by a command ran that command as the web server’s user. An SSH server with AcceptEnv let a client set LANG and the like before the login shell started; a key restricted to one command by ForceCommand still passed the client’s requested command in SSH_ORIGINAL_COMMAND, so “git only” keys became “anything” keys. A DHCP client handed the server’s responses to a shell script. Nothing had to overflow and no memory had to be read; the attacker typed a command and the machine ran it.
The diagnostic from Red Hat’s advisory, run on a current machine for this page:
$ bash --version | head -1
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
$ env 'x=() { :;}; echo vulnerable' 'BASH_FUNC_x()=() { :;}; echo vulnerable' bash -c "echo test"
testA vulnerable bash prints vulnerable before test; this one ignores both planted variables. The function-export feature still exists, but the variable it uses is now unmistakable:
$ f() { echo hi; }; export -f f; env | grep -a BASH_FUNC
BASH_FUNC_f%%=() { echo hi
$ bash -c 'f'
hiOnly a variable named BASH_FUNC_something%% is parsed as a function, and the parser stops at the end of it. A User-Agent header cannot produce a variable with that name, which is the whole fix: the code and the data now live in different namespaces.
Why it spread so fast, and why it was over so fast
Heartbleed needed care to exploit and left its victims guessing about what had been taken. Shellshock needed one HTTP request, returned the output of any command, and announced itself in the web server’s access log. Security firms were reporting automated scanning and botnet recruitment within a day of the disclosure — one web-security company counted some seventeen thousand attack attempts against its customers in the first twenty-four hours, and a large CDN was seeing over a million probes a day by the end of the week. The targets were not so much hardened servers as everything that embedded a shell and faced the network: CGI scripts left over from the previous decade, management interfaces on appliances, and the millions of devices that would never be patched at all.
But where it could be patched, it was remediated in a way Heartbleed never was. Bash is not a long-running daemon: every exploitation started a fresh bash, so the moment the package was updated the hole was closed, with nothing to restart and no keys to reissue. The lingering damage was in two places. Machines that had been exploited before the patch had to be treated as compromised, and were often the hardest to tell apart from the clean ones. And the long tail — routers, NAS boxes, cameras, anything whose vendor had built bash into a firmware image — stayed vulnerable for years, which is where the botnets went next.
One accident of distribution policy mattered more than most people realised. On Ubuntu /bin/sh had been dash since 2006, and on Debian since 2011, so the shell that system() and #!/bin/sh scripts actually started was not bash and imported no functions; those systems were exposed through scripts that named #!/bin/bash explicitly and through the SSH and DHCP paths, but not through every system() call on the machine. On distributions where /bin/sh was bash, every one of those calls was a potential entry point. The difference did not make anyone safe, but it made the attack surface a very different size.
What it taught Linux
The environment is an input, and inputs come from strangers. Every program that turned a network message into environment variables had been doing something reasonable, and every one of them had quietly made bash’s parser part of its attack surface. The fix was not only the bash patch; it was a generation of software becoming more careful about what crossed that boundary. Apache’s CGI modules, OpenSSH’s AcceptEnv handling and DHCP client scripts were all looked at again, and the general principle — if you pass untrusted data to another program, know exactly how that program will interpret it — is now a standard review question rather than a specialist’s instinct. sudo, which had reset the environment by default for years and refused to pass through variables shaped like functions for reasons of its own, was the one widely used program on the list that turned out to be safe, and the reason it was safe is the lesson.
The first fix is a hypothesis. CVE-2014-6271 was followed within days by 7169, 6277, 6278, 7186 and 7187, and the distributions shipped bash three or four times in a week. The right response, which Red Hat and Debian both took, was to treat the vulnerability as a class — “the parser is reachable from the network” — rather than a line, and Weimer’s namespace change closed the class whatever further parser bugs turned up. The episode also made a quiet case for fuzzing: two of the follow-up CVEs were found with afl, whose author had released it the year before, and whose combination with sanitisers is the same approach the Heartbleed page describes becoming routine.
Old code is not safe code. Twenty-five years of use in the most heavily exercised program on the system had not found a bug that sat in plain sight once someone looked at the feature from the attacker’s side. Chazelas was not fuzzing or auditing; he was thinking about what else a function-importing parser might do, and the lesson was repeated by the xz incident a decade later: the quantity of eyes on a piece of code is not the quantity of eyes looking for the right thing.
Shells are not sandboxes. A great deal of 2014’s exposure was design rather than defect: restricted SSH keys that ran a shell to interpret the restriction, web applications that shelled out to do work a library could have done, device firmware that wired a full interpreter to a web form. The slow movement away from that — ForceCommand helpers that do not spawn a shell, application code that calls programs with argument lists instead of command strings, services with no shell in the image at all — is one of Shellshock’s longer-term effects, and the FROM scratch container with no /bin/sh in it is the end of that road.
What to check on your machine today
Every supported distribution has carried a fixed bash since October 2014, so the first check passes everywhere except on firmware and forgotten machines. The rest are about the shape of the problem, which has not gone away.
env 'x=() { :;}; echo vulnerable' 'BASH_FUNC_x()=() { :;}; echo vulnerable' bash -c "echo test"
ls -l /bin/sh # which shell runs system() and #!/bin/sh scripts
sudo -V | grep -i 'reset the environment' # sudo's env_reset, which is why sudo was safeOn the machine used for this page: test alone, /bin/sh -> dash, and sudo reporting that it resets the environment to a default set. A result of vulnerable on anything you own today means an unmaintained device, and the right response is to replace it rather than to find a bash package for it.
sshd -T 2>/dev/null | grep -iE 'acceptenv|forcecommand|permituserenvironment'
grep -rE 'command=|environment=' /etc/ssh/authorized_keys.d ~/.ssh/authorized_keys 2>/dev/null
apache2ctl -M 2>/dev/null | grep -i cgi; ls /usr/lib/cgi-bin 2>/dev/nullKnow which network-facing programs still put a stranger’s strings into an environment and then run a shell. Debian and Ubuntu’s default sshd_config still accepts LANG and LC_* from the client, which is harmless with a fixed bash and worth knowing about regardless; a key with command= in authorized_keys still receives the client’s own request in SSH_ORIGINAL_COMMAND, and the program named in command= should be one that does not hand that string to a shell — SSH Keys Explained covers the restricted-key options. A CGI module loaded on a web server in 2026 is worth a question about why. None of these is a vulnerability now; each is a place where the next bash, perl or Python parser bug becomes remotely reachable, and the list is shorter on a machine built from Securing a New Linux Server.
$ env | grep -a BASH_FUNC # anything a parent exported into this shell
$ bash -c 'echo $BASH_VERSION'
5.2.21(1)-releaseAnd know the feature is still there. Exported functions are a legitimate bash facility used by build systems and some login scripts; if env shows BASH_FUNC_ variables you did not expect, something upstream of your shell is defining functions for you, which is worth understanding for the same reason as any other inherited environment — The Life of a Login is the page on where that environment comes from.
Sources
- oss-security, 24 and 25 September 2014 — the coordinated-disclosure thread for CVE-2014-6271: Florian Weimer’s posts with the upstream patch list (bash30-017 to bash43-025), the vectors, and the prefix-and-suffix hardening patch
- Red Hat Customer Portal, “Bash Code Injection Vulnerability via Specially Crafted Environment Variables (CVE-2014-6271, CVE-2014-7169)”, updated through 2 October 2014 — the diagnostic commands, the dated updates, the vector table and the fixed package versions
- Ubuntu security tracker entries for CVE-2014-6277, 6278, 7186 and 7187 — the follow-up flaws, their dates and fixed versions
- Stéphane Chazelas, bug-bash, 10 October 2014, “when was shellshock introduced” — the 5 August 1989 change and the bash 1.03 release, confirmed by Chet Ramey
- Contemporary reports of exploitation scale (Wired, 25 September 2014; the New York Times, 26 September 2014, citing Incapsula; Bloomberg Businessweek, 30 September 2014, citing CloudFlare) — used only for the attack-volume figures, and attributed to the firms that measured them
Related reading
- Heartbleed — the other 2014 shock, and the opposite case: hard to exploit, invisible, and impossible to finish patching in a day
- The Life of a Login — where a shell’s environment comes from, stage by stage
- SSH Keys Explained —
command=and the other restrictions a key can carry, and what still reaches the server side - ssh —
AcceptEnv,ForceCommandand the rest of the server configuration - Permissions and Privilege — how
sudoand the rest of the privilege machinery fit together - What Ships in Your Container Image — the image with no shell in it, which is where this lesson ends
- The rest of this series — regreSSHion, the privilege-escalation decade, Meltdown and Spectre and the Morris worm, which is where the “ship nothing you are not using” lesson above began

