T1574.004

Dylib Hijacking

Adversaries on macOS may execute malicious payloads by placing a malicious dynamic library (dylib) in a path that a victim application searches at runtime. The macOS dynamic linker searches paths in order: @rpath (relative run-path), @loader_path, @executable_path, and standard system paths (/usr/lib, /System/Library). If an application references a dylib with a weak link (LC_LOAD_WEAK_DYLIB) and the dylib does not exist, an adversary can plant a malicious dylib with the correct name at the expected path. The Empire post-exploitation framework includes modules specifically for scanning and exploiting dylib hijacking vulnerabilities.

Microsoft Sentinel / Defender
kusto
DeviceFileEvents
| where Timestamp > ago(24h)
| where FileName endswith ".dylib"
| where FolderPath has_any ("/tmp/", "/var/folders/", "/Users/", "/Library/Application Support/")
| where ActionType in ("FileCreated", "FileModified")
| join kind=leftouter (
    DeviceProcessEvents
    | where Timestamp > ago(24h)
    | project DeviceId, ProcessId, FileName, FolderPath, AccountName
) on DeviceId, $left.InitiatingProcessId == $right.ProcessId
| project Timestamp, DeviceName, AccountName,
         DylibName=FileName, DylibPath=FolderPath,
         CreatingProcess=FileName1,
         SHA256
| sort by Timestamp desc
high severity medium confidence

Data Sources

File: File Creation File: File Modification Microsoft Defender for Endpoint (macOS)

Required Tables

DeviceFileEvents DeviceProcessEvents

False Positives

  • Software installation processes legitimately creating dylibs in Application Support or Library directories
  • Homebrew and macOS package managers creating dylibs in user-accessible paths
  • Developer builds and Xcode project compilation dropping dylibs in temp directories
  • macOS system updates temporarily staging dylibs in writable directories before installation

Unlock Pro Content

Get the full detection package for T1574.004 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections