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

Add support for gef-remote in gdb.attach #2264

Closed
ValekoZ opened this issue Sep 11, 2023 · 11 comments
Closed

Add support for gef-remote in gdb.attach #2264

ValekoZ opened this issue Sep 11, 2023 · 11 comments
Labels

Comments

@ValekoZ
Copy link
Contributor

ValekoZ commented Sep 11, 2023

It would be a nice feature to be able to use gef-remote when using gef instead of the traditional target remote used in gdb.attach and maybe target extended-remote used here for instance.

Maybe something like the following could do the trick ?

gefpi
>>> if 'gef' in locals():
...     gdb.execute(f'gef-remote {host} {port}')
... else:
...     gdb.execute(f'target remote {host}:{port}')

This could also be a nice feature to add better support for qemu debugging ? I didn't really tested how it works atm but I guess using the qemu-mode should improve it for gef users.

@peace-maker
Copy link
Member

Hm, how would you detect if gef is installed in gdb from the exploit script? Running the detection in python in gdb appears to be the easiest way indeed. I am not sure in which context the commands get executed by gdb.execute - immediately or using some command buffer after the other commands in the gdbscript were ran. Do you want to work on this?

@ValekoZ
Copy link
Contributor Author

ValekoZ commented Sep 12, 2023

Detecting if gef is installed from the exploit script does not seem like something we can do easily. The only way I can see to detect it is directly from gdb.
Maybe we can do it without python in the gdb script ? Or just let the user specify if he uses gef with an argument but it would not be really clean ..

And about your question, afaik gdb.execute will execute the command immediately but I will check that.
I could try to implement this if you want :)

@peace-maker
Copy link
Member

I don't think having some context.have_gef option is a good idea too. Having it just use the correct commands when having gef installed is way nicer.

@Arusekk
Copy link
Member

Arusekk commented Oct 14, 2023

I wonder why GEF does not overwrite the default behaviour if it is unsupported; maybe they could 'fix' it? Pwndbg for example detects what happens on the other end and then adapts (with monitor commands).

Nevertheless, can you try to implement that in the default gdbscript preamble used in pwntools and submit it as a pull request? It should be as easy as py Y() if X else Z(). I think it is safe to assume everybody has Python in their GDB nowadays.

@ValekoZ
Copy link
Contributor Author

ValekoZ commented Oct 24, 2023

After discussing this with @hugsy, probably the best way to resolve this issue is to resolve it directly in gef.
But the "gef-remote" command actually uses the "target remote" command under the hood, so it might not be trivial to fix it.
I'll check how this is done on pwndbg and check if it seems feasible to port the same logic to gef :)

@peace-maker
Copy link
Member

Cool, please keep us updated here!

@peace-maker
Copy link
Member

Any news?

@ValekoZ
Copy link
Contributor Author

ValekoZ commented Dec 6, 2023

Sorry, I did not have much time those days.
The issue seems to correctly work in gef, and I just tested if it worked correctly with pwntools on top of that and it works fine :)

Grazfather pushed a commit to hugsy/gef that referenced this issue Dec 16, 2023
As mentioned in Gallopsled/pwntools#2264, gef does not work properly
with many tools that rely on the `target remote` command.
In this PR, I propose a fix that uses a remote posthook in order to
instantiate and setup the GefRemoteSessionManager after the connection
being established.

Note that this isn't a perfect solution since we do not have all the
information needed for a proper instantiation of the
GefRemoteSessionManager, but it seems to be a good workaround in order
to make tools like `pwntools` work correctly with gef.
@peace-maker
Copy link
Member

Appears to be fixed in gef. Thank you @ValekoZ!

@Grazfather
Copy link
Contributor

It would be nice if there were some option in pwntools that let us override the command issued for a remote session. That way detection would be unnecessary, but we could explicitly overwrite it to e.g. gef-remote in this case.

@peace-maker
Copy link
Member

Do you have a use case in mind where you need this? I thought gef works now with target remote?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants