Prof. David Bernstein
James Madison University
Getting Started
Vulnerabilities when Using Arrays - Length Faults
Vulnerabilities when Using Arrays - Length Faults (cont.)
void operation(int array[]) < int length = sizeof(array) / sizeof(array[0]); for (int i=0; i>
Vulnerabilities when Using Arrays - Sentinel Faults
Vulnerabilities when Using Strings
Vulnerabilities when Using Strings - gets()
char line[81]; gets(line);
Vulnerabilities when Using Strings - strcpy()
Vulnerabilities when Using Strings - strcat()
Vulnerabilities when Using Strings - sprintf()
char line[81]; sprintf(line, "%2d: %s\n", i, user_input);
Vulnerabilities when Using Strings - Null Termination
Vulnerabilities when Using Strings - Null Termination (cont.)
char a[10], b[10]; strncpy(a, "0123456789", 10); // a will not be null-terminated strcpy(b, a); // b will probably overflow
Threats - Memory Corruption
Threats - Arbitrary Memory Writes
. char buffer[BUFFER_SIZE]; long value = . ; long* p = . ; strncpy(buffer, argv[1], length); // Potential overflow into p *p = value; // Assign value to the address pointed to by p .
Threats - Corrupted Function Pointers
. static int value = . ; static char buffer[BUFFER_SIZE]; static void (*f)(int i); f = &some_function; strncpy(buffer, argv[1], length); // Potential overflow into f (void)(*f)(value); // Execute the code pointed to by f .
Threats - Stack Smashing
Attacks - Data Integrity
cexamples/bufferoverflow/windows/string_overflow_data.c
#include #include char eid[9]; // 8 characters plus '\0' int grade; int main(int argc, char* argv[]) < // Initialize strcpy(eid, "bernstdh"); grade = 100; printf("EID: %8s Grade: %d\n", eid, grade); // Copy user input into the eid strcpy(eid, "bernstdh \x08\x08"); // 0x08 is ASCII backspace printf("EID: %8s Grade: %d\n", eid, grade); >
Attacks - Data Integrity (cont.)