Docsity

Applied Security Lab: Buffer Overflow Vulnerabilities and Exploits, Assignments of Computer Science

Toggle sidebar
bg1
APPLIED SECURITY—SPRING 2007
BRENO DE MEDEIROS, INSTRUCTOR.
4th Programming Assignment. DUE on 04/20
Points: 100
These questions were adapted from a buffer overflow lab experiment originally developed by W. Byrd,
at the University of Maryland, Baltimore County [1]. He has generously allowed us to use it in our
courses.
Buffer Overflow Lab
Part I: All Your Stack Are Belong to Us
You have received word that Dr. Evil has hatched another dastardly plan to take over the
campus (as a springboard for taking over the World!). Dr. Evil is planning to break into a new
computer-controlled safe. Once he steals the campus funds, terrible things will follow. Most
ominously, parking rates will skyrocket. Fearing a faculty revolt, the chief of security has asked you to
examine the C program that controls the safe.
Learning Objectives
Analyze source code to identify a possible buffer overflow.
Analyze and explain how stack smashing exploit code works.
Describe how a stack smashing buffer overflow attack works.
Examine the stack and describe how stack smashing changes the stack.
Directions
1. Examine the source code file withdraw.c.
a) Describe the withdraw program. What exactly does the program do?
2. Compile the withdraw program:
gcc -o withdraw withdraw.c
3. Examine the source code file open .c .
a) Describe the open program. What exactly does the program do?
4. Compile the open program:
gcc -o open open.c
5. Run the open command and send the output to the withdraw program:
./open | ./withdraw
a) What Happened? How did open safe wind up being called?
6. Recompile withdraw.c, uncomment the #define DEBUG line and run the program again with
pf3

Partial preview of the text

Download Applied Security Lab: Buffer Overflow Vulnerabilities and Exploits and more Assignments Computer Science in PDF only on Docsity!

APPLIED SECURITY—SPRING 2007

BRENO DE MEDEIROS, INSTRUCTOR.

4 th^ Programming Assignment. DUE on 04/ Points: 100 These questions were adapted from a buffer overflow lab experiment originally developed by W. Byrd, at the University of Maryland, Baltimore County [1]. He has generously allowed us to use it in our courses.

Buffer Overflow Lab

Part I: All Your Stack Are Belong to Us

You have received word that Dr. Evil has hatched another dastardly plan to take over the campus (as a springboard for taking over the World!). Dr. Evil is planning to break into a new computer-controlled safe. Once he steals the campus funds, terrible things will follow. Most ominously, parking rates will skyrocket. Fearing a faculty revolt, the chief of security has asked you to examine the C program that controls the safe. Learning Objectives  Analyze source code to identify a possible buffer overflow.  Analyze and explain how stack smashing exploit code works.  Describe how a stack smashing buffer overflow attack works.  Examine the stack and describe how stack smashing changes the stack. Directions

  1. Examine the source code file withdraw.c. a) Describe the withdraw program. What exactly does the program do?
  2. Compile the withdraw program: gcc -o withdraw withdraw.c
  3. Examine the source code file open.c. a) Describe the open program. What exactly does the program do?
  4. Compile the open program: gcc -o open open.c
  5. Run the open command and send the output to the withdraw program: ./open | ./withdraw a) What Happened? How did open safe wind up being called?
  6. Recompile withdraw.c , uncomment the #define DEBUG line and run the program again with

and without sending the output of open to the program. a) Examine the stack, how does it change when the output of open is sent to it?

Part II: An Easy ‘A

Dr. Evil failed all of his exams in his algorithms class, yet still managed to earn an ‘A’ for the course. The chief security officer suspects that Dr. Evil cheated by exploiting an unknown vulnerability in the instructor's “Easy Grader” grading program, but the instructor thinks that something else might be the problem. Given your success with the computer controlled safe software, the chief security officer has asked you to examine the Easy Grader program, look for vulnerabilities, and decide if Dr. Evil could have changed his course grade for algorithms. Learning Objectives  Understand other categories of buffer overflow attacks.  Analyze the effects compiler options can have on protection mechanisms. Directions

  1. Examine the file easy_grader.c. a) Describe the easy_grader program. What exactly does the program do
  2. In a minute you are going to run the grader program, using a long string composed entirely of the character ‘A’ as the program’s input (i.e., ‘AAAAAAAAA...AAAAAA’). a) What will be the behavior of the easy_grader program with this input string? Justify your answer.
  3. Compile the grader program: gcc -o easy_grader easy_grader.c
  4. Run the grader program from the terminal: ./easy_grader
  5. The program easy_grader outputs some text and then waits for your input. Type a long string of uppercase ‘A’s (at least 90 characters), then press the key. a) How did the easy_grader program behave with this input string? Did the program’s behavior match your predictions in the previous question? If not, explain the discrepancy.
  6. Recompile the grader program, this time with code optimizations turned on: gcc -O2 -o easy_grader easy_grader.c a) How will the code optimizations affect the behavior of the easy_grader program when passed a long string of ‘A’s as input? Hint: The optimized code saves pointers passed as function arguments in CPU registers instead of on the stack.
  7. Run the easy_grader program once again, using a long string of ‘A’s as input a) How did the optimized version of the easy grader program behave? Were you able to successfully predict this behavior in the previous question? If not, explain the discrepancy. Lab Report  Answer the questions presented in the lab.