Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x-terminal-emulator gdb.attach not working properly #2362

Open
cnitlrt opened this issue Mar 3, 2024 · 4 comments · May be fixed by #2363
Open

x-terminal-emulator gdb.attach not working properly #2362

cnitlrt opened this issue Mar 3, 2024 · 4 comments · May be fixed by #2363

Comments

@cnitlrt
Copy link

cnitlrt commented Mar 3, 2024

pwntools version

Name: pwntools
Version: 4.12.0
Summary: Pwntools CTF framework and exploit development library.
Home-page: 
Author: 
Author-email: "Gallopsled et al." <[email protected]>
License: Mostly MIT, some GPL/BSD, see LICENSE-pwntools.txt
Location: /home/ubuntu/.local/lib/python3.8/site-packages
Requires: capstone, colored-traceback, intervaltree, mako, packaging, paramiko, pip, psutil, pyelftools, pygments, pyserial, pysocks, python-dateutil, requests, ropgadget, rpyc, six, sortedcontainers, unicorn, unix-ar, zstandard
Required-by: 

Testcase

test.c

//gcc test.c -o test
#include <stdio.h>
#include <string.h>

int main(){
    puts("Hello");
    char buf[0x20];
    read(0,buf,0x20);
    puts("Hello");
    read(0,buf,0x20);
}

exp.py

from pwn import*
context.arch = "amd64"
# context.log_level = "debug"
p = process("./test")
p.recvuntil(b"Hello")
p.send(b"aaaa")
p.recvuntil(b"Hello")
attach(p)
p.send(b"aaaa")
p.interactive()

Debug Output

image
When I used gdb.attach in x-terminal on ubuntu20.04 to debug, I got an error. I think maybe run_new_terminal returned the wrong gdb_pid so I tried +1 it and found that it worked normally #2363
image

environ

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.6 LTS
Release:	20.04
Codename:	focal

GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
@peace-maker
Copy link
Member

x-terminal-emulator isn't a program on it's own but just a meta placeholder for various terminal emulators. I think this is special to the terminal you're using and should be more strict around that terminal instead of the meta group.

Try update-alternatives --display x-terminal-emulator to see which terminal you're actually using. Maybe it sets some environment variable you could detect?

@cnitlrt
Copy link
Author

cnitlrt commented Mar 3, 2024

thank you for your reply,I used the update-alternatives --display x-terminal-emulator command to show that the terminal in use is /usr/bin/gnome-terminal.wrapper

╰─$ update-alternatives --display x-terminal-emulator
x-terminal-emulator - auto mode
  link best version is /usr/bin/gnome-terminal.wrapper
  link currently points to /usr/bin/gnome-terminal.wrapper
  link x-terminal-emulator is /usr/bin/x-terminal-emulator
  slave x-terminal-emulator.1.gz is /usr/share/man/man1/x-terminal-emulator.1.gz
/usr/bin/gnome-terminal.wrapper - priority 40
  slave x-terminal-emulator.1.gz: /usr/share/man/man1/gnome-terminal.1.gz
/usr/bin/koi8rxterm - priority 20
  slave x-terminal-emulator.1.gz: /usr/share/man/man1/koi8rxterm.1.gz
/usr/bin/lxterm - priority 30
  slave x-terminal-emulator.1.gz: /usr/share/man/man1/lxterm.1.gz
/usr/bin/uxterm - priority 20
  slave x-terminal-emulator.1.gz: /usr/share/man/man1/uxterm.1.gz
/usr/bin/xterm - priority 20
  slave x-terminal-emulator.1.gz: /usr/share/man/man1/xterm.1.gz
╭─ubuntu@ubuntu-virtual-machine ~ 
╰─$ update-alternatives --config x-terminal-emulator
There are 5 choices for the alternative x-terminal-emulator (providing /usr/bin/x-terminal-emulator).

  Selection    Path                             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gnome-terminal.wrapper   40        auto mode
  1            /usr/bin/gnome-terminal.wrapper   40        manual mode
  2            /usr/bin/koi8rxterm               20        manual mode
  3            /usr/bin/lxterm                   30        manual mode
  4            /usr/bin/uxterm                   20        manual mode
  5            /usr/bin/xterm                    20        manual mode

Press <enter> to keep the current choice[*], or type selection number: 

@cnitlrt
Copy link
Author

cnitlrt commented Mar 3, 2024

Oh! I maybe understand what you mean. I tried changing it to xterm and found that it can be attached normally.

@cnitlrt
Copy link
Author

cnitlrt commented Mar 3, 2024

Hello, I attempted to update the code to match the terminal containing 'gnome-terminal' in the symbolic link name for 'x-terminal', and to increment the PID by 1. Does this seem reasonable? Thank you very much.
#2363

@cnitlrt cnitlrt closed this as completed Mar 13, 2024
@cnitlrt cnitlrt reopened this Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants