Skip to content
RCE Write-up Intermediate

CVE-2024-27822: macOS PackageKit Privilege Escalation

macOS PackageKit ran installation scripts from PKG files as root but in the current user's environment, so a ZSH-based script would load the user's .zshenv file. An attacker who could write to that file could execute code as root when the user installed a ZSH-based PKG.

Mykola Grymalyuk Follow

Published on khronokernel.com

Another fun exploit! This time with local privilege escalation through Apple’s PackageKit.framework when running ZSH-based PKGs 🎉.

Mykola Grymalyuk, on khronokernel.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the installer spawned root scripts without clearing the user's environment, so ZSH's startup logic loaded the user-controlled .zshenv file.

What the attacker needed

Ability to write to victim's .zshenv; victim installs a ZSH-based PKG; not via MDM or Munki

The fix

Apple fixed it by setting an environment variable during root escalation and having ZSH and Bash skip loading user startup files when it is present; developers should also use --no-rcs or --noprofile --norc in shebangs.

How it was found

  1. Inject a malicious payload into the .zshenv file.
  2. Install a PKG whose installation script uses the #!/bin/zsh shebang.
  3. Observe the payload executing with root privileges.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

When you install a macOS package, a script inside it runs with the highest system permissions (root). This report found that if that script used the ZSH shell, it also read a settings file from your own home folder, which a normal user can edit. So malicious code placed in that file would run with root powers the next time you installed such a package.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from Apple (macOS)

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.