A short session with gdb verifies a few facts; the student has made notes of some observations:

Size: px
Start display at page:

Download "A short session with gdb verifies a few facts; the student has made notes of some observations:"

Transcription

1 This assignment refers to concepts discussed in the course notes on gdb and the book The Art of Debugging by Matloff & Salzman. The questions are definitely "hands-on" and will require some reading beyond the course notes. Download the file HW10.tar and unpack it on a Linux system. It contains files you will need for this assignment. You may work in pairs for this assignment. If you choose to work with a partner, make sure only one of you submits a solution and that the file lists names and PIDs for both of you. Prepare your answers to the following questions in a single plain ASCII text file. Submit your file to the Curator system by the posted deadline for this assignment. No late submissions will be accepted. You will submit your answers to the Curator System ( under the heading HW [26 points] A student is testing an implementation of the following C function: /** * Computes and returns sum of A[0]:A{Sz-1]. * Pre: * A points to an array of dimension at least Sz * A[0:Sz-1] are initialized * Returns: * sum of A[0] through A[Sz-1] */ int AddEm(const int* A, int Sz); Unfortunately, the student does not have the C source code for the implementation; instead, she has an object file obtained by compiling AddEm.c with the following command: gcc -c -O0 -m32 -std=c99 -Wall AddEm.c As you can see, the object file is compiled to 32-bit instructions, with no optimizations, and (alas) with no debugging information added (since the build did not include the switch g or ggdb3). So, while the student can use gdb to analyze the execution of the function (after writing a driver for it), but gdb will be less useful than she might like. A short session with gdb verifies a few facts; the student has made notes of some observations: 2107: Q1 > gdb Q1main (gdb) list 1 #include <stdio.h> 2 #include "AddEm.h" 3 4 int main() { 5 6 int Sz = 5; 7 int A[5] = {32, 16, 64, 4, 8}; 8 9 int Sum = AddEm(A, Sz); 10 Here's part of my driver code. Note that AddEm() should have returned the sum 124. Pause execution at the beginning of main(). (gdb) break main Breakpoint 1 at 0x80483cd: file Q1main.c, line 6. 1

2 (gdb) run Starting program: /home/jillhokie/hw10/q1/q1main Breakpoint 1, main () at Q1main.c:6 6 int Sz = 5; (gdb) n 7 int A[5] = {32, 16, 64, 4, 8}; (gdb) n 9 int Sum = AddEm(A, Sz); (gdb) p *A@5 $1 = {32, 16, 64, 4, 8} (gdb) print/x &A[0] $9 = 0xffffd7e4 (gdb) p Sum $2 = A points to an array; this prints the first 5 elements. Let's see the address of the array; it's passed in the function call. Sum holds garbage; hasn't been initialized yet. OK. (gdb) n 11 printf("sum is %d\n", Sum); (gdb) p Sum $3 = Sum is obviously wrong why did that happen? Now, we see that the return value from AddEm() is wrong badly wrong. In order to pin down the reason, the student must examine the execution of the instructions in AddEm() itself, but she will not be able to see the C source code. Here's another gdb session: 2108: Q1 > gdb Q1main (gdb) break main Breakpoint 1 at 0x80483cd: file Q1main.c, line 6. (gdb) break AddEm Breakpoint 2 at 0x804843a Pause when AddEm() is called. (gdb) run Starting program: /home/jillhokie/hw10/q1/q1main Breakpoint 1, main () at Q1main.c:6 6 int Sz = 5; (gdb) continue Continuing. Breakpoint 2, 0x a in AddEm () (gdb) disassem Let's look at AddEm() as x86 code. Dump of assembler code for function AddEm: 0x <+0>: push %ebp 0x <+1>: mov %esp,%ebp 0x <+3>: sub $0x10,%esp => 0x a <+6>: movl $0x0,-0x4(%ebp) 0x <+13>: mov 0xc(%ebp),%eax 0x <+16>: shl $0x2,%eax 0x <+19>: add 0x8(%ebp),%eax 0x a <+22>: mov %eax,-0x8(%ebp) 0x d <+25>: jmp 0x804845b <AddEm+39> 0x f <+27>: mov 0x8(%ebp),%eax Stack frame setup nor relevant. Here's the next instruction to be executed. Looks like we have parameters at ebp + 8 and ebp

3 0x <+30>: mov (%eax),%eax 0x <+32>: add %eax,-0x4(%ebp) 0x <+35>: addl $0x1,0x8(%ebp) 0x b <+39>: mov 0x8(%ebp),%eax 0x e <+42>: cmp -0x8(%ebp),%eax 0x <+45>: jb 0x804844f <AddEm+27> 0x <+47>: mov -0x4(%ebp),%eax 0x <+50>: leave 0x <+51>: ret End of assembler dump. (gdb) p/x $ebp + 8 $1 = 0xffffd7d0 (gdb) p/x $ebp + 12 $2 = 0xffffd7d4 (gdb) p/x *($ebp + 12) Attempt to dereference a generic pointer. Looks like we have local variables at ebp - 4 and ebp - 8 I can print register contents! Note use of '$'. And I can print expressions using register names! Now, $ebp + 12 is the address of a word on the stack, presumably it's the second parameter, Sz. Oops need a typecast! (gdb) p/x *(int*)($ebp + 12) $3 = 0x5 (gdb) p/x *(int*)($ebp + 8) $4 = 0xffffd7e4 (gdb) p *$4 $5 = 32 (gdb) p *$4@5 $6 = {32, 16, 64, 4, 8} Yes, that's Sz! And that's the address of the array! I can refer to previously-displayed values by the symbolic names gdb gives them. Now, AddEm() must compute the sum of the array values examining the x86 code above suggests where this is being done: => 0x a <+6>: movl $0x0,-0x4(%ebp) # sum? 0x <+13>: mov 0xc(%ebp),%eax # get array size 0x <+16>: shl $0x2,%eax # multiply it by 4? 0x <+19>: add 0x8(%ebp),%eax # add to array address? 0x a <+22>: mov %eax,-0x8(%ebp) # put in local variable 0x d <+25>: jmp 0x804845b <AddEm+39> # jump to loop test 0x f <+27>: mov 0x8(%ebp),%eax # loop start 0x <+30>: mov (%eax),%eax # retrieve value 0x <+32>: add %eax,-0x4(%ebp) # add it to sum 0x <+35>: addl $0x1,0x8(%ebp) # add 1 to ptr 0x b <+39>: mov 0x8(%ebp),%eax # fetch pointer 0x e <+42>: cmp -0x8(%ebp),%eax # loop test 0x <+45>: jb 0x804844f <AddEm+27> It looks like the sum is being accumulated in a local variable at $ebp 4. And it looks like we're storing a pointer into the array at $ebp + 8 (making the parameter serve double duty). Now, if so, we can trace through the code for AddEm() with some understanding of what's going on there. But, we have to use the right gdb commands to step through the assembly code. 3

4 0x in AddEm () 0x in AddEm () 0x in AddEm () 0x a in AddEm () 0x d in AddEm () I can tell what s being executed by comparing the instruction addresses shown after each ni command to the disassembly of the code. (gdb) disassem 0x a <+6>: movl $0x0,-0x4(%ebp) 0x <+13>: mov 0xc(%ebp),%eax 0x <+16>: shl $0x2,%eax 0x <+19>: add 0x8(%ebp),%eax 0x a <+22>: mov %eax,-0x8(%ebp) => 0x d <+25>: jmp 0x804845b <AddEm+39> 0x f <+27>: mov 0x8(%ebp),%eax 0x <+30>: mov (%eax),%eax 0x <+32>: add %eax,-0x4(%ebp) 0x <+35>: addl $0x1,0x8(%ebp) 0x b <+39>: mov 0x8(%ebp),%eax 0x e <+42>: cmp -0x8(%ebp),%eax 0x <+45>: jb 0x804844f <AddEm+27> 0x <+47>: mov -0x4(%ebp),%eax 0x <+50>: leave 0x <+51>: ret The value at $ebp 8 is used in the loop test what is it? What does 0xffffd7f8 have to do with anything wait 0xffffd7f8 0xffffd7e4 is 0x14 or 20 that s the size of the array (in bytes) (gdb) p/x *(int*)($ebp - 8) $8 = 0xffffd7f8 0x b in AddEm () 0x e in AddEm () 0x in AddEm () 0x f in AddEm () 0x in AddEm () (gdb) p/x $eax $10 = 0xffffd7e4 0x in AddEm () (gdb) p/x $eax $11 = 0x20 (gdb) p $eax $12 = 32 Use ni to step through the machine code again. I've stepped to the instruction at 0x f: mov 0x8(%ebp),%eax Step once more to execute that instruction OK, eax stores the address of the array, which I displayed earlier Step again, to execute mov (%eax),%eax and I just loaded the first value from the array. 0x in AddEm () (gdb) 0x b in AddEm () 4

5 (gdb) p *(int*)($ebp - 4) $14 = 32 0x e in AddEm () 0x in AddEm () 0x f in AddEm () 0x in AddEm () 0x in AddEm () 0x in AddEm () (gdb) p *(int*)($ebp - 4) $15 = (gdb) p $eax $16 = (gdb) p/x *(int*)($ebp + 8) $18 = 0xffffd7e5 I just executed add %eax,-0x4(%ebp) and I m pretty sure that Sum is the local at $ebp 4; OK, the sum is now 32 correct so far. I ll step through the loop again and see what happens on the second pass there s the instruction that updates the sum. OK, Sum is now wildly wrong That's what I just added to Sum that's badly wrong too! And that tells me why Now, that last display is the essential clue the student needed to deduce what was wrong with the implementation of AddEm(). Of course, she might want to further reverse-engineer C from the x86 code to verify her conclusion. a) [10 points] Given the gdb sessions displayed above, what conclusion should the student have reached about the error in the implementation of AddEm()? b) [16 points] Justify your conclusion for part a) carefully. Your justification should definitely cite relevant information from the gdb sessions, and possibly also involve some reverse-engineering of the x86 code. 5

6 2. Another student is testing an implementation of the following C function: /** * Fills array A of dimension Sz with integer squares. * Pre: * A points to an array of dimension Sz (or larger) * Post: * A[k] = k * k, for k = 0:Sz-1 */ void WriteSquares(int* const A, int Sz); As in question 1, the student only has an object file for the function implementation. However, in this case it appears that the implementation does what is required. However, the student suspects his testing may be missing an arraybounds error within the implementation of WriteSquares(). So, the student writes some clever code to see if his hunch about the implementation is correct: The cleverness in this code is that the student has guaranteed that there is a known value (a canary value) just before the first element of the array, and just after the last element of the array. If the implementation of WriteSquares() does violate the array bounds, we should see a change in one or both of the canary values after WriteSquares() returns. #include <stdlib.h> #define CANARY 0XDEADBEEF #include "WriteSquares.h" int main() { DEADBEEF int Sz = 100; int* MemoryBlock = malloc(sz * sizeof(int) + 8); if ( MemoryBlock == NULL ) return 1; *MemoryBlock = CANARY; *(MemoryBlock + 101) = CANARY; int* A = MemoryBlock + 1; DEADBEEF // We suspect this function may contain a bug // (or two), and it may write outside the proper // boundaries of the array A of dimension Sz: WriteSquares(A, Sz); } free(memoryblock); return 0; a) [13 points] Use gdb to examine the results of the call to WriteSquares(). Hint: setting an appropriate watchpoint in gdb can yield a very fast resolution of the question. b) [13 points] Use gdb or objdump to analyze what's wrong with the implementation of WriteSquares(). You must show your gdb session, or your output from objdump and reverse-engineering to support your conclusion. 6

7 3. The directory Q3 (created when you unpacked the tar file referred to above) contains three files: Q3main.c, Q3.h and Q3.o. The object file contains the compiled code for the function Q3() declared in the header file. Q3main.c contains a main() function designed to call Q3(); read the comments in Q3main.c. Experiment a bit with the code; you will discover that running Q3main results in a runtime error, unless you get very lucky and use a parameter to Q3() that satisfies a particular constraint. You must determine what constraint the parameter to Q3() must satisfy in order to avoid the runtime error. Brute force attacks can answer the question and will receive no credit. There are several ways to analyze this situation, and you have a number of tools available to aid you. You can use gdb to examine the execution of the code. You can also use objdump,with the d switch, to display the assembly code for an object or executable file. You must state the constraint the parameter to Q3() must satisfy and show what rational analysis you performed to determine the constraint. You can justify your conclusion by showing a transcript of a gdb session and/or showing objdump output with an analysis of the x86 assembly code. (It's easy to copy text from a Linux shell window and paste it into a text editor.) a) [8 points] Identify the exact assembly/machine instruction within Q3() at which the runtime error occurs. Show exactly how you determined your answer. b) [8 points] Analyze the instruction you identified in part a), and explain exactly why executing this instruction would cause a runtime error. c) [8 points] For what parameter value(s) will Q3() not trigger a segmentation fault? Show exactly how you determined your answer(s) to this question; guessing is not a valid technique, nor is experimentation with different parameter values. 4. Repeat question 1, but with the files Q4main.c, Q4.h and Q4.o. a) [8 points] Identify the exact assembly/machine instruction within Q4() at which the runtime error occurs. Show exactly how you determined your answer. b) [8 points] Analyze the instruction you identified in part a), and explain exactly why executing this instruction would cause a runtime error. c) [8 points] For what parameter value(s) will Q4() not trigger a segmentation fault? Show exactly how you determined your answer(s) to this question; guessing is not a valid technique, nor is experimentation with different parameter values. 7

int32_t Buffer[BUFFSZ] = {-1, -1, -1, 1, -1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, -1, -1, -1, -1, -1}; int32_t* A = &Buffer[5];

int32_t Buffer[BUFFSZ] = {-1, -1, -1, 1, -1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, -1, -1, -1, -1, -1}; int32_t* A = &Buffer[5]; This assignment refers to concepts discussed in the course notes on gdb and the book The Art of Debugging by Matloff & Salzman. The questions are definitely "hands-on" and will require some reading beyond

More information

1. A student is testing an implementation of a C function; when compiled with gcc, the following x86-32 assembly code is produced:

1. A student is testing an implementation of a C function; when compiled with gcc, the following x86-32 assembly code is produced: This assignment refers to concepts discussed in the course notes on gdb and the book The Art of Debugging by Matloff & Salzman. The questions are definitely "hands-on" and will require some reading beyond

More information

1. A student is testing an implementation of a C function; when compiled with gcc, the following x86-64 assembly code is produced:

1. A student is testing an implementation of a C function; when compiled with gcc, the following x86-64 assembly code is produced: This assignment refers to concepts discussed in sections 2.1.1 2.1.3, 2.1.8, 2.2.1 2.2.6, 3.2, 3.4, and 3.7.1of csapp; see that material for discussions of x86 assembly language and its relationship to

More information

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

Download the tarball for this session. It will include the following files:

Download the tarball for this session. It will include the following files: Getting Started 1 Download the tarball for this session. It will include the following files: driver driver.c bomb.h bomb.o 64-bit executable C driver source declaration for "bomb" 64-bit object code for

More information

Download the tarball for this session. It will include the following files:

Download the tarball for this session. It will include the following files: Getting Started 1 Download the tarball for this session. It will include the following files: driver driver.c bomb.h bomb.o 64-bit executable C driver source declaration for "bomb" 64-bit object code for

More information

CS 2505 Computer Organization I

CS 2505 Computer Organization I Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11 X86 Debug Computer Systems Section 3.11 GDB is a Source Level debugger We have learned how to debug at the C level Now, C has been translated to X86 assembler! How does GDB play the shell game? Makes it

More information

CS 3214 Spring # Problem Points Min Max Average Median SD Grader. 1 Memory Layout and Locality Bill

CS 3214 Spring # Problem Points Min Max Average Median SD Grader. 1 Memory Layout and Locality Bill CS 3214 # Problem Points Min Max Average Median SD Grader 1 Memory Layout and Locality 25 2 25 14.2 14 5.7 Bill 2 Stack 25 3 22 12.6 13 4.2 Peter 3 Compilation and Linking 25 0 19 7.6 6 4.7 Maggie 4 Execution

More information

CS 2505 Computer Organization I

CS 2505 Computer Organization I Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

CSE 361S Intro to Systems Software Lab Assignment #4

CSE 361S Intro to Systems Software Lab Assignment #4 Due: Thursday, October 23, 2008. CSE 361S Intro to Systems Software Lab Assignment #4 In this lab, you will mount a buffer overflow attack on your own program. As stated in class, we do not condone using

More information

Compila(on, Disassembly, and Profiling

Compila(on, Disassembly, and Profiling Compila(on, Disassembly, and Profiling (in Linux) CS 485: Systems Programming Fall 2015 Instructor: James Griffioen 1 Recall the compila(on process/steps 2 Turning C into Object Code Code in files p1.c

More information

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer

More information

Lecture 08 Control-flow Hijacking Defenses

Lecture 08 Control-flow Hijacking Defenses Lecture 08 Control-flow Hijacking Defenses Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Slides adapted from Miller, Bailey, and Brumley Control Flow Hijack: Always control + computation

More information

Machine Language, Assemblers and Linkers"

Machine Language, Assemblers and Linkers Machine Language, Assemblers and Linkers 1 Goals for this Lecture Help you to learn about: IA-32 machine language The assembly and linking processes 2 1 Why Learn Machine Language Last stop on the language

More information

CS 3214 Computer Systems. Do not start the test until instructed to do so! printed

CS 3214 Computer Systems. Do not start the test until instructed to do so! printed Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

15-213/18-243, Fall 2010 Exam 1 - Version A

15-213/18-243, Fall 2010 Exam 1 - Version A Andrew login ID: Full Name: Section: 15-213/18-243, Fall 2010 Exam 1 - Version A Tuesday, September 28, 2010 Instructions: Make sure that your exam is not missing any sheets, then write your Andrew login

More information

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page fact sheet. Your fact sheet may contain definitions and examples,

More information

buffer overflow exploitation

buffer overflow exploitation buffer overflow exploitation Samuele Andreoli, Nicolò Fornari, Giuseppe Vitto May 11, 2016 University of Trento Introduction 1 introduction A Buffer Overflow is an anomaly where a program, while writing

More information

EECS 213 Introduction to Computer Systems Dinda, Spring Homework 3. Memory and Cache

EECS 213 Introduction to Computer Systems Dinda, Spring Homework 3. Memory and Cache Homework 3 Memory and Cache 1. Reorder the fields in this structure so that the structure will (a) consume the most space and (b) consume the least space on an IA32 machine on Linux. struct foo { double

More information

Buffer Overflow Attack

Buffer Overflow Attack Buffer Overflow Attack What every applicant for the hacker should know about the foundation of buffer overflow attacks By (Dalgona@wowhacker.org) Email: zinwon@gmail.com 2005 9 5 Abstract Buffer overflow.

More information

CSC 373, Winter 2012 Lab Assignment 3: The Buffer Bomb

CSC 373, Winter 2012 Lab Assignment 3: The Buffer Bomb CSC 373, Winter 2012 Lab Assignment 3: The Buffer Bomb Contact Glenn Lancaster (glancast@cs.depaul.edu) for questions/hints on this assignment. Introduction This assignment helps you develop a detailed

More information

Exercise Session 6 Computer Architecture and Systems Programming

Exercise Session 6 Computer Architecture and Systems Programming Systems Group Department of Computer Science ETH Zürich Exercise Session 6 Computer Architecture and Systems Programming Herbstsemester 2016 Agenda GDB Outlook on assignment 6 GDB The GNU Debugger 3 Debugging..

More information

Advanced Buffer Overflow

Advanced Buffer Overflow Pattern Recognition and Applications Lab Advanced Buffer Overflow Ing. Davide Maiorca, Ph.D. davide.maiorca@diee.unica.it Computer Security A.Y. 2016/2017 Department of Electrical and Electronic Engineering

More information

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION Today: Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics:

More information

Intro x86 Part 3: Linux Tools & Analysis

Intro x86 Part 3: Linux Tools & Analysis Intro x86 Part 3: Linux Tools & Analysis Xeno Kovah 2009/2010 xkovah at gmail Approved for Public Release: 10-3348. Distribution Unlimited All materials is licensed under a Creative Commons Share Alike

More information

Lab 10: Introduction to x86 Assembly

Lab 10: Introduction to x86 Assembly CS342 Computer Security Handout # 8 Prof. Lyn Turbak Wednesday, Nov. 07, 2012 Wellesley College Revised Nov. 09, 2012 Lab 10: Introduction to x86 Assembly Revisions: Nov. 9 The sos O3.s file on p. 10 was

More information

Buffer-Overflow Attacks on the Stack

Buffer-Overflow Attacks on the Stack Computer Systems Buffer-Overflow Attacks on the Stack Introduction A buffer overflow occurs when a program, while writing data to a buffer, overruns the buffer's boundary and overwrites memory in adjacent

More information

CS356: Discussion #5 Debugging with GDB. Marco Paolieri

CS356: Discussion #5 Debugging with GDB. Marco Paolieri CS356: Discussion #5 Debugging with GDB Marco Paolieri (paolieri@usc.edu) Schedule: Exams and Assignments Week 1: Binary Representation HW0. Week 2: Integer Operations Week 3: Floating-Point Operations

More information

Machine Programming 1: Introduction

Machine Programming 1: Introduction Machine Programming 1: Introduction CS61, Lecture 3 Prof. Stephen Chong September 8, 2011 Announcements (1/2) Assignment 1 due Tuesday Please fill in survey by 5pm today! Assignment 2 will be released

More information

Both parts center on the concept of a "mesa", and make use of the following data type:

Both parts center on the concept of a mesa, and make use of the following data type: C Programming Simple Array Processing This assignment consists of two parts. The first part focuses on array read accesses and computational logic. The second part requires solving the same problem using

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures ISAs Brief history of processors and architectures C, assembly, machine code Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface contain?

More information

CSCE 212H, Spring 2008 Lab Assignment 3: Assembly Language Assigned: Feb. 7, Due: Feb. 14, 11:59PM

CSCE 212H, Spring 2008 Lab Assignment 3: Assembly Language Assigned: Feb. 7, Due: Feb. 14, 11:59PM CSCE 212H, Spring 2008 Lab Assignment 3: Assembly Language Assigned: Feb. 7, Due: Feb. 14, 11:59PM February 7, 2008 1 Overview The purpose of this assignment is to introduce you to the assembly language

More information

CPS104 Recitation: Assembly Programming

CPS104 Recitation: Assembly Programming CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in

More information

Buffer-Overflow Attacks on the Stack

Buffer-Overflow Attacks on the Stack Computer Systems Buffer-Overflow Attacks on the Stack Introduction A buffer overflow occurs when a program, while writing data to a buffer, overruns the buffer's boundary and overwrites memory in adjacent

More information

Advanced Buffer Overflow

Advanced Buffer Overflow Pattern Recognition and Applications Lab Advanced Buffer Overflow Ing. Davide Maiorca, Ph.D. davide.maiorca@diee.unica.it Computer Security A.Y. 2017/2018 Department of Electrical and Electronic Engineering

More information

CSC 2400: Computing Systems. X86 Assembly: Function Calls

CSC 2400: Computing Systems. X86 Assembly: Function Calls CSC 24: Computing Systems X86 Assembly: Function Calls 1 Lecture Goals Challenges of supporting functions Providing information for the called function Function arguments and local variables Allowing the

More information

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm

More information

UW CSE 351, Winter 2013 Midterm Exam

UW CSE 351, Winter 2013 Midterm Exam Full Name: Student ID: UW CSE 351, Winter 2013 Midterm Exam February 15, 2013 Instructions: Make sure that your exam is not missing any of the 9 pages, then write your full name and UW student ID on the

More information

Tales of the Unknown. Part One.

Tales of the Unknown. Part One. Tales of the Unknown Part One www.felinemenace.org Table of Contents Introduction... 3 Requisites... 3 The Story... 3 A look at Initialization...4 Compile time...4 Run time...5 A look at Dereferencing...

More information

The assignment requires solving a matrix access problem using only pointers to access the array elements, and introduces the use of struct data types.

The assignment requires solving a matrix access problem using only pointers to access the array elements, and introduces the use of struct data types. C Programming Simple Array Processing The assignment requires solving a matrix access problem using only pointers to access the array elements, and introduces the use of struct data types. Both parts center

More information

CS/ECE 354 Practice Midterm Exam Solutions Spring 2016

CS/ECE 354 Practice Midterm Exam Solutions Spring 2016 CS/ECE 354 Practice Midterm Exam Solutions Spring 2016 C Programming 1. The reason for using pointers in a C program is a. Pointers allow different functions to share and modify their local variables.

More information

15-213/18-213, Fall 2011 Exam 1

15-213/18-213, Fall 2011 Exam 1 Andrew ID (print clearly!): Full Name: 15-213/18-213, Fall 2011 Exam 1 Tuesday, October 18, 2011 Instructions: Make sure that your exam is not missing any sheets, then write your Andrew ID and full name

More information

You may work with a partner on this quiz; both of you must submit your answers.

You may work with a partner on this quiz; both of you must submit your answers. Instructions: Choose the best answer for each of the following questions. It is possible that several answers are partially correct, but one answer is best. It is also possible that several answers are

More information

Project 1 Notes and Demo

Project 1 Notes and Demo Project 1 Notes and Demo Overview You ll be given the source code for 7 short buggy programs (target[1-7].c). These programs will be installed with setuid root Your job is to write exploits (sploit[1-7].c)

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures! ISAs! Brief history of processors and architectures! C, assembly, machine code! Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface

More information

EECS 213, Fall 2009 Exploit Lab

EECS 213, Fall 2009 Exploit Lab EECS 213, Fall 2009 Exploit Lab Introduction This assignment helps you develop a detailed understanding of the calling stack organization on an IA32 processor. It involves applying a series of buffer overflow

More information

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. This examination is closed book and closed

More information

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so! printed Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. This examination is closed book and closed

More information

Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley

Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley Computer Systems Architecture I CSE 560M Lecture 3 Prof. Patrick Crowley Plan for Today Announcements Readings are extremely important! No class meeting next Monday Questions Commentaries A few remaining

More information

The First Real Bug. gdb. Computer Organization I McQuain

The First Real Bug. gdb. Computer Organization I McQuain The First Real Bug 1 Debugging vs Testing 2 Software testing is any activity aimed at evaluating an attribute or capability of a program and determining whether it meets its specified results All about

More information

The Dynamic Debugger gdb

The Dynamic Debugger gdb Introduction The Dynamic Debugger gdb This handout introduces the basics of using gdb, a very powerful dynamic debugging tool. No-one always writes programs that execute perfectly every time, and while

More information

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Machine-level Representation of Programs Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Program? 짬뽕라면 준비시간 :10 분, 조리시간 :10 분 재료라면 1개, 스프 1봉지, 오징어

More information

Creating a String Data Type in C

Creating a String Data Type in C C Programming Creating a String Data Type in C For this assignment, you will use the struct mechanism in C to implement a data type that models a character string: struct _String { char data; dynamically-allocated

More information

CS 105, Fall Lab 4: The Buffer Bomb. See Calendar for Dates

CS 105, Fall Lab 4: The Buffer Bomb. See Calendar for Dates CS 105, Fall 2003 Lab 4: The Buffer Bomb See Calendar for Dates October 15, 2003 8h 39min Geoff (geoff@cs.cmu.edu) and Mike(mike@cs.cmu.edu) are the leads for this assignment. Introduction This assignment

More information

CS / ECE , Spring 2010 Exam 1

CS / ECE , Spring 2010 Exam 1 Andrew login ID: Full Name: Recitation Section: CS 15-213 / ECE 18-243, Spring 2010 Exam 1 Version 1100101 Tuesday, March 2nd, 2010 Instructions: Make sure that your exam is not missing any sheets, then

More information

Systems I. Machine-Level Programming I: Introduction

Systems I. Machine-Level Programming I: Introduction Systems I Machine-Level Programming I: Introduction Topics Assembly Programmerʼs Execution Model Accessing Information Registers IA32 Processors Totally Dominate General Purpose CPU Market Evolutionary

More information

Is stack overflow still a problem?

Is stack overflow still a problem? Morris Worm (1998) Code Red (2001) Secure Programming Lecture 4: Memory Corruption II (Stack Overflows) David Aspinall, Informatics @ Edinburgh 31st January 2017 Memory corruption Buffer overflow remains

More information

Memory, Data, & Addressing II CSE 351 Spring

Memory, Data, & Addressing II CSE 351 Spring Memory, Data, & Addressing II CSE 351 Spring 2018 http://xkcd.com/138/ Review Questions 1) If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) a) 64

More information

MACHINE-LEVEL PROGRAMMING I: BASICS

MACHINE-LEVEL PROGRAMMING I: BASICS MACHINE-LEVEL PROGRAMMING I: BASICS CS 429H: SYSTEMS I Instructor: Emmett Witchel Today: Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics:

More information

ANITA S SUPER AWESOME RECITATION SLIDES

ANITA S SUPER AWESOME RECITATION SLIDES ANITA S SUPER AWESOME RECITATION SLIDES 15/18-213: Introduction to Computer Systems Stacks and Buflab, 11 Jun 2013 Anita Zhang, Section M WHAT S NEW (OR NOT) Bomblab is due tonight, 11:59 PM EDT Your late

More information

Problem Set 1: Unix Commands 1

Problem Set 1: Unix Commands 1 Problem Set 1: Unix Commands 1 WARNING: IF YOU DO NOT FIND THIS PROBLEM SET TRIVIAL, I WOULD NOT RECOMMEND YOU TAKE THIS OFFERING OF 300 AS YOU DO NOT POSSESS THE REQUISITE BACKGROUND TO PASS THE COURSE.

More information

CS354 gdb Tutorial Written by Chris Feilbach

CS354 gdb Tutorial Written by Chris Feilbach CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that

More information

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 5

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 5 Jackson State University Department of Computer Science CSC 439-01/539-02 Advanced Information Security Spring 2013 Lab Project # 5 Use of GNU Debugger (GDB) for Reverse Engineering of C Programs in a

More information

Università Ca Foscari Venezia

Università Ca Foscari Venezia Stack Overflow Security 1 2018-19 Università Ca Foscari Venezia www.dais.unive.it/~focardi secgroup.dais.unive.it Introduction Buffer overflow is due to careless programming in unsafe languages like C

More information

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic: Pointer Manipulations Pointer Casts and Data Accesses Viewing Memory The contents of a block of memory may be viewed as a collection of hex nybbles indicating the contents of the byte in the memory region;

More information

Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT

Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT CS33 Intro to Computer Systems XI 1 Copyright 2017 Thomas

More information

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux

CNIT 127: Exploit Development. Ch 2: Stack Overflows in Linux CNIT 127: Exploit Development Ch 2: Stack Overflows in Linux Stack-based Buffer Overflows Most popular and best understood exploitation method Aleph One's "Smashing the Stack for Fun and Profit" (1996)

More information

Instructions: Submit your answers to these questions to the Curator as OQ02 by the posted due date and time. No late submissions will be accepted.

Instructions: Submit your answers to these questions to the Curator as OQ02 by the posted due date and time. No late submissions will be accepted. Instructions: Submit your answers to these questions to the Curator as OQ02 by the posted due date and time. No late submissions will be accepted. For the next five questions, consider the function to

More information

20: Exploits and Containment

20: Exploits and Containment 20: Exploits and Containment Mark Handley Andrea Bittau What is an exploit? Programs contain bugs. These bugs could have security implications (vulnerabilities) An exploit is a tool which exploits a vulnerability

More information

Introduction to Computer Systems , fall th Lecture, Sep. 28 th

Introduction to Computer Systems , fall th Lecture, Sep. 28 th Introduction to Computer Systems 15 213, fall 2009 9 th Lecture, Sep. 28 th Instructors: Majd Sakr and Khaled Harras Last Time: Structures struct rec { int i; int a[3]; int *p; }; Memory Layout i a p 0

More information

CSC 405 Computer Security Stack Canaries & ASLR

CSC 405 Computer Security Stack Canaries & ASLR CSC 405 Computer Security Stack Canaries & ASLR Alexandros Kapravelos akaprav@ncsu.edu How can we prevent a buffer overflow? Check bounds Programmer Language Stack canaries [...more ] Buffer overflow defenses

More information

Pointer Casts and Data Accesses

Pointer Casts and Data Accesses C Programming Pointer Casts and Data Accesses For this assignment, you will implement a C function similar to printf(). While implementing the function you will encounter pointers, strings, and bit-wise

More information

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1 Homework In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, 361-367 Practice Exam 1 1 In-line Assembly Code The gcc compiler allows you to put assembly instructions in-line

More information

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11 X86 Debug Computer Systems Section 3.11 GDB is a Source Level debugger We have learned how to debug at the C level But the machine is executing X86 object code! How does GDB play the shell game? Makes

More information

CS , Fall 2009 Exam 1

CS , Fall 2009 Exam 1 Andrew login ID: Full Name: Recitation Section: CS 15-213, Fall 2009 Exam 1 Thursday, September 24, 2009 Instructions: Make sure that your exam is not missing any sheets, then write your full name, Andrew

More information

University*of*Washington*

University*of*Washington* Roadmap* C:* car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly* language:* Machine* code:* Computer* system:* get_mpg: pushq movq... popq ret %rbp %rsp,

More information

18-600: Recitation #3

18-600: Recitation #3 18-600: Recitation #3 Bomb Lab & GDB Overview September 12th, 2017 1 Today X86-64 Overview Bomb Lab Introduction GDB Tutorial 2 3 x86-64: Register Conventions Arguments passed in registers: %rdi, %rsi,

More information

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32 GDB Tutorial Young W. Lim 2017-02-14 Tue Young W. Lim GDB Tutorial 2017-02-14 Tue 1 / 32 Outline 1 Introduction Young W. Lim GDB Tutorial 2017-02-14 Tue 2 / 32 Based on "Self-service Linux: Mastering the

More information

Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics.

Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics. Lecture 6B Machine-Level Programming V: Miscellaneous Topics Topics Linux Memory Layout Understanding Pointers Buffer Overflow Upper 2 hex digits of address Red Hat v. 6.2 ~1920MB memory limit FF C0 Used

More information

mp2 Warmup Instructions (Updated 1/25/2016 by Ron Cheung for using VMs)

mp2 Warmup Instructions (Updated 1/25/2016 by Ron Cheung for using VMs) mp2 Warmup Instructions (Updated 1/25/2016 by Ron Cheung for using VMs) Study the lecture notes on the tools and instruction set. Then follow along with this document. Make sure everything works for you

More information

CMPSC 497 Buffer Overflow Vulnerabilities

CMPSC 497 Buffer Overflow Vulnerabilities Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA CMPSC 497 Buffer Overflow

More information

Recitation: Bomb Lab. September 17 th 2018

Recitation: Bomb Lab. September 17 th 2018 15-213 Recitation: Bomb Lab September 17 th 2018 Agenda Logistics - Bomb Lab Overview - Introduction to GDB - GDB and Assembly Tips What is Bomb Lab? An exercise in reading x86-64 assembly code. A chance

More information

CS , Fall 2009 Exam 1

CS , Fall 2009 Exam 1 Andrew login ID: Full Name: Recitation Section: CS 15-213, Fall 2009 Exam 1 Thurs, September 24, 2009 Instructions: Make sure that your exam is not missing any sheets, then write your full name, Andrew

More information

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation Assigned: Sunday, November 14, 2004 Due: Thursday, Dec 9, 2004, at 11:59pm No solution will be accepted after Sunday, Dec 12,

More information

CS341, Spring 2014 The Buffer Bomb Assigned: 9:30AM Thursday, February 27th, 2014 Due: 9:30AM Thursday, March 13th, 2014

CS341, Spring 2014 The Buffer Bomb Assigned: 9:30AM Thursday, February 27th, 2014 Due: 9:30AM Thursday, March 13th, 2014 CS341, Spring 2014 The Buffer Bomb Assigned: 9:30AM Thursday, February 27th, 2014 Due: 9:30AM Thursday, March 13th, 2014 Brady Key (bradykey@gmail.com) is the lead person for this assignment. Introduction

More information

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e CPSC 213 Introduction to Computer Systems Unit 1e Procedures and the Stack 1 Readings for Next 3 Lectures Textbook Procedures - 3.7 Out-of-Bounds Memory References and Buffer Overflow - 3.12 2 Local Variables

More information

CS , Spring 2004 Exam 1

CS , Spring 2004 Exam 1 Andrew login ID: Full Name: CS 15-213, Spring 2004 Exam 1 February 26, 2004 Instructions: Make sure that your exam is not missing any sheets (there should be 15), then write your full name and Andrew login

More information

Introduction Presentation A

Introduction Presentation A CSE 2421/5042: Systems I Low-Level Programming and Computer Organization Introduction Presentation A Read carefully: Bryant Chapter 1 Study: Reek Chapter 2 Skim: Reek Chapter 1 08/22/2018 Gojko Babić Some

More information

Machine-Level Programming I: Introduction Jan. 30, 2001

Machine-Level Programming I: Introduction Jan. 30, 2001 15-213 Machine-Level Programming I: Introduction Jan. 30, 2001 Topics Assembly Programmer s Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate

More information

gcc o driver std=c99 -Wall driver.c bigmesa.c

gcc o driver std=c99 -Wall driver.c bigmesa.c C Programming Simple Array Processing This assignment consists of two parts. The first part focuses on array read accesses and computational logic. The second part focuses on array read/write access and

More information

War Industries Presents: An Introduction to Programming for Hackers Part V - Functions. By Lovepump, Visit:

War Industries Presents: An Introduction to Programming for Hackers Part V - Functions. By Lovepump, Visit: War Industries Presents: An Introduction to Programming for Hackers Part V - Functions By Lovepump, 2004 Visit: www.warindustries.com Goals: At the end of Part IV, you should be able to competently code

More information

Program Exploitation Intro

Program Exploitation Intro Program Exploitation Intro x86 Assembly 04//2018 Security 1 Univeristà Ca Foscari, Venezia What is Program Exploitation "Making a program do something unexpected and not planned" The right bugs can be

More information

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

CSC 2400: Computing Systems. X86 Assembly: Function Calls CSC 24: Computing Systems X86 Assembly: Function Calls" 1 Lecture Goals! Challenges of supporting functions" Providing information for the called function" Function arguments and local variables" Allowing

More information

238P: Operating Systems. Lecture 7: Basic Architecture of a Program. Anton Burtsev January, 2018

238P: Operating Systems. Lecture 7: Basic Architecture of a Program. Anton Burtsev January, 2018 238P: Operating Systems Lecture 7: Basic Architecture of a Program Anton Burtsev January, 2018 What is a program? What parts do we need to run code? Parts needed to run a program Code itself By convention

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 7 LAST TIME Dynamic memory allocation and the heap: A run-time facility that satisfies multiple needs: Programs can use widely varying, possibly

More information

Control flow. Condition codes Conditional and unconditional jumps Loops Switch statements

Control flow. Condition codes Conditional and unconditional jumps Loops Switch statements Control flow Condition codes Conditional and unconditional jumps Loops Switch statements 1 Conditionals and Control Flow Familiar C constructs l l l l l l if else while do while for break continue Two

More information

CS 201 Winter 2014 (Karavanic) Final Exam

CS 201 Winter 2014 (Karavanic) Final Exam CS 201 Winter 2014 (Karavanic) Final Exam Your Name: (1 point) Instructions: - Be sure to write your name on the first sheet. - All answers, and all work submitted in support of answers, should be written

More information