Step 1: Back up your existing Bash binary
Find out where your existing bash binary is located on your system with:
1
|
which bash
|
1
|
/bin/bash
|
1
|
sudo cp /bin/bash /bin/bash.old
|
Step 2: Determine which version of Bash you’re running
Now you’ll need to determining which version of bash your system is running. If you’re running Fedora 12, for example, it’s probably version 4.0. You can find out your version with:
1
|
bash --version
|
1
|
GNU bash, version 4.0.1(1)-release (i686-redhat-linux-gnu)
|
1
|
GNU bash, version 4.0.42(1)-release (i686-pc-linux-gnu)
|
Step 3: Set up your fix environment
Whenever I’m working with source code on a Linux box, I like to keep everything in the /usr/local/src directory. So create a new subdirectory for fixing bash, and then jump into that directory, with:
1
2
|
mkdir /usr/local/src/bashfix
cd /usr/local/src/bashfix
|
1
|
sudo yum install patch byacc textinfo bison autoconf gettext ncurses-devel
|
Step 4: Download the Bash source
Locate the matching source code for the version of Bash you’re already running on the GNU.org FTP server. Since my test system was using 4.0, that’s what I’ll download in this example, but you should obviously download the one that’s appropriate for your system. Again, resist the urge to upgrade to a newer version (such as 4.1, 4.2, or 4.3 in this example). This can potentially create serious problems. Just stick with what you’ve already got for now. Download and extract the appropriate Bash source code into your fix directory with:
1
2
|
wget https://ftp.gnu.org/pub/gnu/bash/bash-4.0.tar.gz
tar zxvf bash-4.0.tar.gz
|
1
|
cd bash-4.0
|
Step 5: Download and Apply the Patches
If you check the GNU.org FTP server where you downloaded the source code, you’ll also see a few sub-directories for each major version that contain all the patches for that version. Different versions of Bash have a different number of patches. In our example, the patches are located in https://ftp.gnu.org/pub/gnu/bash/bash-4.0-patches/. Checking that directory (as of Oct 1, 2014) shows a total of 42 patches for version 4.0, from bash40-001 to bash40-042. Your first option is to download the first patch, apply it to the source code, then download the second patch, apply it to the source code, and so on. Don’t do this just yet, because I’m going to show you a faster way to do it. But you should at least understand what’s happening before you automate it. The command you’d use to download the first patch and apply it in a single step would be (again, don’t do this… it’s just for illustration):
1
|
curl https://ftp.gnu.org/pub/gnu/bash/bash-4.0-patches/bash40-001 | patch -p0
|
1
|
wget https://gist.githubusercontent.com/stevejenkins/3d64d3543060c1bcac92/raw/1ab592f5c8b584e9a0debf8e2ccbcac50cbf6e73/bash-multipatch.sh
|
I do my best to stay on top of this issue, but It’s possible that even more patches are available in the patches directory before I’ve had a chance to update this article. You should always set the lastpatch variable in the script to the last patch you see in the directory to ensure the highest level of vulnerability protection. Save your edited file, then make it executable with:
1
|
chmod 755 bash-multipatch.sh
|
1
|
./bash-multipatch.sh
|
1
2
3
4
5
6
|
https://ftp.gnu.org/pub/gnu/bash/bash-4.0-patches/bash40-042
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
101 4056 101 4056 0 0 10947 0 --:--:-- --:--:-- --:--:-- 54810
patching file parse.y
patching file patchlevel.h
|
1
|
cat patchlevel.h
|
Step 6: Build and Install your Patched Bash Binary
It’s best if the “configure” and “make” steps in this section are performed as a regular, non-root user. However, on particularly older systems, if you’re getting errors other than missing dependencies when running “configure,” you may just have to do them as root.In the source code directory, do:
1
|
./configure
|
1
|
make
|
1
|
make test
|
1
|
ls -la bash
|
1
|
-rwxrwxr-x 1 root root 2273014 2014-09-28 08:37 bash
|
1
|
sudo cp -f bash /bin/bash
|
Step 7: Test Your Fix
Now that you’ve manually downloaded, patched, compiled, and installed a new bash, you should test it to make sure you’re no longer vulnerable. Make sure your current shell session is using your newly compiled bash by simply running the new location from the command line. In this example, that would be:
1
|
/bin/bash
|
1
|
bash --version
|
1
|
GNU bash, version 4.0.42(1)-release (i686-pc-linux-gnu)
|
No comments:
Post a Comment