Mustache for Ruby: RCE using built-in method access
> [!NOTE]
> The vulnerability was fully disclosed to the maintainer in private prior to security advisories were enabled for the project.
> This advisory presents a limited information for initial release to provide a time window for installing updates. Full information with PoCs would be added later.
Summary
Mustache template engine for Ruby in versions 1.1.2 and earlier allows remote attackers to achieve arbitrary code execution through accessing specific built-in methods in an attacker-supplied template.
Details
Mustache is often suggested as a safe simple template language to avoid SSTI vulnerabilities.[^1] [^2]
Mustache for Ruby up to version 1.1.2 did not properly restrict method access which allowed chaining multiple built-in methods to achieve arbitrary code execution.
> [!IMPORTANT]
> Successful exploitation of this vulnerability does not depend on any configuration or objects passed to the template engine.
> An attacker controlling the template string can achieve arbitrary code execution without any additional requirements.
Additional methods provided by the application or installed gems can further expand the attack surface but exploitation was proven without them.
PoC
All discovered payloads were tested using
ruby -e shell commands with
mustache as the only explicitly required gem:
ruby -e 'require "mustache"; puts Mustache.render("PAYLOAD GOES HERE", key: "value")'
For initial information release, only the descriptions of the most important discovered payloads would be provided:
- Universal RCE for a major Ruby version
- File upload to RCE (3 different payloads)
- Infinite memory consumption DoS
- Infinite sleep DoS
Universal RCE payloads for other major Ruby versions and other payloads could exist, as the attack surface is very large. The presented list only contains payloads discovered using a fairly primitive approach.
> [!CAUTION]
> Exploitation is not limited to the discovered Exploits/PoCs and real-life web applications are likely to expose even more dangerous functionality.
Impact
An attacker with the ability to modify the template string can execute arbitrary code in the context of the Ruby application.
Rationale for CVSS assessment:
> No network requirements are present for exploitation.
> Templating functionality is often provided on public websites.
> Attacker can expect reliable and repeatable exploitation.
> There are no requirements beyond attacker's control.
- Privileges Required: None
> Mustache is often used for untrusted user-supplied templates.
> Exploitation is often possible without authorization or by using self-registered accounts (without prior privileges).
> Mustache by itself does not provide access control functionality.
> Exploitation does not require any user interaction to achieve RCE.
> The code is executed with the same privileges as the web application, without changing the scope.
- Confidentiality Impact: High
> Arbitrary code execution leads to the total loss of confidentiality.
> Arbitrary code execution leads to the total loss of integrity.
- Availability Impact: High
> Arbitrary code execution can be used to achieve the total loss of availability.
Resources
[^1]: https://portswigger.net/knowledgebase/papers/serversidetemplateinjection.pdf
[^2]: https://hackerone.com/reports/423541
What the EG score is made of (scorer v4.0: the three questions the 0–10 score mixes, published apart · methodology)
The EG score (9.8): severity, escalated by confirmed exploitation. This CVE's 9.8 is its impact severity (EG Severity), not escalated.
- EG Severity
- 9.8 CRITICALCVSS-B, impact only: no KEV listing, EPSS or EG-KEV tier raises it.GitHub Security Advisory CVSS
- EG Likelihood
- Unknown (no EPSS on record)Unknown, not low: FIRST has published no EPSS probability for this CVE.
- Confirmed exploitation
- None on record (CISA KEV, EG-KEV Tier 1)Reported apart from the likelihood: an observed fact, not a probability.
- EG Priority
- SSVC Track at medium mission impactTrack at low or medium mission impact; Track* at high (mission-essential systems).CISA BOD 26-04: 14 days if the affected system is publicly exposed; Fix on system upgrade if it is not.Each input and its source, and whom BOD 26-04 binds: the SSVC and BOD 26-04 blocks below.
SSVC (CISA's decision table, applied by EchelonGraph)Track at low or medium mission impact; Track* at high (mission-essential systems).
A fixed version is listed under Patch Availability. Apply it within your standard update timelines.
Exploitation none (no CISA value, KEV listing or exploit code on record) · Automatable no (CISA's BOD 26-04 default) · Technical impact total (CISA's BOD 26-04 default). EchelonGraph holds no SSVC assessment of this CVE from CISA: none of these inputs is from Vulnrichment. EchelonGraph applied CISA's decision table to them; CISA publishes SSVC inputs and the table, not a decision for each CVE. Mission impact is CISA's Mission & Well-being decision point, and only you can judge it. CISA's table makes it high when Mission Prevalence is Essential — the vulnerable component "directly provides capabilities that constitute at least one MEF for at least one entity" (MEF: mission essential function) — or when Public Well-Being Impact is Irreversible: "multiple fatalities are likely", the cyber-physical system "is likely lost or destroyed", "extreme or serious externalities" are imposed on other parties, or social systems such as elections or the financial grid "are destabilized and potentially collapse". CISA's decision table
BOD 26-04 (CISA's remediation timeline, Table 1)14 days if the affected system is publicly exposed; Fix on system upgrade if it is not.
The score's inputs: In CISA KEV no (CISA's KEV catalog) · Automatable no (CISA's BOD 26-04 default) · Technical impact total (CISA's BOD 26-04 default). Where an input reads “CISA's BOD 26-04 default”, no one has published it for this CVE, and CISA's implementation guidance says: “If “Automatable” and “Technical Impact” information items about a CVE ID are not available and the CVE ID is not in the KEV Catalog, CISA will treat its values as “no” and “total,” respectively, until CISA or a third party provides metadata about the CVE ID. CISA will always provide the Vulnrichment data for a CVE ID listed in the KEV Catalog.” Whether your system is publicly exposed is yours to answer. BOD 26-04 binds US Federal Civilian Executive Branch agencies; for anyone else it is CISA's published timeline, a reference rather than an obligation. The directive · how EchelonGraph applies it