使用 gdb 来利用缓冲区溢出
using gdb to exploit buffer-overflow
我正在做一项作业,我 运行 遇到了一些问题。我对编程的整个安全领域还很陌生,所以我可能只是遗漏了一些简单的东西,但如果你们能提供任何帮助,我将不胜感激。
在此作业中(旧作业,不适用于我的 class 的这个术语),我们旨在让程序调用与它要调用的函数不同的函数。代码贴在下面:
#include <stdio.h>
#include <stdlib.h>
int oopsIGotToTheBadFunction(void)
{
printf("Gotcha!\n");
exit(0);
}
int goodFunctionUserInput(void)
{
char buf[12];
gets(buf);
return(1);
}
int main(void)
{
goodFunctionUserInput();
printf("Overflow failed\n");
return(1);
}
我们的目的是让 oopsIGotToTheBadFunction
在另一个函数被调用时执行。到目前为止,我在终端或 PuTTy 中加载程序,然后执行 disas
命令,但结果信息不是我所期望的。我期待信息是这样读的
Dump of assembler code for function bar:
0x000000000040068e <+0>: push %rbp
0x000000000040068f <+1>: mov %rsp,%rbp
0x0000000000400692 <+4>: mov [=11=]x400800,%edi
0x0000000000400697 <+9>: callq 0x400528 <puts@plt>
0x000000000040069c <+14>: mov 0x20099d(%rip),%rax # 0x601040 ...
0x00000000004006a3 <+21>: mov %rax,%rdi
0x00000000004006a6 <+24>: callq 0x400558 <fflush@plt>
0x00000000004006ab <+29>: leaveq
0x00000000004006ac <+30>: retq
End of assembler dump.
但我得到的是:
enter(gdb) disas oopsIGotToTheBadFunction
Dump of assembler code for function oopsIGotToTheBadFunction:
0x00000001000008fc <oopsIGotToTheBadFunction+0>: save %sp, -192, %sp
0x0000000100000900 <oopsIGotToTheBadFunction+4>: sethi %hi(0x100000), %g 1
0x0000000100000904 <oopsIGotToTheBadFunction+8>: mov %g1, %g1 ! 0x1000 00
0x0000000100000908 <oopsIGotToTheBadFunction+12>: sllx %g1, 0xc, %g1
0x000000010000090c <oopsIGotToTheBadFunction+16>: or %g1, 0xa20, %o0
0x0000000100000910 <oopsIGotToTheBadFunction+20>: call 0x100100c20 <puts@ plt>
0x0000000100000914 <oopsIGotToTheBadFunction+24>: nop
0x0000000100000918 <oopsIGotToTheBadFunction+28>: clr %o0 ! 0x0
0x000000010000091c <oopsIGotToTheBadFunction+32>: call 0x100100ba0 <exit@ plt>
0x0000000100000920 <oopsIGotToTheBadFunction+36>: nop
0x0000000100000924 <oopsIGotToTheBadFunction+40>: nop
End of assembler dump.
我正在使用的演练要求我操作 rbp 和 leaveq 点中的信息,但我不确定使用什么代替那些,因为当我 运行 disas 命令时它们不存在.
谢谢大家的帮助!
I was expecting the information to read like this
您希望找到 Intel x86_64 说明...
But instead I get this:
您正在查找 Sun SPARC 说明。您知道存在 Intel x86 以外的处理器,对吗?
如果您想 debug/manipulate Intel 组装,您必须在装有 Intel CPU 的机器上进行。
我正在做一项作业,我 运行 遇到了一些问题。我对编程的整个安全领域还很陌生,所以我可能只是遗漏了一些简单的东西,但如果你们能提供任何帮助,我将不胜感激。
在此作业中(旧作业,不适用于我的 class 的这个术语),我们旨在让程序调用与它要调用的函数不同的函数。代码贴在下面:
#include <stdio.h>
#include <stdlib.h>
int oopsIGotToTheBadFunction(void)
{
printf("Gotcha!\n");
exit(0);
}
int goodFunctionUserInput(void)
{
char buf[12];
gets(buf);
return(1);
}
int main(void)
{
goodFunctionUserInput();
printf("Overflow failed\n");
return(1);
}
我们的目的是让 oopsIGotToTheBadFunction
在另一个函数被调用时执行。到目前为止,我在终端或 PuTTy 中加载程序,然后执行 disas
命令,但结果信息不是我所期望的。我期待信息是这样读的
Dump of assembler code for function bar:
0x000000000040068e <+0>: push %rbp
0x000000000040068f <+1>: mov %rsp,%rbp
0x0000000000400692 <+4>: mov [=11=]x400800,%edi
0x0000000000400697 <+9>: callq 0x400528 <puts@plt>
0x000000000040069c <+14>: mov 0x20099d(%rip),%rax # 0x601040 ...
0x00000000004006a3 <+21>: mov %rax,%rdi
0x00000000004006a6 <+24>: callq 0x400558 <fflush@plt>
0x00000000004006ab <+29>: leaveq
0x00000000004006ac <+30>: retq
End of assembler dump.
但我得到的是:
enter(gdb) disas oopsIGotToTheBadFunction
Dump of assembler code for function oopsIGotToTheBadFunction:
0x00000001000008fc <oopsIGotToTheBadFunction+0>: save %sp, -192, %sp
0x0000000100000900 <oopsIGotToTheBadFunction+4>: sethi %hi(0x100000), %g 1
0x0000000100000904 <oopsIGotToTheBadFunction+8>: mov %g1, %g1 ! 0x1000 00
0x0000000100000908 <oopsIGotToTheBadFunction+12>: sllx %g1, 0xc, %g1
0x000000010000090c <oopsIGotToTheBadFunction+16>: or %g1, 0xa20, %o0
0x0000000100000910 <oopsIGotToTheBadFunction+20>: call 0x100100c20 <puts@ plt>
0x0000000100000914 <oopsIGotToTheBadFunction+24>: nop
0x0000000100000918 <oopsIGotToTheBadFunction+28>: clr %o0 ! 0x0
0x000000010000091c <oopsIGotToTheBadFunction+32>: call 0x100100ba0 <exit@ plt>
0x0000000100000920 <oopsIGotToTheBadFunction+36>: nop
0x0000000100000924 <oopsIGotToTheBadFunction+40>: nop
End of assembler dump.
我正在使用的演练要求我操作 rbp 和 leaveq 点中的信息,但我不确定使用什么代替那些,因为当我 运行 disas 命令时它们不存在.
谢谢大家的帮助!
I was expecting the information to read like this
您希望找到 Intel x86_64 说明...
But instead I get this:
您正在查找 Sun SPARC 说明。您知道存在 Intel x86 以外的处理器,对吗?
如果您想 debug/manipulate Intel 组装,您必须在装有 Intel CPU 的机器上进行。