Keydnap
- Type
- Backdoor
- Capabilities
- Credential theftExfiltrationPersistencePrivilege escalationPost exploitationDefense evasionReconnaissance
- Delivery
- Lure
- Platforms
- macOS
Keydnap, also known as OSX/Keydnap, is a macOS credential-stealing backdoor observed in 2016. It combines a downloader with a persistent implant designed to extract passwords and cryptographic keys from the macOS keychain and maintain remote access. Its keychain-theft functionality incorporates code from the publicly available Keychaindump proof of concept, which locates keychain decryption material in the memory of the macOS security service.
Keydnap has been distributed in ZIP archives containing Mach-O executables disguised as text documents or images through misleading extensions and icons. A trailing space in the executable's name causes Finder to launch it through Terminal. The downloader retrieves and executes the backdoor, replaces itself with a decoy document, opens that document, and closes the Terminal window. In August 2016, Keydnap was also distributed through a trojanized Transmission 2.92 application hosted on Transmission's official website. The malicious application carried a valid Apple Developer ID signature that allowed it to pass Gatekeeper checks.
The backdoor establishes persistence through LaunchAgents and can display a fake administrator authentication prompt to capture credentials and obtain root privileges. When privileged, it configures executable ownership and setuid/setgid permissions to preserve elevated execution. It supports remote command and Python-script execution, additional payload download and execution, self-update, and uninstallation. It also reports system information and its privilege status to its operators.
Earlier versions communicate with Tor-hosted command-and-control infrastructure through Tor2Web proxies over HTTPS, with RC4-encrypted POST data. Version 1.5 adds a standalone Tor client and allows the command-and-control address to be changed remotely. Modified UPX packing, process-name masquerading, and decoy-file replacement help conceal the implant and its execution.
Techniques & procedures
30 distinct techniques documented for this family, organized by ATT&CK tactic.
Initial Access
3 techniques
Initial Access
OSX/Keydnap was distributed on a trusted website... via a recompiled version of the otherwise legitimate open source BitTorrent client application Transmission and distributed on their official website.
"the OSX/KeRanger authors hacked the official website for ... 'Transmission' ... infected the legitimate Transmission application"; similarly for Keydnap: "the official Transmission website ... was hacked again ... to distribute Keydnap"
It is still not clear how victims are initially exposed to OSX/Keydnap. It could be through attachments in spam messages, downloads from untrusted websites or something else.
Execution
4 techniques
Execution
Command ID Description ... 4 Decode and execute a base64-encoded Python script ... 6 Download and execute a Python script from a URL ... 7 Execute a command and report the output back to the C&C server
[Keydnap](https://attack.mitre.org/software/S0276) uses Python for scripting to execute additional commands.(Citation: synack 2016 review)
The archive file contains a Mach-O executable file with an extension that looks benign, such as .txt or .jpg. However, the file extension actually contains a space character at the end, which means double-clicking the file in Finder will launch it in Terminal and not Preview or TextEdit.
SHA-1 Filename First seen on VirusTotal Backdoor download URL Decoy description or URL ... CVdetails.doc ... "Most Common Interview Questions" ... Firefox 20 about screenshot
Persistence
2 techniques
Persistence
maintain a permanent backdoor... $HOME/Library/LaunchAgents/com.apple.iCloud.sync.daemon.plist ... $HOME/Library/LaunchAgents/com.geticloud.icloud.photo.plist
[Keydnap](https://attack.mitre.org/software/S0276) uses a Launch Agent to persist.(Citation: synack 2016 review)
Privilege Escalation
4 techniques
Privilege Escalation
It reads securityd’s memory and searches for the decryption key for the user’s keychain.
maintain a permanent backdoor... $HOME/Library/LaunchAgents/com.apple.iCloud.sync.daemon.plist ... $HOME/Library/LaunchAgents/com.geticloud.icloud.photo.plist
[Keydnap](https://attack.mitre.org/software/S0276) uses a Launch Agent to persist.(Citation: synack 2016 review)
[Keydnap](https://attack.mitre.org/software/S0276) adds the setuid flag to a binary so it can easily elevate in the future.(Citation: OSX Keydnap malware)
Stealth
7 techniques
Stealth
It is still packed with the modified UPX described in our first article about Keydnap.
parameters as POST data, encrypted with RC4
The ZIP also contains the Resource fork that contains the icon of the executable file. It mimics the icon Finder usually applies to JPEG or text files to increase the likelihood the recipient will double-click the file.
[Keydnap](https://attack.mitre.org/software/S0276) puts a space after a false .jpg extension so that execution actually goes through the Terminal.app program.(Citation: synack 2016 review)
To camouflage the location of the malicious file, Keydnap replaces argv[0] with /usr/libexec/icloudsyncd –launchd netlogon.bundle.
It reads securityd’s memory and searches for the decryption key for the user’s keychain.
[Keydnap](https://attack.mitre.org/software/S0276) uses a resource fork to present a macOS JPEG or text file icon rather than the executable's icon assigned by the operating system.(Citation: OSX Keydnap malware)
Defense Impairment
1 technique
Defense Impairment
a legitimate code signing key was used to sign the malicious Transmission application bundle... still signed by Apple and bypasses Gatekeeper protection.
Credential Access
5 techniques
Credential Access
[Keydnap](https://attack.mitre.org/software/S0276) prompts the users for credentials.(Citation: synack 2016 review)
The OSX/Keydnap backdoor is equipped with a mechanism to gather and exfiltrate passwords and keys stored in OS X’s keychain.
Keydnap: "ability to dump credentials ... from the keychain ... via code from the open-source keychaindump project"
[Keydnap](https://attack.mitre.org/software/S0276) uses the keychaindump project to read securityd memory.(Citation: synack 2016 review)
If the victim falls for this and enters their credentials, the backdoor will henceforth run as root and the content of the victim’s keychain will be exfiltrated.
Collection
1 technique
Collection
[Keydnap](https://attack.mitre.org/software/S0276) prompts the users for credentials.(Citation: synack 2016 review)
Command and Control
6 techniques
Command and Control
The RC4 key used to encrypt HTTP POST data and decrypt the response changed... The hardcoded C&C URL is now hxxp://t4f2cocitdpqa7tv.onion/api/osx
[Keydnap](https://attack.mitre.org/software/S0276) uses HTTPS for command and control.(Citation: synack 2016 review)
The FRP client can be configured to connect to the server through a proxy. The server component of SystemBC has used SOCKS5 for C2 communication. Keydnap uses a copy of tor2web proxy for HTTPS communications.
[Keydnap](https://attack.mitre.org/software/S0276) uses a copy of tor2web proxy for HTTPS communications.(Citation: synack 2016 review)
Keydnap’s downloader is simple. It will: Download and execute the backdoor component
The data field is encrypted with the RC4 key "u2RLhh+!LGd9p8!ZtuKcN" without quotes.
Exfiltration
1 technique
Exfiltration
The HTTP resource always starts with /api/osx/ and contains actions such as: /api/osx/keychain to exfiltrate the content of the keychain
Observables
34 indicators attributed across vendor reports, sandbox runs, and researcher write-ups. Values are masked here and available in full in Mallory.
Recent activity
17 sources tracked across advisories, community write-ups, and news. New activity surfaces here as Mallory finds it.