为什么在GDB上出现断点问题? GDB停止 [英] Why do i have this problem with breakpoints on GDB? GDB Stops

查看:285
本文介绍了为什么在GDB上出现断点问题? GDB停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试调用函数 strcpy()时,我试图在GDB上设置一个断点,但是GDB停止了,我不知道如何找到错误,这对GDB和我想研究二进制剥削,因此我正在阅读的论坛对此没有任何解释,这里是输出;

(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? 

解决方案

GDB停止是一个错误,当GDB在尝试放置断点时引发错误时,就会发生此错误,此错误已通过以下补丁在上游GDB中修复:

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

一旦看到GDB这样停止:

[1]+ Stopped

您应该放回外壳.只需使用fg命令恢复GDB,然后继续进行调试会话. GDB 9发布后,此错误将得到修复.

正如评论中指出的那样,断点地址不正确的原因是您使用的是位置独立可执行文件(PIE),该代码将在流程启动时重新定位.

使用starti启动GDB,然后您可以反汇编main并查看代码的实际放置位置.

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? 

解决方案

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.

这篇关于为什么在GDB上出现断点问题? GDB停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆