Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original.

Slides:



Advertisements
Similar presentations
Introduction to the SPL Interpreter
Advertisements

Utilizing the GDB debugger to analyze programs Background and application.
Assembly 01. Outline Binary vs. Text Files Compiler vs. Assembler Mnemonic Assembly Process Development Process Debugging Example 1 this analogy will.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Creating a Program In today’s lesson we will look at: what programming is different types of programs how we create a program installing an IDE to get.
Lab6 – Debug Assembly Language Lab
Introduction to a Programming Environment
Guide To UNIX Using Linux Third Edition
OllyDbg Debuger.
CS 0008 Day 2 1. Today Hardware and Software How computers store data How a program works Operators, types, input Print function Running the debugger.
MBAC 611.  We have been using MS Access to query and modify our databases.  MS Access provides a GUI (Graphical User Interface) that hides much of the.
Recitation: Bomb Lab June 5, 2015 Dipayan Bhattacharya.
F13 Forensic tool analysis Dr. John P. Abraham Professor UTPA.
Gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and.
Application Security Tom Chothia Computer Security, Lecture 14.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
P.1ECE 331, Prof. A. Mason Professor Andrew Mason Michigan State University Spring 2013 ECE 331: PC Lab 1: Using HC12 ASM Simulators.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Carnegie Mellon Linux Boot Camp Jenna MacCarley, Peter Pearson, Shashank Goyal 9/19/2015.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Objective At the conclusion of this chapter you will be able to:
9/2/ CS171 -Math & Computer Science Department at Emory University.
Carnegie Mellon Recitation: Bomb Lab 21 Sep 2015 Monil Shah, Shelton D’Souza.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Slide 1 Project 1 Task 2 T&N3311 PJ1 Information & Communications Technology HD in Telecommunications and Networking Task 2 Briefing The Design of a Computer.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
C++ crash course Class 9 flight times program, using gdb.
Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4: Monday, Sept. 16, 2013 Marjorie Carlson Section A.
S OME USEFUL D EBUG C OMMANDS FOR C LEAR -S PEED S OFTWARE D EVELOPMENT K IT -- COMMANDS FROM CHAP.7 By: Pallav Laskar.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
OUTLINE 2 Pre-requisite Bomb! Pre-requisite Bomb! 3.
Debugging Lab Antonio Gómez-Iglesias Texas Advanced Computing Center.
Editing and Debugging Mumps with VistA and the Eclipse IDE Joel L. Ivey, Ph.D. Dept. of Veteran Affairs OI&T, Veterans Health IT Infrastructure & Security.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
GDB Introduction And Lab 2
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 4, 2010 CSCE 212Honors Computer Organization.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
DEBUG.
Computer System Laboratory
Recitation 5: Attack Lab
Static and dynamic analysis of binaries
Recitation: Bomb Lab _______________ 18 Sep 2017.
More GDB, Intro to x86 Calling Conventions, Control Flow, & Lab 2
Dynamic Analysis ddaa.
Assembly Language Programming Part 3
Debugging with gdb gdb is the GNU debugger on our CS machines.
Recitation: Bomb Lab _______________ 06 Feb 2017.
Malware Incident Response  Dynamic Analysis - 2
gdb gdb is the GNU debugger on our CS machines.
Introduction to Computer Systems
Computer Architecture “Bomb Lab Hints”
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
CSC235 - Visual Studio Tutorial
Homework Reading Programming Assignments Finish K&R Chapter 1
System Level Programming Software College of SCU
Some Assembly (Part 2) set.html.
Debugging.
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
Computer Architecture and System Programming Laboratory
Recitation: Bomb Lab Your TAs September 16th 2019.
Presentation transcript:

Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original source of this document is “CSAP lab”.

Memory & Storage Architecture Seoul National University Bomb lab  Goal  Learn how to read assembly code  Learn how to use the tools necessary to deal with assembly code gdb objdump strings 2

Memory & Storage Architecture Seoul National University Getting Started  Environment  the bomb is complied for IA32 and should thus run on (almost) any sufficiently recent Linux installation the bomb does not do any harm to your computer (only to your score) you might need to install additional software to run the lab If you are trying to run “./bomb” on 64-bit machine … 3

Memory & Storage Architecture Seoul National University Downloading the Bomb  Visit   and fill in your name and student number to download your personalized bomb  Save the bomb file to a directory of your choice, then extract the tar archive: 4

Memory & Storage Architecture Seoul National University Downloading the Bomb  Bombs are custom-built, i.e., each student gets a different bomb  The folder contains a README file with the information you entered 5

Memory & Storage Architecture Seoul National University Inspecting the Bomb’s Source Code  The source code for the main bomb file is provided. From this file, you can get important information on how the bomb runs.  Open a terminal, cd into the bomb directory, and open the bomb. The example below uses the vi editor; if you are not comfortable with vi you can use any other editor: 6

Memory & Storage Architecture Seoul National University Inspecting the Bomb’s Source Code  In the main() function, find the code that reads and checks the input for each phase. In the example below, the code for phase_1 is highlighted 7

Memory & Storage Architecture Seoul National University Inspecting the Bomb’s Source Code  We see that the input string is stored in variable input which is then used as an argument for the function phase_1().  We conclude that it might be a good idea to have a closer look at the function phase_1().  Hint: quit vi by entering “:q” +. If that doesn’t work, hit a couple of times and try entering “:q” + again. 8

Memory & Storage Architecture Seoul National University Running the Bomb  First, let’s see what happened when we run the bomb. Maybe we can guess the input string. Let’s try “test”:  Hmmm…this is not going to work 9

Memory & Storage Architecture Seoul National University Disassembling the Bomb using objdump  objdump can display the bomb’s symbol table (contains names of functions, variables, and other symbols) and also disassemble the code of the bomb.  print the symbol table with objdump –t bomb 10

Memory & Storage Architecture Seoul National University Disassembling the Bomb using objdump  The output is rather long, so let’s dump it to two files  save the symbol table by executing objdump –t bomb > bomb.sysbols  disassemble the bomb’s code and save it to bomb.disas by executing objdump –d bomb > bomb.disas 11

Memory & Storage Architecture Seoul National University Inspecting the code of phase_1()  Open the disassembled code in a text editor and locate phase_1() 12

Memory & Storage Architecture Seoul National University Inspecting the code of phase_1()  From the code we can see that:  phase_1 calls a function called strings_not_equal() with two arguments (it pushes two values on the stack)  then, depending on the result of strings_not_equal() in register %eax either calls explode_bomb() or returns. 13

Memory & Storage Architecture Seoul National University Debugging the Bomb in gdb  With this knowledge we now run the bomb in the GNU debugger  go back to the terminal and  execute gdb bomb  set a breakpoint at phase_1 by  entering break phase_1  run the bomb by entering run  enter the first string and hit enter  now gdb stops at the entry of phase_1 (disassemble with disas ) 14

Memory & Storage Architecture Seoul National University Stepping through the Code  The command step executes the C code line-by-line  the C code for phase_1 is not available, so gdb executed the function phase_1 until the end  not really what we wanted… 15

Memory & Storage Architecture Seoul National University Stepping through the Code  We can set more breakpoints and continue execution until the next breakpoint is reached. Looking at the code, a breakpoint at address 0x08048b32 call 0x seems reasonable.  breakpoints to addresses are set by entering break *  continue execution to the next breakpoint with cont (or simply c)  Now, single-step instruction-by- instruction through the code by executing stepi  step: step through the program line-by-line  stepi: step through the program one (machine) instruction exactly 16

Memory & Storage Architecture Seoul National University Inspecting Registers and Memory  After executing stepi at the call to strings_not_equal, enter disas again to see where we currently are  as expected, the debugger stopped at the first instruction of strings_not_equal  looking at the code, we see that the function loads the two arguments from the stack into registers %esi and %edi  from the name we guess that the function probably compares two strings. The code confirms this assumption: it first calls the string_length function on both strings (0x , 0x804904e) and then compares their length (0x ). If they are not equal, it sets the result to false and exits(0x804905c). If they are equal, it starts comparing the strings character by character (0x ) until the characters differ (0x ) or the end of the string is reached (0x ). 17

Memory & Storage Architecture Seoul National University Inspecting Register and Memory  With this knowledge, we now want to inspect those two strings. The arguments to the function are loaded into registers by the two mov instructions at 0x We thus want to stop after they have been executed. You can either use stepi to reach that location or set another breakpoint at the instruction following the two movs (0x ) and then continue. 18

Memory & Storage Architecture Seoul National University Inspecting Register and Memory  Once we are there, let’s first print the contents of the two registers  Use p/x $ to print the contents of a register in hexadecimal form  enter help print (or help p) to see what options the print command offers 19

Memory & Storage Architecture Seoul National University Inspecting Register and Memory  We assume that both registers contain addresses of strings. Let’s print the contents of the memory at those addresses  Use x/s to dump memory contents at address interpreted as a string (again, use help x do get help on the different options to this function)  Indeed, we see the input string (“test”) as well as another string (“Verbosity leads to unclear, inarticulate things.”)  Could this be the passphrase for phase 1? 20

Memory & Storage Architecture Seoul National University Restarting the Program from the Beginning  Let’s check if the second string is indeed the correct string for phase 1.  Hint: to restart the program, you don’t have to exit gdb, simply type “run” This has the additional benefit that all breakpoints are still set.  Confirm with “y” 21

Memory & Storage Architecture Seoul National University Restarting the Program from the Beginning  The program restarts and asks for the passphrase again. Copy- paste (mark with the mouse, then middle-click) and hit enter.  The program stops at all breakpoints, we are impatient and want to continue  Indeed, we have defused the first stage and the bomb asks us for the second passphrase! 22

Memory & Storage Architecture Seoul National University Now, it’s your turn!  This walk-through showed you how to use the various debugging tools to defuse phase 1. Go on and attack the other phases, one by one.  Scoreboard:  check your score at  If you have any question or problem, send mail to Good Luck! 23