user11375131
user11375131

Reputation:

Why do i have this problem with breakpoints on GDB? GDB Stops

I tried to set a break-point on GDB when a function strcpy() is called, but GDB stops, and i don't know how to find the error, im new to GDB and i want to study binary exploitation, so the forum i'm reading does not explain nothing about this, here is the output;

(gdb) disassemble main
Dump of assembler code for function main:
   0x00000000000011c9 <+0>: endbr64 
   0x00000000000011cd <+4>: push   rbp
   0x00000000000011ce <+5>: mov    rbp,rsp
   0x00000000000011d1 <+8>: sub    rsp,0x50
   0x00000000000011d5 <+12>:    mov    DWORD PTR [rbp-0x44],edi
   0x00000000000011d8 <+15>:    mov    QWORD PTR [rbp-0x50],rsi
   0x00000000000011dc <+19>:    mov    rax,QWORD PTR fs:0x28
   0x00000000000011e5 <+28>:    mov    QWORD PTR [rbp-0x8],rax
   0x00000000000011e9 <+32>:    xor    eax,eax
   0x00000000000011eb <+34>:    cmp    DWORD PTR [rbp-0x44],0x1
   0x00000000000011ef <+38>:    jne    0x1207 <main+62>
   0x00000000000011f1 <+40>:    lea    rsi,[rip+0xe10]        # 0x2008
   0x00000000000011f8 <+47>:    mov    edi,0x1
   0x00000000000011fd <+52>:    mov    eax,0x0
   0x0000000000001202 <+57>:    call   0x10c0 <errx@plt>
   0x0000000000001207 <+62>:    mov    DWORD PTR [rbp-0x34],0x0
   0x000000000000120e <+69>:    mov    rax,QWORD PTR [rbp-0x50]
   0x0000000000001212 <+73>:    add    rax,0x8
   0x0000000000001216 <+77>:    mov    rdx,QWORD PTR [rax]
   0x0000000000001219 <+80>:    lea    rax,[rbp-0x30]
   0x000000000000121d <+84>:    mov    rsi,rdx
   0x0000000000001220 <+87>:    mov    rdi,rax
   0x0000000000001223 <+90>:    call   0x1090 <strcpy@plt> // breakpoint here
   0x0000000000001228 <+95>:    mov    eax,DWORD PTR [rbp-0x34]
   0x000000000000122b <+98>:    test   eax,eax
   0x000000000000122d <+100>:   je     0x1247 <main+126>
   0x000000000000122f <+102>:   mov    eax,DWORD PTR [rbp-0x34]
   0x0000000000001232 <+105>:   mov    esi,eax
   0x0000000000001234 <+107>:   lea    rdi,[rip+0xde5]        # 0x2020
   0x000000000000123b <+114>:   mov    eax,0x0
   0x0000000000001240 <+119>:   call   0x10d0 <printf@plt>
   0x0000000000001245 <+124>:   jmp    0x1253 <main+138>
   0x0000000000001247 <+126>:   lea    rdi,[rip+0xe12]        # 0x2060
   0x000000000000124e <+133>:   call   0x10a0 <puts@plt>
   0x0000000000001253 <+138>:   mov    eax,0x0
   0x0000000000001258 <+143>:   mov    rcx,QWORD PTR [rbp-0x8]
   0x000000000000125c <+147>:   xor    rcx,QWORD PTR fs:0x28
   0x0000000000001265 <+156>:   je     0x126c <main+163>
   0x0000000000001267 <+158>:   call   0x10b0 <__stack_chk_fail@plt>
   0x000000000000126c <+163>:   leave  
   0x000000000000126d <+164>:   ret    
End of assembler dump.
(gdb) break *0x0000000000001223            // I want to set the breakpoint here
Breakpoint 1 at 0x1223
(gdb) r AAAA                               // I try to run the program providing arguments
Starting program: /home/ryan/liveoverflow_youtube/0x05_simple_crackme_intro_assembler/stackReg AAAA

[1]+  Stopped                 gdb stackReg // This is the problem? 

Upvotes: 0

Views: 600

Answers (1)

Andrew
Andrew

Reputation: 4751

GDB stopping like this is a bug which occurs when GDB throws an error while trying to place a breakpoint, it was fixed in upstream GDB with this patch:

https://sourceware.org/ml/gdb-patches/2019-05/msg00361.html

Once you see GDB stopped like this:

[1]+ Stopped

you should be dropped back to a shell. Just resume GDB with the fg command and continue your debug session. Once GDB 9 is out this bug will be fixed.

As was pointed out in a comment the reason the breakpoint address is incorrect is that you are using a Position Independent Executable (PIE), the code will be relocated when the process starts.

Start GDB with starti, then you can disassemble main and see where the code has actually been placed.

Upvotes: 4

Related Questions