【问题标题】:printf and gets not showing in assembler codeprintf 并没有在汇编代码中显示
【发布时间】:2017-01-17 21:16:57
【问题描述】:

我刚开始处理缓冲区溢出,当我寻找教程时,每个人的汇编代码中都有 printf@plt 和 gets@plt,但我没有看到它们。我是不是做错了什么?

源代码:

#include <stdio.h>
#include <string.h>

int main()
{
char password[16];
int passcheck = 0;
void secret();

printf("\nWhat's the password?\n");
gets(password);

if (strcmp(password, "password1"))
{
    printf("\nYou fail/n");
}
else
{
    printf("\nCorrect password\n");
    passcheck = 1;
}

if(passcheck)
{
    secret();
}
return 0;
}

void secret()
{
printf("\nYou got it!!!\n");
}

汇编代码:

0x00001e50 <+0>:    push   %ebp
0x00001e51 <+1>:    mov    %esp,%ebp
0x00001e53 <+3>:    push   %edi
0x00001e54 <+4>:    push   %esi
0x00001e55 <+5>:    sub    $0x40,%esp
0x00001e58 <+8>:    call   0x1e5d <main+13>
0x00001e5d <+13>:   pop    %eax
0x00001e5e <+14>:   lea    0x101(%eax),%ecx
0x00001e64 <+20>:   movl   $0x0,-0xc(%ebp)
0x00001e6b <+27>:   movl   $0x0,-0x20(%ebp)
0x00001e72 <+34>:   mov    %ecx,(%esp)
0x00001e75 <+37>:   mov    %eax,-0x24(%ebp)
0x00001e78 <+40>:   call   0x1f28
0x00001e7d <+45>:   lea    -0x1c(%ebp),%ecx
0x00001e80 <+48>:   mov    %ecx,(%esp)
0x00001e83 <+51>:   mov    %eax,-0x28(%ebp)
0x00001e86 <+54>:   call   0x1f22
0x00001e8b <+59>:   lea    -0x1c(%ebp),%ecx
0x00001e8e <+62>:   mov    -0x24(%ebp),%edx
0x00001e91 <+65>:   lea    0x118(%edx),%esi
0x00001e97 <+71>:   mov    %esp,%edi
0x00001e99 <+73>:   mov    %esi,0x4(%edi)
0x00001e9c <+76>:   mov    %ecx,(%edi)
0x00001e9e <+78>:   mov    %eax,-0x2c(%ebp)
0x00001ea1 <+81>:   call   0x1f2e
0x00001ea6 <+86>:   cmp    $0x0,%eax
0x00001ea9 <+89>:   je     0x1ec8 <main+120>
0x00001eaf <+95>:   mov    -0x24(%ebp),%eax
0x00001eb2 <+98>:   lea    0x122(%eax),%ecx
0x00001eb8 <+104>:  mov    %ecx,(%esp)
0x00001ebb <+107>:  call   0x1f28
0x00001ec0 <+112>:  mov    %eax,-0x30(%ebp)
0x00001ec3 <+115>:  jmp    0x1ee3 <main+147>
0x00001ec8 <+120>:  mov    -0x24(%ebp),%eax
0x00001ecb <+123>:  lea    0x12e(%eax),%ecx
0x00001ed1 <+129>:  mov    %ecx,(%esp)
0x00001ed4 <+132>:  call   0x1f28
0x00001ed9 <+137>:  movl   $0x1,-0x20(%ebp)
0x00001ee0 <+144>:  mov    %eax,-0x34(%ebp)
0x00001ee3 <+147>:  cmpl   $0x0,-0x20(%ebp)
0x00001ee7 <+151>:  je     0x1ef2 <main+162>
0x00001eed <+157>:  call   0x1f00 <secret>
0x00001ef2 <+162>:  xor    %eax,%eax
0x00001ef4 <+164>:  add    $0x40,%esp
0x00001ef7 <+167>:  pop    %esi
0x00001ef8 <+168>:  pop    %edi
0x00001ef9 <+169>:  pop    %ebp
0x00001efa <+170>:  ret    
0x00001efb <+171>:  nopl   0x0(%eax,%eax,1)

【问题讨论】:

标签: c assembly gdb buffer exploit


【解决方案1】:

通过为您的C 编译器编译您的C 程序并为您的C 编译器添加调试符号。例如,如果您使用gcc,请使用-g 开关,如here: 所述。之后,在 gdb 下执行二进制文件时,您将能够看到原始的 C 符号名称

关于您的评论 - 也许您的目标文件没有从头开始重新编译。如果您使用 makefile 或仅删除所有对象 (.o) 文件,请尝试 make clean,然后使用 -ggdb 开关重新编译您的程序(它与 -g 开关相同,但专门为 gdb 生成调试信息)。重新编译后在二进制文件中查找调试信息 - 几个字符串,如“printf@plt”和“gets@plt”。

【讨论】:

  • 它仍然没有显示它们。我这样做了: gcc -g -fno-stack-protector -m32 -D_FORTIFY_SOURCE=0 -o a /Users/Tridie2000/Documents/Programmeer-projecten/CotEditor/simple.c 然后是 gdb a 和 disas main
  • 也许您的目标文件没有从头开始重新编译。如果您使用 makefile 或仅删除所有对象 (.o) 文件,请尝试make clean,然后使用-ggdb 开关重新编译您的程序(它与-g 开关相同,但专门为gdb 生成调试信息)
  • 顺便说一句:一些 printf-s 确实会被 puts 替换,即使优化关闭。
猜你喜欢
  • 2012-01-20
  • 2020-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
相关资源
最近更新 更多