CSCI 237
Computer Organization
Home | Lectures | Labs | CS@Williams
Lab 2: Bomb Lab
Assigned | Feb 26, 2025 |
---|---|
Prelim Due Date | Mar 4/5 at 11:00pm. At least the first three phases must be defused. |
Final Due Date | Mar 11/12 at 11:00pm. All five phases must be defused. The sixth phase is extra credit. There also may or may not be a secret seventh phase. If you find it, it's extra credit too. |
Files | See instructions on obtaining your unique bomb below. |
Submissions | Please submit your final solution file, defuser.txt, on Glow. In addition, please submit a short description of your strategy for solving each phase. No need to write a novel. A few sentences on each phase is sufficient. This should be submitted on Glow as well (txt or pdf). |
Overview
The purpose of this assignment is twofold: first, you will
gain basic familiarity with x86-64 assembly instructions and how
they are used to implement comparison, loops, switch statements,
recursion, pointers, and arrays; and second, you will gain experience
using the gdb debugger
and other tools to step through assembly code.
Note: You must ssh into lohani, limia, angus, or brownswiss to complete this lab.
Instructions
The nefarious Dr. Evil has planted a slew of “binary bombs” on our machines. A binary bomb is a program that consists of a sequence of phases. Each phase expects you to type a particular string on stdin (standard input). If you type the correct string, then the phase is defused and the bomb proceeds to the next phase. Otherwise, the bomb explodes by printing “BOOM!!!” and then terminating. Each time the bomb explodes you will lose 0.25 points, so be careful! The bomb is defused when every phase has been defused.
There are too many bombs for us to deal with, so we are giving everyone a bomb to defuse. Your mission, which you have no choice but to accept, is to defuse your bomb before the due date. Good luck, and welcome to the bomb squad!
The bombs were constructed specifically for 64-bit machines. You should do this assignment on a 64-bit lab Linux machine. Be sure to test your solution on one of those platforms before submitting it, to make sure it works when we grade it! In fact, there is a rumor that Dr. Evil has ensured the bomb will always blow up if run elsewhere. There are several other tamper-proofing devices built into the bomb as well, or so they say.
Everyone gets a unique bomb to defuse. You can obtain your bomb by pointing your Web browser here. This will display a binary bomb request form for you to fill in. Enter your user name and email address and hit the Submit button. The server will build your bomb and return it to your browser in a tar file called bomb$NUM.tar, where $NUM is the unique number of your bomb. If your browser tries to block the download, make sure you allow it to proceed.
If you are not directly logged into a lab machine, you will have to copy your file to a lab machine. You can do this using the following command:
scp bomb$NUM.tar 27abc1@lohani.cs.williams.edu:
Insert your bomb number for $NUM and your username for 27abc1. You can use either
lohani, limia, angus, or brownswiss as the destination machine. This command will copy the tarball to your home
directory on the Linux machines. Next, you should ssh to either lohani, limia, angus, or brownswiss
and untar your bomb using the following command:
tar xvf bomb$NUM.tar
These commands will create a directory called bomb$NUM (where $NUM is the ID of your bomb) with the following files:
bomb
: The executable binary bombbomb.c
: Source file with the bomb's main routineREADME
: A mostly empty file that just shows your nameYour job is to defuse the bomb. You can use many tools to help you with this; please look at the tools section for some tips and ideas. Two of the best ways are to (a) use a debugger to step through the disassembled binary and (b) print out the dissassembled code and step through it by hand.
The bomb has 5 regular phases. The first four are worth 10 points, and the fifth phase is worth 15, for a total of 55 points. The 6th phase is extra credit, and rumor has it that a secret 7th phase exists. If it does and you can find and defuse it, you will receive additional extra credit points. The phases get progressively harder to defuse, but the expertise you gain as you move from phase to phase should offset this difficulty. Nonetheless, the latter phases are not easy, so please don't wait until the last minute to start. (If you're stumped, check the hints section at the end of this document, and come see me and/or the TAs.)
Here are some hints for what to think about at each stage: (1) comparison, (2) loops, (3) switch statements, (4) recursion, (5) pointers and arrays, (6) sorting linked lists.
The bomb ignores blank input lines. If you run your bomb with a command line argument, for example,
./bomb defuser.txt
then it will read the input lines from defuser.txt until it reaches
EOF (end of file), and then switch over to stdin (standard input from
the terminal). In a moment of weakness, Dr. Evil added this feature so
you don't have to keep retyping the solutions to phases you have
already defused, instead you can put them in defuser.txt
.
When formatting your defuser.txt file, please remember to:
1. This is my answer for phase 1
).To avoid accidentally detonating the bomb, you will need to learn how to single-step through the assembly code in gdb 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.
Resources
There are a number of online resources that will help you understand any assembly instructions you may encounter while examining the bomb. In particular, the programming manuals for x86-64 processors distributed by Intel and AMD are exceptionally valuable. They both describe the same ISA, but sometimes one may be easier to understand than the other. In addition, you can also refer to your textbook.
Important Note: The instruction format used in the Intel and AMD manuals is known as “Intel format”. This format is very different than the format used in our text, in lecture slides, and in what is produced by gcc, objdump and other tools (which is known as “AT&T format”. You can read more about these differences in our textbook (on p. 177 of your book) or on Wikipedia. The biggest difference is that the order of operands is SWITCHED. This also serves as a warning that you may see both formats come up in web searches.
Speaking of web searches, under no circumstances are you to search for anything involving the words "binary bomb" on the Internet. This would obviously be a violation of the Honor Code. There are many incorrect solutions out there, and they would truly be detrimental in the long run.
Tools and Hints (Read This!!)
The x86-64 ISA passes the first six arguments to a function in
registers. Registers are used in the following
order: rdi
, rsi
, rdx
, rcx
, r8
, r9
. The
return value for functions is passed in rax
.
There are many ways of defusing your bomb. You can print out the assembly and 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. Both are useful skills to develop.
Please do not use brute force! You could write a program that will try every possible key to find the right one, but the number of possibilities is so large that you won't be able to try them all in time, and you'll lose points each time you blow up the bomb.
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.
gdb
: The GNU debugger is a command line debugger
tool available on virtually every platform. 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. Here are some tips for using gdb
.
help
at
the gdb
command prompt, or type "man
gdb", or "info gdb" at a Unix prompt. Some people
also like to run gdb
under gdb-mode in emacsobjdump -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 may look cryptic. 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 -t x bomb
: This utility will display the
printable strings in your bomb and their offset within the
bomb.Looking for a particular tool? How about documentation? Don't
forget, the commands apropos
and man
are
your friends. In particular, man ascii
is more useful
than you'd think.
Scoreboard
Track the progress of your classmates. Check out the scoreboard for more info.
Final scores available here.