I was just starting to learn how buffer overflows work, and I tried to simulate an attack on Windows 7 using Visual C 2010. The buffer overflow attack is very far-fetched, it just overwrites the return address with the address of the local variable "buffer". The buffer contains a shellcode string.
Whether I am running the program in Visual Studio 2010 Debug or not, the program will go to the shell code and almost begin to execute it, but I get an access violation error and the program will not continue to execute the shell code.
Why am I getting this error? Is this some kind of buffer overflow protection in Windows?
How can you make a program execute shellcode in a buffer?
edit:
Hans (answer) is correct. This is discussed in the Security chapter of Windows Internals 5th, and the cause of the error is Microsoft's implementation of Executable Space Protection .
If this question helped anyone, any ratings would be appreciated.
void execute_my_shellcode() { char buffer[24]; memcpy(buffer, "\x6A\x21\xFF\x15\x40\x62\x40\x00\x83\xC4\x04\x6A\x0A\xFF\x15\x40\x62\x40\x00\x83\xC4\x04\xC3", 24); printf("current return address: %p\n", *(int*)((char*)&buffer + 24 + 4)); *(int*)((char*)&buffer + 24 + 4) = (int)&buffer; printf("return address is now : %p\n\n", (int*)*(int*)((char*)&buffer + 24 + 4) ); }
source share