Skip to content

osx priv-esc cve-2024-27822#21499

Merged
msutovsky-r7 merged 2 commits into
rapid7:masterfrom
h00die:mac_priv_esc
Jul 6, 2026
Merged

osx priv-esc cve-2024-27822#21499
msutovsky-r7 merged 2 commits into
rapid7:masterfrom
h00die:mac_priv_esc

Conversation

@h00die

@h00die h00die commented May 25, 2026

Copy link
Copy Markdown
Contributor

fixes #19914

This PR adds an exploit for older MACs (like I have) with cve-2024-27822. Requires user interaction.

This module exploits CVE-2024-27822, a vulnerability in macOS
PackageKit.framework where PKG installer scripts using a ZSH shebang
(#!/bin/zsh) are executed as root while inheriting the installing user's
environment. This causes ZSH to load the user's ~/.zshenv with root
privileges before the installer script body runs.

The module injects a payload into ~/.zshenv that only fires when EUID is 0,
uploads a minimal PKG (from data/exploits/CVE-2024-27822/template.pkg) whose
install script uses a #!/bin/zsh shebang, and opens it with Installer.app.
When the user approves the installation dialog and authenticates, PackageKit
runs the install script as root. ZSH sources ~/.zshenv before the script body
executes, so the payload fires with root privileges. The original ~/.zshenv
content is restored immediately after the payload runs.

Affected: macOS 14.4 and earlier, 13.6.6 and earlier, 12.7.4 and earlier,
and all macOS 11 and older releases.
Fixed in: macOS 14.5, 13.6.7, 12.7.5.

Claude assisted in generating this code.

Verification

  • Start msfconsole
  • get a user session
  • use exploit/osx/local/packagekit_zshenv_privesc
  • set parameters as needed
  • exploit
  • You'll need to click through the install on the mac
  • Verify you get a shell

Comment thread modules/exploits/osx/local/packagekit_zshenv_privesc.rb Outdated
Comment thread modules/exploits/osx/local/packagekit_zshenv_privesc.rb Outdated
Comment thread modules/exploits/osx/local/packagekit_zshenv_privesc.rb
Comment thread modules/exploits/osx/local/packagekit_zshenv_privesc.rb

@msutovsky-r7 msutovsky-r7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msf exploit(osx/local/packagekit_zshenv_privesc) > [*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. macOS 11.7.11 (11 and older) is vulnerable
[*] Injecting payload into /Users/ms/.zshenv
[*] Uploading PKG: /tmp/SoftwareUpdate.pkg
[+] PKG uploaded: /tmp/SoftwareUpdate.pkg
[!] Opening Installer.app - the user must click Install and authenticate.
[!] Tried to delete /Users/ms/.zshenv, unknown result
[*] Command shell session 2 opened (10.38.37.13:4444 -> 10.11.58.111:44973) at 2026-07-01 11:38:04 +0200
id
[*] exec: id

uid=1000(ms) gid=1000(ms) groups=1000(ms),3(sys),90(network),950(docker),956(libvirt),959(nopasswdlogin),979(rfkill),982(users),983(video),985(storage),989(lp),990(kvm),995(audio),998(wheel)

@h00die

h00die commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Review comments addressed, retested and got my shell still

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Metasploit Kanban Jul 4, 2026
@msutovsky-r7 msutovsky-r7 merged commit 1e0760f into rapid7:master Jul 6, 2026
18 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Metasploit Kanban Jul 6, 2026
@msutovsky-r7 msutovsky-r7 added the rn-modules release notes for new or majorly enhanced modules label Jul 6, 2026
@msutovsky-r7

msutovsky-r7 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Release Notes

This adds a new local privilege escalation module for macOS targeting CVE-2024-27822 in PackageKit.framework. When a PKG installer script uses a ZSH shebang, PackageKit runs it as root while inheriting the installing user's environment, causing ZSH to source the user's ~/.zshenv with root privileges. The module plants a payload in ~/.zshenv that fires only when running as root, then opens a minimal PKG with Installer.app; once the user approves the installation prompt and authenticates, the payload executes as root and a root session is returned. Affected versions are macOS 14.4, 13.6.6, 12.7.4, and 11 and earlier; the issue is patched in 14.5, 13.6.7, and 12.7.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs module rn-modules release notes for new or majorly enhanced modules

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

CVE-2024-27822: macOS priv esc in PackageKit

4 participants