🌐
pwntools
docs.pwntools.com › en › stable › context.html
pwnlib.context — Setting runtime variables — pwntools 4.15.0 documentation
Many settings in pwntools are controlled via the global variable context, such as the selected target operating system, architecture, and bit-width.
Getting Started
>>> asm('nop') b'\x90' >>> context(arch='arm', os='linux', endian='big', word_size=32) >>> asm('nop') b'\xe3 \xf0\x00' You can control the verbosity of the standard pwntools logging via context.
pwnlib.tubes
Same as recv(), but returns a str, decoding the result using context.encoding.
Installation
Pwntools is best supported on 64-bit Ubuntu LTS releases (14.04, 16.04, 18.04, and 20.04). Most functionality should work on any Posix-like distribution (Debian, Arch, FreeBSD, OSX, etc.) · In order to get the most out of pwntools, you should have the following system libraries installed
pwnlib.tubes.process
The default value is inherited from context.aslr.
🌐
Readthedocs
python3-pwntools.readthedocs.io › en › latest › context.html
pwnlib.context — Setting runtime variables — pwntools 2.2.1 documentation
Global context object, used to store commonly-used pwntools settings. In most cases, the context is used to infer default variables values. For example, pwnlib.asm.asm() can take an os parameter as a keyword argument. If it is not supplied, the os specified by context is used instead.
🌐
pwntools
docs.pwntools.com › en › stable
pwntools — pwntools 4.15.0 documentation
pwnlib.config — Pwntools Configuration File · pwnlib.context — Setting runtime variables · pwnlib.dynelf — Resolving remote functions using leaks · pwnlib.encoders — Encoding Shellcode · pwnlib.elf.config — Kernel Config Parsing · pwnlib.elf.corefile — Core Files ·
🌐
GitHub
github.com › Gallopsled › pwntools-tutorial › blob › master › context.md
pwntools-tutorial/context.md at master · Gallopsled/pwntools-tutorial
The context object is a global, thread-aware object which contains various settins used by pwntools.
Author   Gallopsled
🌐
Agr0 Hacks Stuff
agrohacksstuff.io › posts › pwntools-tricks-and-examples
Pwntools Tricks and Examples | Agr0 Hacks Stuff
September 12, 2024 - Pwntools needs to know the endianness and architecture, as well as whether or not we’re dealing with any built-in securities. Additionally, the context tells pwntools how you prefer to have your local setup, which includes the ability to open and attach a gdb debugging window alongside your ...
🌐
pwntools
docs.pwntools.com › en › dev › context.html
pwnlib.context — Setting runtime variables — pwntools 5.0.0dev documentation
Many settings in pwntools are controlled via the global variable context, such as the selected target operating system, architecture, and bit-width.
🌐
pwntools
docs.pwntools.com › en › stable › globals.html
from pwn import * — pwntools 4.15.0 documentation
pwnlib.context.context · Responsible for most of the pwntools convenience settings · Set context.log_level = ‘debug’ when troubleshooting your exploit · Scope-aware, so you can disable logging for a subsection of code via ContextType.local() remote, listen, ssh, process ·
🌐
Zeshan Ahmed Nobin
nobinpegasus.github.io › blog › a-beginners-guide-to-pwntools
A beginners guide to pwntools | Zeshan Ahmed Nobin
September 27, 2023 - p = process("./chal") # or context.binary = "./chal" # setting the context automatically tells pwntools to run that specific binary.
🌐
pwntools
docs.pwntools.com › en › dev
pwntools — pwntools 5.0.0dev documentation
pwnlib.config — Pwntools Configuration File · pwnlib.context — Setting runtime variables · pwnlib.dynelf — Resolving remote functions using leaks · pwnlib.encoders — Encoding Shellcode · pwnlib.elf — ELF Executables and Libraries · pwnlib.exception — Pwnlib exceptions ·
🌐
pwntools
docs.pwntools.com › en › stable › intro.html
Getting Started — pwntools 4.15.0 documentation
>>> asm('nop') b'\x90' >>> context(arch='arm', os='linux', endian='big', word_size=32) >>> asm('nop') b'\xe3 \xf0\x00' You can control the verbosity of the standard pwntools logging via context.
Find elsewhere
🌐
Gitbook
ir0nstone.gitbook.io › notes › misc › pwntools › logging_and_context
Logging and Context - Cybersecurity Notes - GitBook
March 5, 2021 - Libc base is at 0xf7653000') [+] ASLR bypassed! Libc base is at 0xf7653000 ... context is a 'global' variable in pwntools that allows you to set certain values once and all future functions automatically use that data.
🌐
Corgi
corgi.rip › posts › pwntools-cheatsheet
Yet Another Pwntools Cheatsheet | .
April 4, 2024 - # pwntools needs context for things like shellcode generation # if you don't set this yourself, pwntools may give the wrong info # the easiest way to do this is simply exe = ELF("./vuln_program") context.binary = exe # but you are free to set it yourself context.arch = 'amd64' # accepts i386, ...
🌐
Readthedocs
python3-pwntools.readthedocs.io › en › latest › globals.html
from pwn import * — pwntools 2.2.1 documentation
pwnlib.context.context · Responsible for most of the pwntools convenience settings · Set context.log_level = ‘debug’ when troubleshooting your exploit · Scope-aware, so you can disable logging for a subsection of code via pwnlib.context.ContextType.local ·
🌐
pwntools
docs.pwntools.com › en › stable › config.html
pwnlib.config — Pwntools Configuration File — pwntools 4.15.0 documentation
[log] success.symbol=😎 error.symbol=☠ info.color=blue [context] adb_port=4141 randomize=1 timeout=60 terminal=['x-terminal-emulator', '-e'] [update] interval=7
🌐
GitHub
github.com › Gallopsled › pwntools › blob › dev › pwnlib › context › __init__.py
pwntools/pwnlib/context/__init__.py at dev · Gallopsled/pwntools
#: #: In most cases, the context is used to infer default variables values. #: For example, :func:`.asm` can take an ``arch`` parameter as a · #: keyword argument. #: #: If it is not supplied, the ``arch`` specified by ``context`` is used instead.
Author   Gallopsled
🌐
Medium
medium.com › @zeshanahmednobin › title-a-beginners-guide-to-pwntools-aaf56fc62e0a
A beginners guide to pwntools. [Pwntools](https://github.com/Gallopsled… | by NobinPegasus | Medium
November 15, 2023 - # or context.binary = “./chal” # setting the context automatically tells pwntools to run that specific binary.
🌐
Readthedocs
pwntools-docs-zh.readthedocs.io › zh-cn › dev › context.html
pwnlib.context — 设置运行时参数 — pwntools 3.12.0dev 文档
Many settings in pwntools are controlled via the global variable context, such as the selected target operating system, architecture, and bit-width.
🌐
pwntools
docs.pwntools.com › en › dev › intro.html
Getting Started — pwntools 5.0.0dev documentation
>>> asm('nop') b'\x90' >>> context(arch='arm', os='linux', endian='big', word_size=32) >>> asm('nop') b'\xe3 \xf0\x00' You can control the verbosity of the standard pwntools logging via context.
Top answer
1 of 1
16

You can use the pwnlib.gdb to interface with gdb.

You can use the gdb.attach() function: From the docs:

bash = process('bash')

# Attach the debugger
gdb.attach(bash, '''
set follow-fork-mode child
break execve
continue
''')

# Interact with the process
bash.sendline('whoami')

or you can use gdb.debug():

# Create a new process, and stop it at 'main'
io = gdb.debug('bash', '''
# Wait until we hit the main executable's entry point
break _start
continue

# Now set breakpoint on shared library routines
break malloc
break free
continue
''')

# Send a command to Bash
io.sendline("echo hello")

# Interact with the process
io.interactive()

The pwntools template contains code to get you started with debugging with gdb. You can create the pwntools template by running pwn template ./binary_name > template.py. Then you have to add the GDB arg when you run template.py to debug: ./template.py GDB.

If you get [ERROR] Could not find a terminal binary to use., you might need to set context.terminal before you use gdb.

If you're using tmux, the following will automatically open up a gdb debugging session in a new horizontally split window:
context.terminal = ["tmux", "splitw", "-h"]

And to split the screen with the new gdb session window vertically:
context.terminal = ["tmux", "splitw", "-v"]

(Note: I never got this part working, so idk if it'll work. Tell me if you get the gdb thing working).
(To use tmux, install tmux on your machine, and then just type tmux to start it. Then type python template.py GDB.

If none of the above works, then you can always just start your script, use ps aux, find the PID, and then use gdb -p PID to attach to the running process.