cs01 / gdbgui

Browser-based frontend to gdb (gnu debugger). Add breakpoints, view the stack, visualize data structures, and more in C, C++, Go, Rust, and Fortran. Run gdbgui from the terminal and a new tab will open in your browser.
https://gdbgui.com
GNU General Public License v3.0
9.9k stars 499 forks source link

Using "Connect to gdbserver" option overwrites/corrupts input binary #370

Open BinaryWarlock opened 3 years ago

BinaryWarlock commented 3 years ago

Describe the bug As noted, I just tried gdbgui, I followed the guide and typed in my binary path (which is in the current working directory), and hit "Load binary". The md5sum of the binary then changes, and attempting to run it shows it's been corrupted.

To Reproduce Steps to reproduce the behavior:

  1. Type in a path to a binary
  2. Hit "Load Binary"
  3. Hit "Connect to gdbserver"
  4. Compare contents/hashes of the binary before and after
  5. Observe that they are different

In this case, with a simple C hello world:

e69083542e702b7f5a8feb304a958d8a  g # corrupted by gdbgui
36690ecdd2b375e200ce03a7870d1e09  g.bak # backed up original

Expected behavior Not modifying the input binary

Screenshots If applicable, add screenshots to help explain your problem.

Please complete the following information:

Additional context

The gdb console says:

Remote connection closed

And that's it.

It overwrites the ELF header with:

0000h: 2B 24 71 53 75 70 70 6F 72 74 65 64 3A 6D 75 6C  +$qSupported:mul 
0010h: 74 69 70 72 6F 63 65 73 73 2B 3B 73 77 62 72 65  tiprocess+;swbre 
0020h: 61 6B 2B 3B 68 77 62 72 65 61 6B 2B 3B 71 52 65  ak+;hwbreak+;qRe 
0030h: 6C 6F 63 49 6E 73 6E 2B 3B 66 6F 72 6B 2D 65 76  locInsn+;fork-ev 
0040h: 65 6E 74 73 2B 3B 76 66 6F 72 6B 2D 65 76 65 6E  ents+;vfork-even 
0050h: 74 73 2B 3B 65 78 65 63 2D 65 76 65 6E 74 73 2B  ts+;exec-events+ 
0060h: 3B 76 43 6F 6E 74 53 75 70 70 6F 72 74 65 64 2B  ;vContSupported+ 
0070h: 3B 51 54 68 72 65 61 64 45 76 65 6E 74 73 2B 3B  ;QThreadEvents+; 
0080h: 6E 6F 2D 72 65 73 75 6D 65 64 2B 3B 78 6D 6C 52  no-resumed+;xmlR 
0090h: 65 67 69 73 74 65 72 73 3D 69 33 38 36 23 36 61  egisters=i386#6a 
BinaryWarlock commented 3 years ago

Actually I suppose it's just that the binary filename is kept in the textbox which is expected to be a connection string, and for some reason gdbgui overwrites that file. That's bad and unexpected default behavior.