T1574.004 Dylib Hijacking
Sub-technique of: T1574
High-Level Description
Adversaries may execute their own payloads by placing a malicious dynamic library (dylib) with an expected name in a path a victim application searches at runtime. The dynamic loader will try to find the dylibs based on the sequential order of the search paths. Paths to dylibs may be prefixed with @rpath, which allows developers to use relative paths to specify an array of search paths used at runtime based on the location of the executable. Additionally, if weak linking is used, such as the LC_LOAD_WEAK_DYLIB function, an application will still execute even if an expected dylib is not present. Weak linking enables developers to run an application on multiple macOS versions as new APIs are added.
Adversaries may gain execution by inserting malicious dylibs with the name of the missing dylib in the identified path. Dylibs are loaded into an application's address space allowing the malicious dylib to inherit the application's privilege level and resources. Based on the application, this could result in privilege escalation and uninhibited network access. This method may also evade detection from security products since the execution is masked under a legitimate process.
Kill Chain Phase
- Persistence (TA0003)
- Privilege Escalation (TA0004)
- Defense Evasion (TA0005)
Platforms: macOS
What to Check
- Identify if Dylib Hijacking technique is applicable to target environment
- Check macOS systems for indicators of Dylib Hijacking
- Verify mitigations are bypassed or absent (1 known mitigations)
- Assess detection coverage (1 detection strategies)
How to Test
Manual Testing
Identify Attack Surface: Determine if the target environment is susceptible to Dylib Hijacking by examining the target platforms (macOS).
Assess Existing Defenses: Review whether mitigations for T1574.004 are in place. If defenses are absent or misconfigured, this technique may be exploitable.
Execute Test: Use tools and methods described in the MITRE ATT&CK page and external references below.
Note: No Atomic Red Team tests available for this technique. See Atomic Red Team GitHub for updates.
Remediation Guide
M1022 Restrict File and Directory Permissions
Set directory access controls to prevent file writes to the search paths for applications, both in the folders where applications are run from and the standard dylib folders.
Detection
Detection Strategy for Hijack Execution Flow: Dylib Hijacking
Risk Assessment
| Finding | Severity | Impact |
|---|---|---|
| Dylib Hijacking technique applicable | High | Persistence |
CWE Categories
| CWE ID | Title |
|---|---|
| CWE-276 | Incorrect Default Permissions |
References
- MalwareUnicorn macOS Dylib Injection MachO
- Apple Developer Doco Archive Run-Path
- Wardle Dylib Hijacking OSX 2015
- Writing Bad Malware for OSX
- Wardle Dylib Hijack Vulnerable Apps
- wardle artofmalware volume1
- Github EmpireProject HijackScanner
- Github EmpireProject CreateHijacker Dylib
- Atomic Red Team - T1574.004
- MITRE ATT&CK - T1574.004