我正在尝试运行此代码来获取 shell,但即使禁用了 ASLR,我也会遇到分段错误。我在装有 Ubuntu 20.04 64 位版本的 AMD Ryzen 3 计算机上运行此代码。
我正在使用以下命令进行编译:
$ gcc -O0 -fno-stack-protector -z execstack getshell.c -o getshell
Run Code Online (Sandbox Code Playgroud)
文件getshell.c如下:
#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();
}
Run Code Online (Sandbox Code Playgroud)
编辑:我在这里找到了这段代码
unsigned char __attribute__((section(".text#"))) shellcode[]
为我工作(注意#)
#是一个技巧 - 它注释了 gcc 发出的汇编代码的一部分。