pwnlib.args
— Magic Command-Line Arguments
Pwntools exposes several magic command-line arguments and environment variables when operating in from pwn import * mode.
The arguments extracted from the command-line and removed from sys.argv
.
Arguments can be set by appending them to the command-line, or setting
them in the environment prefixed by PWNLIB_
.
The easiest example is to enable more verbose debugging. Just set DEBUG
.
$ PWNLIB_DEBUG=1 python exploit.py
$ python exploit.py DEBUG
These arguments are automatically extracted, regardless of their name, and
exposed via pwnlib.args.args
, which is exposed as the global variable
args
. Arguments which pwntools
reserves internally are not exposed
this way.
$ python -c 'from pwn import *; print(args)' A=1 B=Hello HOST=1.2.3.4 DEBUG
defaultdict(<type 'str'>, {'A': '1', 'HOST': '1.2.3.4', 'B': 'Hello'})
This is very useful for conditional code, for example determining whether to run an exploit locally or to connect to a remote server. Arguments which are not specified evaluate to an empty string.
if args['REMOTE']:
io = remote('exploitme.com', 4141)
else:
io = process('./pwnable')
Arguments can also be accessed directly with the dot operator, e.g.:
if args.REMOTE:
...
Any undefined arguments evaluate to an empty string, ''
.
The full list of supported “magic arguments” and their effects are listed below.
- pwnlib.args.DEBUG(x)[source]
Sets the logging verbosity to
debug
which displays much more information, including logging each byte sent by tubes.
- pwnlib.args.LOG_FILE(x)[source]
Sets a log file to be used via
context.log_file
, e.g.LOG_FILE=./log.txt
- pwnlib.args.LOG_LEVEL(x)[source]
Sets the logging verbosity used via
context.log_level
, e.g.LOG_LEVEL=debug
.
- pwnlib.args.NOPTRACE(v)[source]
Disables facilities which require
ptrace
such asgdb.attach()
statements, viacontext.noptrace
.