2017-01-17 51 views
0

我刚刚开始使用缓冲区溢出显示,当我找教程每个人都有的printf @ PLT,并得到@在他们的汇编代码PLT,但我没有看到他们。难道我做错了什么?printf和没有得到汇编代码

的源代码:

#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) 
+2

参见:[为什么'得到()'太危险使用 - 永远!(http://stackoverflow.com/questions/1694036/why-is-the-gets-function-dangerous-why-should-它而不是待使用)。 –

+0

运行'strings -a binary',你很可能会看到这些函数的字符串。 –

+0

@Jonathan Leffler,就是这一点。 OP想要尝试溢出缓冲区。 – ikegami

回答

3

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

关于您的评论 - 也许您的目标文件不是从头开始重新编译的。如果使用makefile或者只是删除所有对象(.o)文件,然后使用-ggdb开关(与-g开关相同,但专门为gdb生成调试信息)重新编译程序,请尝试使用makefile进行清理。重新编译后,在你的二进制文件中查找调试信息 - 像'printf @ plt'和'gets @ plt'这样的字符串。

+0

它仍然不显示它们。我这样做:gcc的-g -fno-堆栈保护-m32 -D_FORTIFY_SOURCE = 0 -oa /Users/Tridie2000/Documents/Programmeer-projecten/CotEditor/simple.c其次是广发行和disas主 –

+1

也许你的目标文件间没有从头开始重新编译。如果你使用makefile或者只是删除所有的对象(.o)文件,然后用'-ggdb'开关重新编译你的程序(它和'-g'开关一样,但是专门为' gdb') – SergeyLebedev

+0

顺便说一句:有些printf-s会被put取代,即使关闭了优化。 – dbrank0