Lab 2: Disassembling and Defusing a Binary Bomb

Assigned Monday, January 23, 2017
Due Date Friday, February 3, 2017 at 5:00pm
Files Available at https://courses.cs.washington.edu/courses/cse351/17wi/labs/lab2/<username>/lab2-bomb.tar (Note: substitute your UWNetID for <username>)
Video You may find this video helpful for getting started with the lab.
Submissions Submit your completed defuser.txt file using the course's Assignment Drop Box. Make sure the file format of your file is correct, so that it can be used as submitted on a CSE VM to defuse your bombs. Details below.

Learning Objectives

Overview

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. 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!

Instructions

The bombs were constructed specifically for 64-bit machines. You should do this assignment on a 64-bit CSE Linux VM or a CSE lab Linux machine or on attu. 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. Get your file and then extract it by executing the following two commands (substituting your UWNetID for <username>):

wget https://courses.cs.washington.edu/courses/cse351/17wi/labs/lab2/<username>/lab2-bomb.tar

tar xvf lab2-bomb.tar

These commands will create a directory called bomb$NUM (where $NUM is the ID of your bomb) with the following files:

Your 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 6th phase is extra credit (worth half as much as a regular phase), 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.)

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.

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.

Useful for this Lab

Important Note: The instruction format used in these 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 the 3e) 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.

Not Directly Useful, but Good Brainfood Nonetheless

x86-64 Calling Conventions

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.

Tools (Read This!!)

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.

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 the number of possibilities is so large that you won't be able to try them all in time.

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.

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. If you get stumped, use the course's discussion board.

Hints

If you're still having trouble figuring out what your bomb is doing, 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.

Submission Instructions (!)

All you submit is your defuser.txt files. So that our grading scripts can use your file as-is to defuse your bombs, please make sure it obeys these formatting rules, otherwise our script is likely to conclude you defused zero bombs: