Vulnerability24 Sep 2014

Shellshock (Bash Bug)

Bash ran commands hidden after function definitions in environment variables. The bug had been there since 1989.

Severity
History books
Difficulty
intermediate
Companies
GNU Bash, Red Hat, Google
Tech
Bash, CGI, Environment variables, OpenSSH, DHCP
Root cause
injection / unsafe parsing, unpatched flaw

The story

Quick (1 min)

On 24 September 2014, a serious bug in Bash, the command shell installed on most Linux and Unix systems, was made public. It was nicknamed Shellshock.

Bash lets programs pass small scripts (functions) to each other through environment variables, a kind of shared settings list. The bug: if someone put extra commands after a function in that list, Bash ran them when it started.

That matters because lots of internet-facing software copies user input into environment variables. Old-style web scripts (CGI), for example, copy request details like the browser name. An attacker could put commands in a web request and the server would run them. Attacks started within an hour of the announcement.

The lesson: never let data be treated as code, and parsers that handle untrusted input need hard testing.

Keep reading to the end to earn XP.Read. XP earned.

Engineer (2 min)

Function export. Bash can export functions to child Bash processes by encoding them in environment variables. Each new Bash process scans its environment, rebuilds those functions, and executes the definitions. It assumed the variables came from another trusted Bash process.

The bug (CVE-2014-6271). Bash kept executing whatever came after the function body. A variable like x='() { :;}; echo vulnerable' defines an empty function and then runs echo vulnerable the moment Bash starts. NVD: Bash "processes trailing strings after function definitions in the values of environment variables, which allows remote attackers to execute arbitrary code via a crafted environment."

How attackers got input into the environment:

  • CGI web servers copy request data (headers and so on) into environment variables before running a handler. If the handler is or calls Bash, that's remote code execution.
  • OpenSSH ForceCommand puts the user's requested command in SSH_ORIGINAL_COMMAND, so restricted SSH users could escape to a full shell.
  • DHCP clients pass server-supplied options to scripts, so a malicious Wi-Fi network could run code on a laptop.
  • qmail and others passing external input through Bash.

Whack-a-mole. The first patch didn't fully fix the parser. Within days, related CVEs followed (CVE-2014-7169, -6277, -6278, -7186, -7187). Google's Michał Zalewski found some with the american fuzzy lop fuzzer and confirmed that a patch by Red Hat's Florian Weimer stopped them.

Age. Source history shows the bug was introduced on 5 August 1989 and released in Bash 1.03 on 1 September 1989, so it was 25 years old.

Interview takeaway: treat environment variables and headers as untrusted input. Avoid passing them to shells, and fuzz parsers.

Keep reading to the end to earn XP.Read. XP earned.

Deep dive (2 min)

Timeline (Wikipedia, NVD)

  • 5 August 1989: the bug enters Bash's source. 1 September 1989: released in Bash 1.03.
  • 12 September 2014: Stéphane Chazelas tells Bash maintainer Chet Ramey about the bug, which he calls "Bashdoor," and works with security experts on a patch.
  • 24 September 2014: public disclosure with fixed Bash updates; CVE-2014-6271 published. A few companies and distributors were informed beforehand.
  • Within an hour: reports of machines being compromised.
  • 25 September: botnets built on Shellshock exploits are used for DDoS and scanning.
  • 26 September: the "wopbot" botnet is reported attacking Akamai and scanning the US Department of Defense. Incapsula counts 17,400 attacks on 1,800+ domains in 24 hours. David A. Wheeler warns the patches are a "whack-a-mole" job.
  • 27 September – 1 October: Michał Zalewski reports more bugs found with AFL fuzzing and confirms Florian Weimer's 25 September patch prevents them.
  • 30 September: Cloudflare tracks about 1.5 million Shellshock attacks and probes per day.
  • 28 January 2022: added to CISA's Known Exploited Vulnerabilities catalogue (NVD).

Why "trust the environment" was the real flaw

Bash assumed exported functions in the environment came from another Bash process. But many programs, including web servers, SSH and DHCP clients, put outside data in environment variables. Once that happens, a parser bug becomes remote code execution.

Related CVEs (Wikipedia)

  • CVE-2014-7169: the first fix was incomplete.
  • CVE-2014-6277 and CVE-2014-6278: function-definition parsing bugs found by Zalewski.
  • CVE-2014-7186 and CVE-2014-7187: further parser memory issues.

Severity

NVD rates CVE-2014-6271 at CVSS 3.1 base score 9.8 (critical). Wikipedia notes it was compared to Heartbleed because of the millions of potentially exposed systems.

Keep reading to the end to earn XP.Read. XP earned.

Failure replay

Step by step, what broke and what it hit next.

  1. Sep 1989
    Bash function importdegraded

    Bash 1.03 ships code that imports exported functions from environment variables and also runs anything trailing them.

    Affects: Web server CGI

  2. Attack
    Attackercompromised

    The attacker puts "() { :;}; <command>" in a request header, such as the User-Agent.

    Affects: Web server CGI

  3. Attack
    Web server CGIcompromised

    The CGI server copies the header into an environment variable and launches a Bash-based handler.

    Affects: Bash function import

  4. Attack
    Bash function importcompromised

    Bash starts, imports the "function", and executes the trailing command with the server's privileges.

    Affects: Server data

  5. Sep 24–30, 2014
    Server datacompromised

    Within hours, botnets use Shellshock for DDoS and scanning. Cloudflare sees about 1.5 million attacks a day.

  6. Sep 24, 2014
    Bash function importrecovering

    The first patch ships with disclosure. Related parser bugs keep appearing in the following days.

  7. Sep 25 – Oct 1
    Bash function importhealthy

    Fuzzing finds more bugs. Zalewski confirms a patch by Red Hat's Florian Weimer prevents them.

Impact

Who was affected
Systems where untrusted input reached Bash via environment variables, including CGI web servers, restricted OpenSSH setups, DHCP clients and some mail servers; millions of internet-facing systems were potentially exposed.
How long
Bug present since 1989; mass exploitation began within hours of disclosure on 24 September 2014 and patches followed over about a week.
Cost
not disclosed

Lessons

  • Data should never be treated as code; implicit execution of imported data is dangerous.
  • Any value that can come from outside (headers, env vars, DHCP options) is untrusted.
  • Fuzzing finds parser bugs that manual review misses.
  • Initial patches for parser bugs are often incomplete; plan for follow-ups.
  • Very old code in core tools can hide critical flaws.

Quiz

  1. What did Shellshock let attackers do?

    Check answer

    Execute arbitrary commands via crafted environment variables processed by Bash. Bash executed commands trailing function definitions in environment variables.

  2. Why were CGI web servers especially vulnerable?

    Check answer

    They copy request data such as headers into environment variables before running handler scripts. Attacker-controlled headers became environment variables that Bash then parsed.

  3. How old was the bug when it was disclosed?

    Check answer

    About 25 years (introduced in 1989). Source history shows it was introduced in August 1989 and released in Bash 1.03.

  4. How were several follow-up Bash bugs found?

    Check answer

    Fuzzing with american fuzzy lop by Google's Michał Zalewski. Zalewski used AFL fuzzing to find further parsing bugs.

Interview prep

Try answering out loud before you open the model answer.

  1. security

    How did Shellshock turn a local shell feature into remote code execution on web servers?

    Show model answer

    Bash imported exported functions from environment variables and executed any commands trailing the function definition. CGI web servers copy request data such as headers into environment variables before running handlers. If the handler was a Bash script or invoked Bash, an attacker could put "() { :;}; command" in a header and Bash would run it on the server. The same pattern applied to OpenSSH ForceCommand and DHCP clients. Defences: patch Bash, avoid shells in request-handling paths, don't pass untrusted data into environments, and run with minimal privileges.

    A strong answer hits:

    • Function import executes trailing commands
    • CGI copies headers into env vars
    • Other vectors (SSH, DHCP)
    • Avoid shells for untrusted input; least privilege
  2. debugging

    You apply an emergency patch for a parser vulnerability and researchers keep finding bypasses. How do you approach a durable fix?

    Show model answer

    Patching each input pattern is whack-a-mole, as David A. Wheeler warned about Bash's parser. Change the design so untrusted data can't reach the dangerous code path at all, for example by making sure arbitrary variables are never parsed as code. Pair it with fuzzing (AFL found Bash's follow-up bugs) and add regression tests for every bypass. Communicate clearly that more patches may follow.

    A strong answer hits:

    • Fix the class, not individual inputs
    • Isolate untrusted data from parsers
    • Fuzzing and regression tests
    • Expect and communicate follow-ups
  3. system design

    Your company has thousands of servers and a critical Bash vulnerability was just announced, with attacks already happening. What do you do in the first 24 hours?

    Show model answer

    Prioritise by exposure: identify internet-facing systems where untrusted input can reach Bash (CGI, SSH ForceCommand, DHCP-exposed devices). Deploy WAF or IDS rules to block known patterns as a stopgap. Push patched Bash through config management, starting with the most exposed systems, and verify with a test command. Watch for follow-up CVEs and be ready to patch again. Hunt for signs of compromise in logs from before you patched.

    A strong answer hits:

    • Exposure-based prioritisation
    • Temporary WAF or IDS signatures
    • Automated patch rollout and verification
    • Hunt for compromise and track follow-up CVEs

Go deeper