pwntools icon indicating copy to clipboard operation
pwntools copied to clipboard

How do I remove DEBUG/INFO messages?

Open nigel opened this issue 3 years ago • 2 comments

I'm looking through the documentation for logging. I have tried setting context.log_level to NOTSET, CRITICAL, and WARNING.

However, I was never able to get rid of the DEBUG/INFO messages coming from calling pwn.asm, pwn.ELF.from_assembly, etc. DEBUG and INFO messages are still popping up,

I am calling import pwn instead of from pwn import * if that matters-- There are other imports in my project and I'm not using this for CTF purposes. How do I remove this debug output?

nigel avatar Jul 28 '22 22:07 nigel

Have you tried context.quiet? I do not know where are those messages coming from. They might be caused by internal log_level manipulations throughout the library. You should probably take a look at pwnlib.args for some explanation on what the difference is between from pwn import * / import pwn and import pwnlib / from pwnlib import stuff.

Arusekk avatar Jul 30 '22 21:07 Arusekk

The easiest way to get rid of them is to use the pwnlib.args magic.

https://docs.pwntools.com/en/latest/args.html

The easiest way is to use e.g. python3 ./myexploit.py SILENT which should silence everything but errors.

Otherwise, you can use python3 ./myexploit.py LOG_LEVEL=warn.

# $ cat 2089.py
#!/usr/bin/env python3
from pwn import *

debug('debug')
info('info')
warn('warning')
error('error')
# fatal('fatal')
$ python3 2089.py LOG_LEVEL=debug
[DEBUG] debug
[*] info
[!] warning
[ERROR] error
Traceback (most recent call last):
  File "/Users/zachriggle/github.com/ctf-solutions/pwntools/issues/2089.py", line 7, in <module>
    error('error')
  File "/Users/zachriggle/github.com/pwntools/pwnlib/log.py", line 439, in error
    raise PwnlibException(message % args)
pwnlib.exception.PwnlibException: error
$ python3 2089.py LOG_LEVEL=warn
[!] warning
[ERROR] error
Traceback (most recent call last):
  File "/Users/zachriggle/github.com/ctf-solutions/pwntools/issues/2089.py", line 7, in <module>
    error('error')
  File "/Users/zachriggle/github.com/pwntools/pwnlib/log.py", line 439, in error
    raise PwnlibException(message % args)
pwnlib.exception.PwnlibException: error

zachriggle avatar Aug 22 '22 09:08 zachriggle

You can also set context.log_level='warn'

zachriggle avatar Feb 09 '23 17:02 zachriggle

if you don't care about any logs, using the old ./exploit.py 2>/dev/null is always an option.

shellmage avatar Nov 22 '23 00:11 shellmage