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.NOASLR(v)[source]

Disables ASLR via context.aslr

pwnlib.args.NOPTRACE(v)[source]

Disables facilities which require ptrace such as gdb.attach() statements, via context.noptrace.

pwnlib.args.NOTERM(v)[source]

Disables pretty terminal settings and animations.

pwnlib.args.RANDOMIZE(v)[source]

Enables randomization of various pieces via context.randomize

pwnlib.args.SILENT(x)[source]

Sets the logging verbosity to error which silences most output.

pwnlib.args.STDERR(v)[source]

Sends logging to stderr by default, instead of stdout

pwnlib.args.TIMEOUT(v)[source]

Sets a timeout for tube operations (in seconds) via context.timeout, e.g. TIMEOUT=30

pwnlib.args.asbool(s)[source]

Convert a string to its boolean value

pwnlib.args.isident(s)[source]

Helper function to check whether a string is a valid identifier, as passed in on the command-line.