Skip to content
RCE Write-up Advanced

Rotten Apples Returns: macOS Codesigning Translocation Revisited

A flaw in macOS's AMFI framework allows certain code signing entitlements to be transplanted onto non-Apple binaries, and combined with a race condition in dyld, an attacker can inject a malicious dylib into a running application. This could enable malware deployment without root privileges if the attacker has write access to the target app's bundle.

Brandon Duncan Follow

Published on osec.com

In 2021, OSec’s vulnerability research team discovered a flaw in amfid that allowed transplanting codesigning entitlements from one binary to another. We called it “Rotten Apples.” Apple’s M1 release inadvertently patched this specific bug, though Apple never acknowledged it as a vulnerability, deeming it normal…

Brandon Duncan, on osec.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 AMFI framework's logic for unrestricted entitlements allows a signature blob containing only those entitlements to be transplanted onto any non-Apple-anchored binary, and the dyld loader has a time-of-check to time-of-use window during framework loading.

Impact

An attacker with write access to a target app's bundle could inject a malicious dylib that runs with transplanted entitlements, potentially deploying malware without root; the race succeeded 100% against Obsidian's Electron.framework in testing.

What the attacker needed

Write access to target app's bundle; no root required for user-installed apps; admin group for /Applications installs

The fix

Apple should restrict the transplantation of unrestricted entitlements to only binaries that are properly anchored, and address the TOCTOU race in dyld's framework loading.

How it was found

  1. Obtain a donor signature with suitable entitlements, such as from Obsidian's Electron.framework, or craft one.
  2. Locate the LC_CODE_SIGNATURE load command in the donor's Mach-O, copy the blob, append it to the malicious binary's __LINKEDIT segment, and add a new load command pointing to it.
  3. Clear the CS_REQUIRE_LV flag using csops(CS_OPS_CLEAR_LV) to disable library validation.
  4. Ensure write access to the target application's bundle directory, specifically the Frameworks/ subtree.
  5. Write the malicious dylib and a backup copy before starting the race.
  6. Use the renamex_np syscall with RENAME_SWAP to atomically swap the real framework binary and the malicious dylib while the target application launches and terminates repeatedly.

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.

On macOS, every program must have a digital signature that says who made it and what it is allowed to do. This research found that some of those permissions can be copied from one program to another, and by quickly swapping files during startup, an attacker can sneak their own code into a trusted app. The attacker needs to be able to write files inside the app's folder, which is often possible for apps the user installed themselves.

What is RCE?

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

More by Brandon Duncan

View all

2 more disclosed reports, best first.

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.