无法设置断点

时间:2011-02-14 07:45:19

标签: gdb buffer-overflow disassembly

我试图获取buf的起始地址。所以我编译了以下程序并将其加载到gdb中。

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

int main(int argc, char **argv) {
    char buf[128];
    if(argc < 2) return 1;
    strcpy(buf, argv[1]);
    printf("%s\n", buf);    
    return 0;
}

在反汇编main时,我们得到: -

(gdb) disassemble main
Dump of assembler code for function main:
0x080483b4 <main+0>:    push   ebp
0x080483b5 <main+1>:    mov    ebp,esp
0x080483b7 <main+3>:    sub    esp,0xa8
0x080483bd <main+9>:    and    esp,0xfffffff0
0x080483c0 <main+12>:   mov    eax,0x0
0x080483c5 <main+17>:   sub    esp,eax
0x080483c7 <main+19>:   cmp    DWORD PTR [ebp+0x8],0x1
0x080483cb <main+23>:   jg     0x80483d9 <main+37>
0x080483cd <main+25>:   mov    DWORD PTR [ebp-0x8c],0x1
0x080483d7 <main+35>:   jmp    0x8048413 <main+95>
0x080483d9 <main+37>:   mov    eax,DWORD PTR [ebp+0xc]
0x080483dc <main+40>:   add    eax,0x4
0x080483df <main+43>:   mov    eax,DWORD PTR [eax]
0x080483e1 <main+45>:   mov    DWORD PTR [esp+0x4],eax
0x080483e5 <main+49>:   lea    eax,[ebp-0x88]
0x080483eb <main+55>:   mov    DWORD PTR [esp],eax
0x080483ee <main+58>:   call   0x80482d4 <strcpy@plt>
0x080483f3 <main+63>:   lea    eax,[ebp-0x88]
0x080483f9 <main+69>:   mov    DWORD PTR [esp+0x4],eax
0x080483fd <main+73>:   mov    DWORD PTR [esp],0x8048524
0x08048404 <main+80>:   call   0x80482b4 <printf@plt>
0x08048409 <main+85>:   mov    DWORD PTR [ebp-0x8c],0x0
0x08048413 <main+95>:   mov    eax,DWORD PTR [ebp-0x8c]
0x08048419 <main+101>:  leave  
0x0804841a <main+102>:  ret    
End of assembler dump.

为了找到buf的起始地址,我需要查看加载到eax的地址。当我在0x080483e50x080483ee设置断点时,我得到以下内容。

(gdb) b 0x080483eb
Function "0x080483eb" not defined.
Make breakpoint pending on future shared library load? (y or [n])     
(gdb) run test
Starting program: /levels/level05 test
test

Program exited normally.

我做错了什么?为什么程序执行不会在该地址暂停?

1 个答案:

答案 0 :(得分:1)

如果您想在地址设置断点,则必须说b *0x080483eb 有关详细信息,请参阅here

您还应该使用-g编译程序,而不进行优化。当你到达main时,你可以break main停下来,用n走几行,用buf打印p buf