Fall 2000 |
Lab 12: Hackers R Us |
CS61C |
Purpose:
Overview:
Prelab:
Read
Smashing The Stack For Fun And Profit
and
Stackguard: Automatic Adaptive Detection and Prevention of Buffer-Overflow Attacks (pdf)
Smashing The Stack For Fun and Profit is arguably the definitive how-to on
writing buffer overflow attacks. Stackguard presents a novel method for
preventing them. Pay particular attention to section 2 of Stackguard as it
provides a concise description of buffer overflow attacks in general. The two
documents are quite lengthy and Smashing The Stack uses significant amounts of
X86 assembly, so, once you've got the basic idea down, you may stop reading if
you get bored or lost.
Have a working copy of the disassembler project ready to run when you come
into lab. You may use your own disassembler, or, if necessary, you can grab
the dissassembler solution at: ~cs61c/solutions/proj/dis-sol.c.
Answer the following question:
Assignment:
Task 1:
Task 2:
Task 3:
Just in case you don't believe us, try typing a lengthy line of text, and watch the code crash and burn.
You are to create an input file called "overflow" such that if you do "cat overflow | spim -file lab12.s", the file will cause a buffer overflow which will cause the program to print out "Hot Dog, we have a weiner!" and exit. Read on to find out how to go about doing this.
We all know by now that the ascii value of a number and the 2's complement value of the same number are two different animals. Your job is to write a C program that will print to a file the ascii character of the corresponding 2's complement value. This 2's complement value will correspond to the address where you would like the function "test" in lab12.s to return to. You should make an array of four characters and populate it with the integer value of the address in memory. For example if we wanted to see the corresponding ascii representation of address 0x00400000 the following would work:
char addr[4]; addr[0] = 0; addr[1] = 0x40; addr[2] = 0; addr[3] = 0; . . .
And this would print to the file: ^@@^@^@ ( n times )
^@ = 0
@ = 0x40
To sum it up, the goal of this exercise is to locate the appropriate address to put into the array of characters defined in your lab12.c file. (Hint 1: think disassembler - and don't forget, you'll have to use spim to create a dump file from the given .s file.) (Hint 2:Pay attention to endianness) You will also need to figure out the number times you need to print this address to the file. For example a "for" loop should execute enough times to generate enough characters to write over the return address located on the stack. You should write the address to the file just enough times to write over the return address, no more and no less (i.e. do not write the address a million times and call it a day!).
Task 4:
Task 5:
Final Remarks:
Feedback:
Last updated: 11/8