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

doc: add example case for tuple (host, port pair) in gdb.attach #2504

Merged
merged 6 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#2527][2527] Allow setting debugger path via `context.gdb_binary`
- [#2530][2530] Do NOT error when passing directory arguments in `checksec` commandline tool.
- [#2529][2529] Add LoongArch64 support
- [#2504][2504] doc: add example case for `tuple` (host, port pair) in `gdb.attach`

[2519]: https://github.com/Gallopsled/pwntools/pull/2519
[2507]: https://github.com/Gallopsled/pwntools/pull/2507
Expand All @@ -93,6 +94,7 @@ The table below shows which release corresponds to each branch, and what date th
[2527]: https://github.com/Gallopsled/pwntools/pull/2527
[2530]: https://github.com/Gallopsled/pwntools/pull/2530
[2529]: https://github.com/Gallopsled/pwntools/pull/2529
[2504]: https://github.com/Gallopsled/pwntools/pull/2504

## 4.15.0 (`beta`)

Expand Down
22 changes: 21 additions & 1 deletion pwnlib/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
Can be any socket type, including :class:`.listen` or :class:`.remote`.
:class:`.ssh_channel`
Remote process spawned via :meth:`.ssh.process`.
This will use the GDB installed on the remote machine.
**This will use the GDB installed on the remote machine.**
If a password is required to connect, the ``sshpass`` program must be installed.

Examples:
Expand Down Expand Up @@ -1078,6 +1078,26 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
>>> io.recvline()
b'This will be echoed back\n'
>>> io.close()

To attach to remote gdbserver, assume you have a socat server delivering gdbserver
with ``socat TCP-LISTEN:1336,reuseaddr,fork 'EXEC:"gdbserver :1337 /bin/bash"'``,
then you can connect to gdbserver and attach to it by:
(When connection with gdbserver established, ``/bin/bash`` will pause at ``_start``,
waiting for our gdb to attach.)

A typical case is a sample can't run locally as some dependencies is missing,
so this sample is provided by remote server or docker.

>>> with context.local(log_level='warning'):
... server = process(['socat', 'TCP-LISTEN:1336,reuseaddr,fork', 'EXEC:"gdbserver :1337 /bin/bash"'])
... sleep(1) # wait for socat to bind
... io = remote('127.0.0.1', 1336)
... _ = gdb.attach(('127.0.0.1', 1337), 'c', '/bin/bash')
... io.sendline(b'echo Hello')
... io.recvline()
... io.close()
... server.close()
b'Hello\n'
"""
if context.noptrace:
log.warn_once("Skipping debug attach since context.noptrace==True")
Expand Down
Loading