Twig
Last updated
Was this helpful?
Last updated
Was this helpful?
The content below is based on OffSec's course.
PHP does not check data types, thus, treats strings as numbers. Both the examples below will be evaluated to 25
.
A unique piece of Twig syntax is using -
to trim whitespace.
A for
loop.
A if
statement and the use of the capitalize
filter.
To make sure that this is indeed a server-side and not a client-side template injection, we can view the source code and check if the result is 49
or {{7*'7'}}
.
The example below is based on TCM's course.
Following the methodology outlined , we can see that we are dealing with a Twig engine (Figure 1).
We can also confirm that we are dealing with either a Twig or Jinja2 engine by following the steps outlined (Figure 2). Twig uses PHP which does not check the variable type and as a result it treats 7
and '7'
the same.
Next, we can try any Twig-specific payload from this , in this case leveraging the filter, and achieve (Figure 3).
The above process could be automated using .
The example below is based on OffSec's course.
Another filter we can leverage is the filter which takes an arrow function and an initial value as arguments (Figure 4).
We can replace the arguments with something that executes system commands, such as PHP's function and achieve RCE (Figure 5).
reduce
filter.reduce
filter to achieve RCE.