Php

Server-Side Template Injection (SSTI) is a vulnerability that occurs when an attacker can inject malicious input into a server-side template, causing the template engine to execute arbitrary commands on the server. In PHP, SSTI can arise when user input is embedded within templates rendered by templating engines like Smarty, Twig, or even within plain PHP templates, without proper sanitization or validation.

Summary

Templating Libraries

Template Name
Payload Format

Laravel Blade

{{ }}

Latte

{var $X=""}{$X}

Mustache

{{ }}

Plates

<?= ?>

Smarty

{ }

Twig

{{ }}

Smarty

Official websitearrow-up-right

Smarty is a template engine for PHP.


Twig

Official websitearrow-up-right

Twig is a modern template engine for PHP.

Twig - Basic Injection

Twig - Template Format

Twig - Arbitrary File Reading

Twig - Code Execution

Example injecting values to avoid using quotes for the filename (specify via OFFSET and LENGTH where the payload FILENAME is)

Example with an email passing FILTER_VALIDATE_EMAIL PHP.


Latte

Latte - Basic Injection

Latte - Code Execution


patTemplate

patTemplatearrow-up-right non-compiling PHP templating engine, that uses XML tags to divide a document into different parts


PHPlib and HTML_Template_PHPLIB

HTML_Template_PHPLIBarrow-up-right is the same as PHPlib but ported to Pear.

authors.tpl

authors.php


Plates

Plates is inspired by Twig but a native PHP template engine instead of a compiled template engine.

controller:

page template:

layout template:

References

Last updated