This lab should be done with a partner.
Here is the lab4 partner list.
Lab 4 Goals:
- reading and tracing through the execution of IA32 assembly
- understanding how IA32 translates to C instructions, data structure
access, and function calls
- practice with tools for examining binary files
- gain expertise in gdb
Lab 4 Intro
In this assignment, you and your partner are going to be given a binary
bomb program. Your bomb has 5 phases, each on needs to be defused by
entering a correct phrase on stdin (you can also have your bomb read
phrases from a file given as a command line argument).
Your goal is to defuse all phases of your bomb, limiting the number of
times you explode it in the process.
Your bomb will automatically notify me if it explodes and when you have defused
a phase. In addition, you must run your bomb on one of the CS lab machines
(your assigned machine or any machine in the overflow or main labs).
You will submit your lab4 solution in two parts:
Part 1: The Checkpoint (due before Fall break):
- defusing the first two phases of your bomb (I encourage you to try
to get 3 phases defused before break).
Part 2: The complete solution (due after Fall break):
- defusing the first four phases of the bomb
- submitting (via handin31) a file contianing the 4 (or 5) solution strings
to defuse your bomb, and a file containing your write-up of how you sovled
each of the phases. update31 copies over starting point files
for both of these into your cs31/labs/04/ subdirectory.
- phase 5 is not required. If you solve it, you
will receive extra credit. Include a description of how you solved it in
your write-up.
Getting Your Bomb: we will do this together in class Thurs
- First, both you and your partner should run update31, which will
create the directory structure for your lab 4 assignment and copies over some
starting point files:
$ update31
$ cd cs31/labs/04
$ pwd
/home/your_user_name/cs31/labs/04
$ ls
README bomb_ID bomb_how_we_solved_it soln.txt
- Next, follow these steps to get your bomb:
- In firefox on the CS system, one of you or your partner should enter
this url:
http://zucchini.cs.swarthmore.edu:15213/
- Enter your user name and email address on our system (username@cs.swarthmore.edu), and choose Submit.
- Choose to save the bombX.tar file in the dialog box that pops up.
- move the file into your labs/ directory (do not put it in your labs/04
directory as I do not want you to submit your bomb with your lab 4 solution):
mv ~/Desktop/bombX.tar ~/cs31/labs/
- cd into your labs directory, and scp the tar file to your partner
cd ~/cs31/labs
ls
scp bombX.tar partner_username@cs.swarthmore.edu:cs31/labs/.
# partner enters his/her password, and the bombX.tar file should be scp'ed
# into their cs31/labs/ subdirectory
- both you and your partner can untar the bomb.tar file in your private
labs/ subdirectory:
cd ~/cs31/labs
ls # you should see your bombX.tar file
tar xvf bombX.tar
- if you cd into your bombX subdirectory, you will see 3 files:
README bombX* main.c
Do not run the bomb program yet!
Checking the status of your bomb
From firefox running on the CS system, enter this url (you cannot
connect to this url from outside our network):
http://zucchini.cs.swarthmore.edu:15213/scoreboard
You will see your bomb in this list. The scoreboard displays
how many stages you have defused, how many total explosions your bomb
has had, and your score so far.
This information is updated about every 40 seconds. Re-load the
page to see the latest information.
Details of the Bomb lab
Introduction
A binary bomb is a program that consists of a
sequence of phases. Each phase expects you to type a particular string
on stdin. If you type the correct string, then the phase is
defused and the bomb proceeds to the next phase. Otherwise, the
bomb explodes and terminates. The bomb is defused when every phase has
been defused. You will be penalized for explosions (1/4 a point for
each one), so you need to be careful not to explode your bomb too many
times.
You can receive up to 85 points total on this lab:
- Defusing phases 1-4 are each worth 10 points (40pts total)
- Defusing phase 5 is worth 15 points
- Your write-up of how you solved each phase is worth
4 points for each phase (20 points total). Your write-up should be
in the file bomb_how_we_solved_it in your
cs31/labs/04 subdirectory.
- The checkpoint is worth 10 points.
In addition, I will take up to 5 points off total for explosions.
You will lose a point for each 4th explosion (number 4, 8, 12, ...),
so you get a few for "free". I will not take off more than 5 points
total for explosions, unless it is clear that you are trying a brute
force approach, in which case I will.
Also, you may find some opportunity to gain a few additional points as you go.
Defuse Your Bomb
You must run your bomb on one of the class machines; the bomb
will always blow up if run elsewhere. There are several other
tamper-proofing devices built into the bomb as well. In particular,
do not use the gdb
set command while trying to defuse your
bomb.
To kill your bomb executable (to make it exit without
exploding), type CNTRL-C. This way you can run your bomb, solve
a phase, and exit and come back later to try the next phase.
You can use many tools to help you defuse your bomb. Please look at
the hints section below for some tips and ideas. The best way is to
use ddd or gdb to step through the disassembled binary.
Each time your bomb explodes it notifies the bomblab server, and you lose
1/4 point (up to a max of 5 points) in the final score for the lab.
So there are consequences to exploding the bomb. You must be careful!
The first four phases are worth 10 points each. Phase 5 is a
little more difficult, so it is worth 15 points.
Although phases get progressively harder to defuse, the expertise you
gain as you move from phase to phase should offset this
difficulty. However, the last phase will challenge even the best
students, so please don't wait until the last minute to start.
Once you have solved a phase, I encourage you to run your bomb with a
soln.txt file containing the input phrases for the phases you have
solved. The format of the file should be one phrase per line, in order
of bomb phases. Using an input file will help to prevent you from
accidentally exploding the bomb on a previously solved phase.
For example:
./bomb soln.txt
will read the input lines from soln.txt until it reaches
EOF (end of file), and then switch over to stdin for the remaining
input. This feature is so you don't have to keep
retyping the solutions to phases you have already defused.
The bomb ignores blank input lines, both in the file and on stdin.
To avoid accidentally detonating the bomb, you will need to learn how to
single-step through the assembly code and how to set breakpoints. You
will also need to learn how to inspect both the registers and the
memory states. One of the nice side-effects of doing the lab is that
you will get very good at using a debugger. This is a crucial skill
that will pay big dividends the rest of your career.
The Write-up
Edit the file cs31/labs/04/bomb_how_we_solved_it in vim (or emacs) to
include a short explanation of how you defused each phase and a short
explaination of what the phase is doing.
Describe at a high-level what the original C code is doing for
each phase. For example, is it doing some type of numeric computation,
string processing, function calls, etc. and describe the specific
computation it is doing (i.e. what type of string processing and how is
that being used?).
Do not list registers and assembly code for this part, but describe
what the phase is doing at a higher-level in terms of C sematics.
You do not have to reverse engineer the IA32 code and translate
every part of every phase to equivalent C code. Instead, give a rough
idea of equivalent C or psuedo code for the main part of
each phase. For example, something like "uses an if-else to choose
to do X or Y based on the input value Z" is an appropriate right level of
explaination. Something like "moves the value at %ebp-8 into register %eax"
is way too low-level.
This part of the lab should not be onerous; you should be able in
a short paragraph or two (maybe with a few lines of C or psuedo code
to help explain), describe to me what each phase is doing.
I recommend doing the write-ups for each phase as you solve them.
Excessively verbose, low-level descriptions will be penalized,
as will vague descriptions; you want to clearly demonstrate to me that you
figured out what that phase is doing by examining the IA32 code for
each phase in your bomb executable.
If you are unable to solve a phase, you can still receive partial credit for
it in the write-up part by telling me what you have determined about that
phase.
Hints
There are many ways of defusing your bomb. You can examine it in
great detail without ever running the program, and figure out exactly
what it does. This is a useful technique, but it not always easy to
do. You can also run it under a debugger, watch what it does step
by step, and use this information to defuse it. This is probably the
fastest way of defusing it.
We do make one request, please do not use brute force! You could
write a program that will try every possible key to find the right
one. But this is no good for several reasons:
- You lose 1/4 point (up to a max of 5 points)
every time you guess incorrectly and the bomb explodes.
- Every time you guess wrong, a message is sent to the bomblab server.
You could very quickly saturate the network with these messages, and cause
the system administrators to revoke your computer access.
- We haven't told you how long the strings are, nor have we told you
what characters are in them. Even if you made the (incorrect) assumptions
that they all are less than 80 characters long and only contain
letters, then you will have 26^80 guesses for each phase. This will
take a very long time to run, and you will not get the answer before
the assignment is due.
There are many tools which are designed to help you figure out both
how programs work, and what is wrong when they don't work. Here is a
list of some of the tools you may find useful in analyzing your bomb,
and hints on how to use them. And refer to the week04 and week05 weekly
lab pages for information on using gdb and tools for examining binaries:
- ddd (or gdb) bomb
The GNU debugger will be your most useful tool.
You can trace through a program line by
line, examine memory and registers, look at both the source code and
assembly code (we are not giving you the source code for most of your
bomb), set breakpoints, set memory watch points, and write scripts.
See weekly lab pages about using ddd and gdb, my gdb Guide, and figure
3.30 of the text book for a summary of useful gdb commands.
- draw the stack and register contents as you are tracing through
code in gdb, and take notes as you go (this will also help you with
the write-up part of the lab assignment).
- objdump -t bomb
This will print out the bomb's symbol table. The symbol table includes the
names of all functions and global variables in the bomb, the names of
all the functions the bomb calls, and their addresses. You may learn
something by looking at the function names!
- objdump -d bomb
Use this to disassemble all of the code in the bomb. You can also
just look at individual functions. Reading the assembler code can
tell you how the bomb works.
Although objdump -d gives you a lot of information, it doesn't tell
you the whole story. Calls to system-level functions are displayed in
a cryptic form. For example, a call to sscanf might appear as:
8048c36: e8 99 fc ff ff call 80488d4 <_init+0x1a0>
To determine that the call was to sscanf, you would need to
disassemble within gdb.
- strings bomb
This utility will display the printable strings in your bomb.
Looking for documentation about a particular tool? Don't
forget, the commands
apropos,
man and
in gdb the
info command.
What to submit
Whether or not you have defused a bomb phase, and how many times you
have exploded your bomb is automatically submitted
to the bomb server by your bomb program.
Checkpoint:
For the checkpoint, you need do nothing to "submit" it. I'll check
the scoreboard at the due date to verify whether or not you met the
checkpoint.
Complete Solution:
For the complete solution you will run handin31 to submit
the contents of your cs31/labs/04 directory. In particular, make
sure that it contains these three files:
- bomb_how_we_solved_it: the write-up part for your bomb.
- soln.txt: your bomb's solution input file: ./bombX soln.txt
- bomb_ID: this file just lists your bomb ID
You do not need to submit your binary bomb file (I have a copy of it).
I'll also check the scoreboard at the due date to determine which phase
you sovled and how many times you exploded your bomb.
Submit
Once you are satisfied with your solution, hand it in by typing
handin31 at the unix prompt.
Only one of you or your partner should run handin31 to submit your
joint solutions If you accidentally both run it, send me email right
away letting me know which of the two solutions I should keep and which
I should discard (you don't want the grader to just guess which joint
solution to grade).
You may run
handin31
as many times as you like, and only the
most recent submission will be recorded. This is useful if you realize,
after handing in some programs, that you'd like to make a few more
changes to them.