Skip to content

Commit 447ac94

Browse files
doc: add example case for tuple (host, port pair) in gdb.attach (#2504)
* doc: add example case for `tuple` * update changelog * doc: fix typos and test errors * gdb: complete attach doc * gdb: sleep in doc test to pass test --------- Co-authored-by: peace-maker <[email protected]>
1 parent 3eb690b commit 447ac94

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ The table below shows which release corresponds to each branch, and what date th
8383
- [#2527][2527] Allow setting debugger path via `context.gdb_binary`
8484
- [#2530][2530] Do NOT error when passing directory arguments in `checksec` commandline tool.
8585
- [#2529][2529] Add LoongArch64 support
86+
- [#2504][2504] doc: add example case for `tuple` (host, port pair) in `gdb.attach`
8687

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

9799
## 4.15.0 (`beta`)
98100

pwnlib/gdb.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
963963
Can be any socket type, including :class:`.listen` or :class:`.remote`.
964964
:class:`.ssh_channel`
965965
Remote process spawned via :meth:`.ssh.process`.
966-
This will use the GDB installed on the remote machine.
966+
**This will use the GDB installed on the remote machine.**
967967
If a password is required to connect, the ``sshpass`` program must be installed.
968968
969969
Examples:
@@ -1078,6 +1078,26 @@ def attach(target, gdbscript = '', exe = None, gdb_args = None, ssh = None, sysr
10781078
>>> io.recvline()
10791079
b'This will be echoed back\n'
10801080
>>> io.close()
1081+
1082+
To attach to remote gdbserver, assume you have a socat server delivering gdbserver
1083+
with ``socat TCP-LISTEN:1336,reuseaddr,fork 'EXEC:"gdbserver :1337 /bin/bash"'``,
1084+
then you can connect to gdbserver and attach to it by:
1085+
(When connection with gdbserver established, ``/bin/bash`` will pause at ``_start``,
1086+
waiting for our gdb to attach.)
1087+
1088+
A typical case is a sample can't run locally as some dependencies is missing,
1089+
so this sample is provided by remote server or docker.
1090+
1091+
>>> with context.local(log_level='warning'):
1092+
... server = process(['socat', 'TCP-LISTEN:1336,reuseaddr,fork', 'EXEC:"gdbserver :1337 /bin/bash"'])
1093+
... sleep(1) # wait for socat to bind
1094+
... io = remote('127.0.0.1', 1336)
1095+
... _ = gdb.attach(('127.0.0.1', 1337), 'c', '/bin/bash')
1096+
... io.sendline(b'echo Hello')
1097+
... io.recvline()
1098+
... io.close()
1099+
... server.close()
1100+
b'Hello\n'
10811101
"""
10821102
if context.noptrace:
10831103
log.warn_once("Skipping debug attach since context.noptrace==True")

0 commit comments

Comments
 (0)