EC312 Review. Rules of Engagement Teams selected by instructor Host will read the entire questions. Only after, a team may “buzz” by raise of hand A team.

Slides:



Advertisements
Similar presentations
Topic Reviews For Unit ET156 – Introduction to C Programming Topic Reviews For Unit
Advertisements

Buffer Overflows Nick Feamster CS 6262 Spring 2009 (credit to Vitaly S. from UT for slides)
Recitation 4 Outline Buffer overflow –Practical skills for Lab 3 Code optimization –Strength reduction –Common sub-expression –Loop unrolling Reminders.
Smashing the Stack for Fun and Profit
Programming and Data Structure
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Files in C Rohit Khokher. Files in C Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two.
The art of exploitation
Kernighan/Ritchie: Kelley/Pohl:
Stack and Queue Dr. Bernard Chen Ph.D. University of Central Arkansas.
1 Day 03 Introduction to C. 2 Memory layout and addresses r s int x = 5, y = 10; float f = 12.5, g = 9.8; char c = ‘r’, d = ‘s’;
1 CIS 205 Practice Test George Lamperti A word that has a predefined meaning in a C++ program and cannot be used as a variable name is known as.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
CS100A, Fall 1997, Lectures 221 CS100A, Fall 1997 Lecture 22, Tuesday 18 November Introduction To C Goal: Acquire a reading knowledge of basic C. Concepts:
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Recursion A recursive function is a function that calls itself either directly or indirectly through another function. The problems that can be solved.
1 The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into.
CMSC 414 Computer and Network Security Lecture 20 Jonathan Katz.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
ITEC 352 Lecture 12 ISA(3). Review Buses Memory ALU Registers Process of compiling.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Pointers OVERVIEW.
STARTING OUT WITH STARTING OUT WITH Class 9 Honors.
Smashing the Stack Overview The Stack Region Buffer Overflow
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
EC week Review. Rules of Engagement Teams selected by instructor Host will read the entire questions. Only after, a team may “buzz” by raise of.
CECS 130 EXAM 1.  int main() { printf (“%c %c \n", 'a', 65); printf ("%d %ld\n", 1977, L); printf (" %10d \n", 1977); printf ("%010d \n", 1977);
CSE 351 Final Exam Review 1. The final exam will be comprehensive, but more heavily weighted towards material after the midterm We will do a few problems.
Functions. Motivation What is a function? A function is a self-contained unit of program code designed to accomplish a particular task. We already used.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Information Security - 2. A Stack Frame. Pushed to stack on function CALL The return address is copied to the CPU Instruction Pointer when the function.
11 PART 2 ARRAYS. 22 PROCESSING ARRAY ELEMENTS Reassigning Array Reference Variables The third statement in the segment below copies the address stored.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Programming Fundamentals. Today’s Lecture Array Fundamentals Arrays as Class Member Data Arrays of Objects C-Strings The Standard C++ string Class.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
EC310 6-week Review. Rules of Engagement Teams selected by instructor Host will read the entire questions. Only after, a team may “buzz” by raise of hand.
EC week Review. Rules of Engagement Teams selected by instructor Host will read the entire questions. Only after, a team may “buzz” by raise of.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
Pointers: Basics. 2 Address vs. Value Each memory cell has an address associated with it
Data Structures & Algorithms CHAPTER 2 Arrays Ms. Manal Al-Asmari.
EC310 6-week Review.
Buffer Overflow Walk-Through
Instructions for test_function
Protecting Memory What is there to protect in memory?
Computer Science 210 Computer Organization
Protecting Memory What is there to protect in memory?
Chapter 4 C Program Control Part I
Chapter 12 Variables and Operators
Protecting Memory What is there to protect in memory?
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Chapter 12 Variables and Operators
Buffer Overflow Walk-Through
Computer Science 210 Computer Organization
Chapter 12 Variables and Operators
We’re moving on to more recap from other programming languages
Pointers The C programming language gives us the ability to directly manipulate the contents of memory addresses via pointers. Unfortunately, this power.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
Presentation transcript:

EC312 Review

Rules of Engagement Teams selected by instructor Host will read the entire questions. Only after, a team may “buzz” by raise of hand A team must answer the question within 5 seconds after buzzing in (must have answer at hand) If the answer is incorrect, the team will lose its turn and another team may buzz in. No score will be deducted. No negative scores. Maximum score is 100. Once reached, that team will stand down for others to participate. Teams will earn all points scored at the end of game. When selecting a question, Teams must only select questions of different value, unless there are no others, but may be from different categories. All team members will participate and will answer questions Only one round - No Daily Doubles, Double Jeopardy or Final Jeopardy … and no partial credits!

Jeopardy! Numbers / C Transistors / Logic Pointers, Arrays & Strings Assembly and Memory Functions and Stack / Heap Buffer Overflow / Privileges 10 pts 20 pts 40 pts 60 pts

How many total bytes would be needed to store the following variables? int time_1, time_2, time_3; float PRT = 9.5; char mid_1, mid_2, mid_3; int score; Numbers / C 10 pts integers: 4 x 4 = 16 floats: 1 x 4 = 4 characters: 3 x 1 = 3 TOTAL = 23 bytes

In which direction does the arrow point on an NPN transistor? Transistors/Logic 10 pts Arrow points outward at the EMITTER (Not Pointing iN)

What is the address operator used to access the address of a variable? Pointers, Arrays & Strings 10 pts &

How many bits are represented in an address? Assembly and Memory 10 pts 4 bits per number, 8 numbers per address = 32 bits

True or False: The Heap grows from the top (smaller memory address) down (to larger memory addresses) making it grow towards the stack. In fact the stack and the heap compete for memory space and it is the programmer who must take care of the heap. Functions and Stack / Heap 10 pts True

What does the Linux command sudo do? Buffer Overflow / Privileges 10 pts Executes a single command as the root user!

Express the binary number as a decimal number? Numbers / C 20 pts Ans= = 90 10

Properly bias the transistor below: Transistors/Logic 20 pts Properly biased NPN

What would be the output of the code below? #include int main() { char phrase[] = “Military Academy”; strcpy (phrase, “Naval Academy”); printf(“%s\n”, phrase); } Pointers, Arrays & Strings 20 pts Naval Academy

Name the processor registers and their purpose: Assembly and Memory 20 pts eip (instruction pointer) – it holds the address of the next instruction the CPU intends to execute esp (stack pointer) – it holds the address of the top of the stack ebp (base pointer) – points to the first address right below the stack

What elements and in what order they appear on the stack during a function call from main? Functions and Stack / Heap 20 pts Function’s Variables Saved value of prior ebp Return Address Function’s Arguments Main’s Variables

Buffer Overflow / Privileges 20 pts What does setting the setuid permission on an executable program do? Whenever the program is executed it will behave as though it were being executed by the owner!

Numbers / C 40 pts Consider the code below. What is the exact output if the user enters 4 when prompted? Is 4 your favorite number? Navy

To what logic gate does the following Truth table correspond? Transistors/Logic 40 pts NOR Gate

What is the output of the program below? #include int main() { int salary[4] = {1000, 1500, 2000}; int j; for(j = 0 ; j <= 3; j = j + 1) { printf(“Salary %d is %d \n”, j+1, salary[j]); } Pointers, Arrays & Strings 40 pts Salary 1 is 1000 Salary 2 is 1500 Salary 3 is 2000 Salary 4 is 0

Consider the memory stack allocation below. What would be displayed by the command x/s 0x ? Assembly and Memory 40 pts USNA AddressDataASCII x55U x53S x4eN x41A x00null

Functions and Stack / Heap 40 pts Consider the code below where a break has been set at line 10. Fill the missing items in the stack? 1 void test_function( int a, int b, int c, int d, int e) 2 { 3 int flag; 4 char buffer[10]; 5 6 flag = 1000; 7 buffer[0] = ‘U’; 8 buffer[1] = ‘S’; 9 buffer[2] = ‘A’; 10 } 11 int main () 12 { 13 test_function(5,6,7,8,9); 14 } 0x550x530x410x00Name? 0xe80x030x00 Name? 0x180xf80xff0xbfWhat is this? 0x050x00 } what are these? 0x060x00 0x070x00 0x080x00 0x090x00 bfff818ebp_main 0x550x530x410x00buffer 0xe80x030x00 flag 0x180xf80xff0xbfprevious ebp 0x050x00 } function arguments 0x060x00 0x070x00 0x080x00 0x090x00 bfff818ebp_main

Buffer Overflow / Privileges 40 pts Consider the code below. What is the minimum amount of characters needed in the string alpha_code to change the value of a in the stack? float happy_times(int x, float y) { char alpha_code[7]; float sum; sum = x + y; Return sum; } int main() { int a = 77; float b = ; a = happy_times(a,b) + 1; exit(1); } alpha_code = 7 saved ebp = 4 Ret Add = 4 copy of x = 4 copy of y = 4 b = 4 “change value of a” = change 1 byte …so TOTAL = = 27

Complete the code below to return the factorial of a number (hint: use for loop) #include int main ( ) { int number, counter; printf(“Enter a number and I will return its factorial:”); scanf( “%d”, &number ); //enter 2 lines //of code here printf(“The factorial is: %d \n”, number ); } Numbers / C 60 pts for (counter = number; counter > 1; counter = counter-1) number = number * (counter-1);

Transistors/Logic 60 pts For the logic circuit below, complete the corresponding truth table and determine the Boolean expression for the output X. ABCANDNORX ABCANDNORX

Consider the code and the stack below. What would be the output of the program? #include int main() { int a = 11; int *a_ptr; a_ptr = &a; printf(“\nThe value of a is %d and the address is %x \n”, a, &a); printf(“\nThe value of a_ptr is %x and the address is %x \n\n”, a_ptr, &a_ptr); } Pointers, Arrays & Strings 60 pts The value of a is 11 and the address is bffff850 The value of a_ptr is bffff850 and the address if bffff84c esp0x50 0xf8 0xff 0xbf 0x0b 0x00 ebp

Consider the memory stack allocation below. What would be displayed by the command x/xw 0x ? Assembly and Memory 60 pts 0x414e5355 AddressDataASCII x55U x53S x4eN x41A x00null

Functions and Stack / Heap 60 pts Consider the code below. Give the different variable values at specific break points. 1 #include 2 int AbsVal( int number) 3 { 4 int AV; 5 if(number >=0) 6 { 7 AV = number; 8 } 9 else 10 { 11 AV = -1*number; 12 } 13 return AV; 14 } 15 int main() 16 { 17 int x, y; 18 x = -1; 19 y = AbsVal(x); 20 printf("The absolute value of the integer is %d\n", y); 21 } BreakpointxynumberAV Line 18?? Line 19?? Line 5?? Line 13? Line 20??? BreakpointxynumberAV Line 18garbage Line 19garbage Line 5garbage Line 131 Line 2011

Consider the code below. A break was set at line 15, at which time the command i r ebp returned the value 0xbffff800. The code was allowed to continue until it prompted its message. Would a segmentation fault occur if the user inadvertently enters 14 characters? Explain. 1 #include 2 void echo_string() 3 { 4 int count; 5 char entered_string[10]; 6 printf(“Enter a string: “); 7 scanf(“%s”, entered_string); 8 for(count=0; count < 10; count=count+1) 9 { 10 printf(“%s\n”,entered_string); 11 } 12 } 13 int main() 14 { 15 echo_string(); 16 } Buffer Overflow / Privileges 60 pts No. Although 14 characters would cause a byte to overwrite saved_ebp, the null would only replace 0x00, so the value does not change and therefore there is no access to memory outside that that was allotted and thus no SegFault.

Score Card TeamTallyScore