gpt4 book ai didi

c - 运行 shellcode 时出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:46:34 26 4
gpt4 key购买 nike

在深入研究 shellcode 之前,我正在试验它,所以我从 shellcoders 手册中看到了一个例子。示例如下:

char shellcode[] = "\xeb\x1a\x5e\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x89\x4
\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xe1\xff\xff\xff\x2f\x62\x69
\x6e\x2f\x73\x68";

int main() {

int *ret;
ret = (int *)&ret + 2;
(*ret) = (int)shellcode;
}

shellcode 应该生成一个 shell。但是我收到段错误。我使用带有 -fno-stack-protector-z execstack 选项的 gcc 编译器编译程序。我快速查看了 readelf 命令,很明显堆栈是可执行的

 GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4

最佳答案

ret 是一个指针,当您声明它时它不指向任何内存位置。稍后您尝试通过向指针指向的位置添加 2 来为其分配一些值。(这是矛盾的说法)

ret = (int *)&ret + 2;/* Which is wrong */

关于c - 运行 shellcode 时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26671104/

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