pwnlib.log and — Logging stuff¶
Logging module for printing status during an exploit, and internally within pwntools.
By using the standard from pwn import *, an object named log will be inserted into the global namespace. You can use this to print out status messages during exploitation.
[*] Hello, world!
Additionally, there are some nifty mechanisms for performing status updates on a running job (e.g. when brute-forcing).:
p = log.progress('Working') p.status('Reticulating splines') time.sleep(1) p.success('Got a shell!')
The verbosity of logging can be most easily controlled by setting context.log_level on the global context object.:
log.info("No you see me") context.log_level = 'error' log.info("Now you don't")
A module-specific logger can be imported into the module via:
log = logging.getLogger(__name__)
This provides an easy way to filter logging programmatically or via a configuration file for debugging.
There’s no need to expressly import this log module.
When using progress, you should use the with keyword to manage scoping, to ensure the spinner stops if an exception is thrown.
- class pwnlib.log.Logger(*args, **kwargs)¶
Specialization of logging.Logger which uses pwnlib.context.context.log_level to infer verbosity.
Also adds some pwnlib flavor via:
Adds pwnlib-specific information for coloring and indentation to the log records passed to the logging.Formatter.
Internal:Permits prepending a string to each message, by means of msg_prefix. This is leveraged for progress messages.
Logs a debug message.
To be called outside an exception handler.
Logs an error message, then raises a PwnlibException.
Logs a failure message. If the Logger is animated, the animation is stopped.
- indented(message, level=logging.INFO)¶
Log an info message without the line prefix.
Parameters: level (int) – Alternate log level at which to set the indented message.
Logs an info message.
Logs an info message. The same message is never printed again.
- progress(self) → Logger¶
The Logger returned is also a scope manager. Using scope managers ensures that the animation is stopped, even if an exception is thrown.
- with log.progress(‘Trying something...’) as p:
- for i in range(10):
- p.status(“At %i” % i) time.sleep(0.5)
x = 1/0
Logs a success message. If the Logger is animated, the animation is stopped.
Logs a warning message.
Logs a warning message. The same message is never printed again.