CVE-2023-26818 - Bypass TCC with Telegram in macOS
The Telegram macOS app was not built with the Hardened Runtime, so an attacker could inject an unsigned dynamic library via the DYLD_INSERT_LIBRARIES environment variable. This allowed the injected code to inherit Telegram's camera permission and record video without the user's consent.
Let’s dive into a sneaky flaw in the Telegram app on macOS that lets us inject a Dynamic Library (Dylib). We’ll cover some essential macOS concepts to help you grasp how we spotted this weakness and crafted a clever exploit to hijack your webcam, riding on the permissions Telegram was already granted.
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
Impact
An attacker with local code execution could bypass macOS TCC privacy controls and record video from the camera using Telegram's permissions, even without root access.
What the attacker needed
Local access to the Mac; ability to run code or create files; Telegram installed from App Store
The fix
The app should be built with the Hardened Runtime and without entitlements that allow DYLD environment variable injection or disable library validation.
How it was found
- Inspect Telegram's code signature and entitlements using the codesign command to confirm it lacks the hardened flag.
- Create a dynamic library in Objective-C that captures video from the camera.
- Compile the library with gcc, linking Foundation and AVFoundation frameworks.
- Inject the library by setting the DYLD_INSERT_LIBRARIES environment variable when launching Telegram.
- Observe that Terminal, not Telegram, requests camera access, so use a LaunchAgent to run Telegram outside Terminal's sandbox.
- Create a LaunchAgent property list that sets DYLD_INSERT_LIBRARIES and runs Telegram, then load it with launchctl to record video.
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, apps need your permission to use the camera or microphone. Telegram had permission, but because it wasn't built with a security feature called Hardened Runtime, another program could sneak code into Telegram and use its permission to record you. The attacker needed to run code on your Mac first, but then could bypass the privacy prompt.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.