The program asks you your name, and prints out something like this (where the user input and program output are indicated by fonts style):
% hello
What is your name?
Bob
Thank you, Bob.
I recommend that you get a grade of D on this assignment.
However, the author of the program has inexplicably forgotten to do bounds-checking on the array into which it reads the input, and therefore it is vulnerable to attack.
% hello < data
What is your name?
Thank you, Bob.
I recommend that you get a grade of A on this assignment.
As you can see from reading the program, it is not designed to give anyone an A under any circumstances. However, it is programmed sloppily: it reads the input into a buffer, but forgets to check whether the input fits. This means that a too-long input can overwrite other important memory, and you can trick the program into giving you an A.
This assignment has several parts.
"If you were to use a buffer overrun attack to knowingly gain unauthorized access or to cause damage to other people's computers, the Computer Fraud and Abuse Act provides a maximum penalty of _______ years in prison for a first offense. However, the creator of the Melissa virus plea-bargained down to ______ months in prison."
% gdb hello (gdb) x/68i readStringCopy the resulting 68 lines of text into a text file named traces, and then annotate the code to explain what's going on. You should use the source code in hello.c as a reference, and indeed your annotation should just consist of showing how the machine code corresponds to the C code. You don't need an annotation for every line of machine code.
% gdb hello (gdb) print &grade (gdb) print gradePlace a diagram in your traces file showing the layout of the data section.
% gdb hello (gdb) print &NamePlace a diagram in your traces file showing the layout of the bss section.
% gdb hello (gdb) break *readString+73 (gdb) run Type a name (gdb) print $esp (gdb) print $ebp (gdb) x/??b $esp (where ?? is the appropriate number of bytes)Place a diagram of the stack frame layout, indicating addresses relative to the stack pointer in your traces file.
You may create your traces file jointly with one other student; if you do so, tell us who you worked with. You should do the rest of the assignment on your own (though, as usual, you may discuss problems and approaches with other students as long as you don't copy each others' programs).
Recommended method: overrun the buffer with a return address that jumps to a place inside of the main function.
Recommended method: overrun the buffer with a three-part byte-sequence: (1) your name, (2) a return address that points into the buffer, and (3) a short machine-language program that stores an 'A' into the right place and then jumps somewhere useful.
For parts B and A, if your name is very long, you may use just the first 15 characters of your name for the purposes of this assignment.
Create your programs on hats using the bash shell, xemacs, gcc, and gdb.
The directory /u/cos217/Assignment6 contains the hello.c and hello files. It also contains a makefile that you might find helpful during development.
Create a readme text file that contains:
Submit your work electronically on hats via the command:
/u/cos217/bin/i686/submit 6 traces createdataC.c createdataB.c createdataA.c readme
We will grade your work on correctness and design. We will consider understandability to be an important aspect of good design. To encourage good coding practices, we will compile using "gcc -Wall -ansi -pedantic" and take off points based on warning messages during compilation.
#include <stdio.h> #include <sys/mman.h> #include <string.h> #include <stdlib.h> #define BUFSIZE 30 char grade = 'D'; char Name[BUFSIZE]; void readString(char *s) { char buf[BUFSIZE]; int i = 0; int c; for (;;) { c = fgetc(stdin); if ((c == EOF) || (c == '\n')) break; buf[i++] = c; } buf[i] = 0; for (i = 0; i < BUFSIZE; i++) s[i] = buf[i]; } int main(void) { mprotect((void*)((unsigned int)Name & 0xfffff000), 1, PROT_READ | PROT_WRITE | PROT_EXEC); printf("What is your name?\n"); readString(Name); if (strcmp(Name, "Andrew Appel") == 0) grade = 'B'; printf("Thank you, %s.\n", Name); printf("I recommend that you get a grade of %c on this assignment.\n", grade); exit(0); }