Online Python Editor
Description: If you’re tired of fast and good-looking editors, try this. Now with extra crispiness!
Introduction
This is the first web in the TRX2025 CTF. And it’s basically a simple online Python editor with a syntax checker.
Source
Go to the source code and we can immediately see two things:
-
In a file called
secret.py
, which is never called, read or otherwise used. -
The main
app.py
file
What happens is that the template is rendered and every N seconds the check
method is called, which parses the Python code sent by the client and returns the traceback, which is very useful for us later.
Solution
Where’s the vuln? Well, it’s quite simple here: ast.parse(**request.json)
, The call to ast.parse
is vulnerable to Python code injection, in fact we can pass arbitrary parameters to the function (because of the **request.json
), and if we look at the documentation for ast.parse
we know that we can pass a filename to the function, and ast.parse uses something like compile(source, filename, mode, PyCF_ONLY_AST)
, which allows us to leak sensitive information causing syntax errors in specific lines of code.
So finally we get
Author: akiidjk