【问题标题】:segmentation fault while running shellcode运行 shellcode 时出现分段错误
【发布时间】:2014-10-31 09:17:41
【问题描述】:

在深入研究之前我正在尝试使用 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

【问题讨论】:

  • 反引号用于引用代码,而不是强调。

标签: c gcc buffer-overflow shellcode


【解决方案1】:

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

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

【讨论】:

  • 是的。现在清楚了。这就是为什么你总是需要别人来阅读你写的东西,因为他只会看到你每次重新阅读代码时忽略的错误。
  • 我否决了这个答案。该问题的代码旨在用shellcode的地址覆盖返回地址;这不是偶然的未定义行为。 (显然它不应该是可移植的或符合标准的 C)
  • @immibis 你愿意回答这个问题吗?
  • @T-D 我们无法说服所有人我希望我回答了你的问题 :)
【解决方案2】:

我使用“gcc filename.cpp”命令编译以下代码。 Ti的编译没有错误。我希望这能帮助你解决你的疑问。

#include<stdio.h>

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; //I don't know why you had written this
ret = (int *)shellcode;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    相关资源
    最近更新 更多