Now that I’ve got that netcat tip out of the way, I want to share a quick example of how gcc deals with buffer overflows.
The problem is that gcc does some stack smashing detection to detect when a buffer overflow is trying to be exploited. This makes learning about buffer overflows and related exploits more difficult. To turn this off, use the fno-stack-protector switch as follows:
<pre>
$ gccfno-stack-protector -o overflow overflow.c
#include
#include
main() {
char str1[10];
strcpy(str1, ""AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"");
printf(""hello\n"");
}