I am trying to run this code to get a shell but I am getting a segmentation fault even with ASLR disabled. I am running this code on my AMD Ryzen 3 computer with Ubuntu 20.04 64bit version.
I am compiling with the following command:
gcc -O0 -fno-stack-protector -z execstack getshell.c -o getshell
File getshell.c is as following:
#include <stdio.h>
unsigned char shellcode[] = \
"\x48\x31\xf6\x56\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5f\x6a\x3b\x58\x99\x0f\x05";
int main()
{
int (*ret)() = (int(*)())shellcode;
ret();
}
CodePudding user response:
unsigned char __attribute__((section(".text#"))) shellcode[]
works for me (mind the #
)
#
is a trick - it comments part of the emitted assembly code by gcc.