What is the CVE-2014-6271 bash vulnerability (Shellshock) and how do I fix it?
Recently, there have been news going around regarding "CVE-2014-6271" (See USN-2362-1), which is a vulnerability in Bash. How do I know if I am affected by this, how can I fix it, and why should I care?
This is designed as a canonical answer for this vulnerability, due to its scope and severity.
Solution 1:
What is Bash?
Bash is the default interactive shell in Ubuntu. When you are interfacing with the terminal (either through the terminal emulator, over a tty, or ssh), you are generally typing commands that bash
will read, and execute. Even if you do not use the terminal at all, you still have Bash.
On Ubuntu, /bin/sh
is not bash (it is dash). Only bash is affected by this vulnerability.
How does the exploit affect me?
Bash and the OS keep track of a set of environment variables that describe the current logged-on user, where to look for programs on the hard disk, and other such functions. By crafting an environment variable with a specific structure, an attacker might be able to execute code next time Bash starts.
The attacker can set that environment variable multiple ways:
- Remotely connect to a service such as SSH with a specific setup such as git over ssh. As Mitre warns, the use of the sshd
ForceCommand
option is an attack vector. Accounts whose shell isn't bash aren't affected. - Tricking you into setting the environment variable.
- Causing another program to set an environment variable to have that crafted value. For example, you might have a webserver and script that needs to set an environment variable with specific user content. Even if that script creates its own, and doesn't touch other environment variables, it's enough. A single environment variable with any name and a crafted value is enough for the exploit to succeed.
- Other ways I have not mentioned here.
Once they set this variable, the next time bash
opens for any reason, your attacker's code will be run. This is especially fearsome with sudo -s
, as it spawns bash as the super-user (an administrative user rule that has full control over your computer's data and programs). Even if you only start bash as a standard user, that user's files can be deleted.
It is important to note that even if you do not use bash yourself, many programs will spawn bash by themselves as part of their operation. Even in this case, you are vulnerable. However, Ubuntu's /bin/sh
is not bash, so only programs that explicitly invoke bash and not the default scripting shell are affected.
According to Mitre:
vectors involving the ForceCommand feature in OpenSSH sshd, the mod_cgi and mod_cgid modules in the Apache HTTP Server, scripts executed by unspecified DHCP clients, and other situations in which setting the environment occurs across a privilege boundary from Bash execution.
Am I vulnerable?
Use dpkg to check your installed package version:
dpkg -s bash | grep Version
This will look up info on your bash
package, and filter the output to only show you the version. The fixed versions are 4.3-7ubuntu1.4
, 4.2-2ubuntu2.5
, and 4.1-2ubuntu3.4
.
For example, I see:
wlan1-loopback% dpkg -s bash | grep Version
Version: 4.3-7ubuntu1.4
and can determine that I am not vulnerable.
How do I update?
The standard update manager will offer you this update. This is a prime example of how security updates are important, no matter what OS you use or how well-maintained it is.
The USN Bulletin states that new versions have been released for Ubuntu 14.04 Trusty Tahr, 12.04 Precise Pangolin, and 10.04 Lucid Lynx. If you are not on one of these LTS versions, but are on a reasonably-recent version, you'll most likely be able to find a patched package.
First, check if you
If you are vulnerable, you should first grab the newest package lists:
sudo apt-get update && sudo apt-get install bash
The first command makes sure that you have the newest package list that includes the fixed version, and the second command installs the newest (fixed) version of bash.
While the bug only appears to come into play when bash is spawned, it's still a good idea to reboot immediately if feasible.
Solution 2:
Stole this off of cft over at Hacker News. If you have trouble with your repos like me(Odroid-XU), then this should work nicely if you want to patch/build from source.
TMPDIR=/tmp/bash-src
mkdir $TMPDIR
cd $TMPDIR
#download bash
wget http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz
#download all patches
for i in $(seq -f "%03g" 1 999); do
wget http://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-$i
if [[ $? -ne "0" ]]; then
MAX=$(expr $i - 1)
break;
fi
done
tar zxf bash-4.3.tar.gz
cd bash-4.3
#apply all patches
for i in $(seq -f "%03g" 1 $MAX);do
echo apply patch bash43-$i
patch -p0 < ../bash43-$i
done
#build and install
./configure && make
sudo make install
cd ../..
rm -r $TMPDIR
Then run:
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
And if you get:
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'
this is a test
Then you're all good!
WARNING: make install will install bash in /usr/local/bin
, so /bin/bash
is not modified and can be invoked from curl !!
Solution 3:
Note: The Security Patch for CVE-2014-7169 has been released as a standard security update. There is no need to add additional ppa's to receive this patch. Only the following is needed.
sudo apt-get update
sudo apt-get upgrade
To ensure you have patched bash correctly, run the following command
dpkg -s bash | grep Version
If you are on 14.04 LTS, you should see an output of:
Version: 4.3-7ubuntu1.4
If you are on 12.04 LTS, your output should be:
Version: 4.2-2ubuntu2.5
Solution 4:
If you are on 11.04: use below steps (it worked for me)
cd ~/
mkdir bash
wget https://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz
for i in $(seq -f "%03g" 0 25); do wget https://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-$i; done
if it is not downloaded required patche then install ftp package
apt-get install ftp
for i in $(seq -f "%03g" 0 25); do wget https://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-$i; done
tar zxvf bash-4.3.tar.gz
cd bash-4.3
for i in $(seq -f "%03g" 0 25);do patch -p0 < ../bash43-$i; done
./configure && make && make install
apt-get install build-essential
./configure && make && make install
To see if the patch was applied:
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"