为什么我在 GDB 上的断点有这个问题?GDB 停止 [英] Why do i have this problem with breakpoints on GDB? GDB Stops

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

问题描述

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

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 像这样停止是一个错误,当 GDB 在尝试放置断点时抛出错误时,它已在上游 GDB 中通过此补丁修复:

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

一旦你看到 GDB 像这样停止:

Once you see GDB stopped like this:

[1]+ Stopped

你应该被扔回一个shell.只需使用 fg 命令恢复 GDB 并继续您的调试会话.GDB 9 发布后,此错误将得到修复.

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.

正如评论中指出的,断点地址不正确的原因是您使用的是与位置无关的可执行文件 (PIE),当进程启动时,代码将被重新定位.

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.

starti启动GDB,然后你可以反汇编main,看看代码实际放在了哪里.

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

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

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