Per Apple’s developer documentation, when macOS and OS X boot up, launchd is run to finish system initialization. This process loads the parameters for each launch-on-demand system-level daemon from the property list (plist) files found in /System/Library/LaunchDaemons and /Library/LaunchDaemons (Citation: AppleDocs Launch Agent Daemons). These LaunchDaemons have property list files which point to the executables that will be launched (Citation: Methods of Mac Malware Persistence).
Adversaries may install a new launch daemon that can be configured to execute at startup by using launchd or launchctl to load a plist into the appropriate directories (Citation: OSX Malware Detection). The daemon name may be disguised by using a name from a related operating system or benign software (Citation: WireLurker). Launch Daemons may be created with administrator privileges, but are executed under root privileges, so an adversary may also use a service to escalate privileges from administrator to root.
The plist file permissions must be root:wheel, but the script or program that it points to has no such requirement. So, it is possible for poor configurations to allow an adversary to modify a current Launch Daemon’s executable and gain persistence or Privilege Escalation.
T1160は「Launch Daemon(ローンチデーモン)」として定義されていた、macOS環境における極めて強力な自動実行・特権昇格手法です。
T1159「Launch Agent」と対になる仕組みですが、Launch Daemonは「OSの起動直後に、ユーザーのログインに関係なく root(最高権限)で自動実行される」という、より強力で危険な性質を持っています。
この手法で攻撃者は、「Macの電源が入った瞬間から、OSの最高権限(root)で動作し続ける、文字通りの『完全なバックドア』」を実現します。
最高権限(root)での動作:
起動するマルウェアが最初からシステム最高権限(root)を持つため、カーネルレベルの操作や、システム全体のデータ窃取、セキュリティプロセスの強制終了などが容易に行えます。
ログイン不要の永続化:
誰もMacにサインインしていない「起動直後のログイン画面」の状態であっても、裏で自動的にC2サーバーへ接続(ビーコニング)を開始させることができます。
macOSのサービス管理フレームワーク launchd が読み込むファイルですが、配置場所と権限が異なります。
| 項目 | Launch Agent (T1159) | Launch Daemon (T1160) |
|---|---|---|
| 実行タイミング | ユーザーがログインした直後 | OSが起動した直後(ログイン前) |
| 実行権限 | ログインしたユーザーの権限 | システムのroot権限(最高権限) |
| 配置フォルダ | `~/Library/LaunchAgents/` など | `/Library/LaunchDaemons/` |
| 必要な設置権限 | 一般ユーザー権限で作成可能 | 管理者権限(sudo / root)が必要 |
Launch Daemonを登録するためには、攻撃者は事前にシステム内での管理者権限(Administrator権限またはsudo権限)を確保している必要があります。
マルウェアの配置:
攻撃者は永続化させたい不正なバイナリ(RATなど)を、システムフォルダ内(例: /usr/local/bin/ などの目立たない場所)に配置します。
悪意あるPlistの作成と配置:
管理者権限(sudo)を悪用して、以下のデーモン専用フォルダに新しい .plist(プロパティリスト)ファイルを作成して設置します。
/Library/LaunchDaemons/.plist 内には、以下のようなバックドアの永続化設定を書き込みます。
* `RunAtLoad`: `true`(起動時に自動実行)
* `KeepAlive`: `true`(プロセスが落とされたらOSが自動で再起動する)
* `ProgramArguments`: (手順1で置いたマルウェアのパスを指定)
launchctl load /Library/LaunchDaemons/bad.plist コマンドを使って、再起動を待たずにその場でroot権限のマルウェアを強制起動させるか、次回のシステム再起動を待ちます。最高権限の永続化ポイントであるため、厳重な監視が必要です。
LaunchDaemonsフォルダの整合性監視(最重要):
/Library/LaunchDaemons/ の配下に新しい .plist ファイルが作成されたり、既存のファイルが変更されたりする挙動を、EDRやmacOSの「Endpoint Security Framework (ESF)」で常時監視し、即座にアラートを上げます。通常、新しいソフトウェアのインストール時以外でここにファイルが増えることはありません。
root権限によるlaunchctlコマンドの監視:
root または sudo 経由で launchctl load や launchctl bootstrap コマンドが不審なパスのplistを指定して実行されていないかをコマンドラインログで監視します。
システム通知の確認:
モダンなmacOSでは、新しいLaunch Daemonが登録されると、画面に「バックグラウンド項目が追加されました」と通知されます。管理者が意図していない通知があった場合は即座にトリアージを行います。
CWE-15: External Control of System or Configuration Setting:
システムの永続化設定(Launch Daemonのリスト)を外部から不正に変更されてしまう不備。
CWE-250: Execution with Unnecessary Privileges:
必要以上の高い権限(root)でプログラムを実行できてしまう設計・管理上の不備。
Macを標的にする高度なAPTグループが、最終的な「絶対的な足場」として利用します。
Lazarus Group (北朝鮮政府系):
Macユーザーを狙った標的型攻撃(偽の暗号資産アプリや偽の求人ファイルを送りつける手口)において、一般ユーザー権限で侵入した後に巧妙に管理者権限へと昇格し、最終的に /Library/LaunchDaemons/ に独自のplist(T1160 / T1543.004)を書き込んで、システムの完全な支配権を長期維持する手法が何度も確認されています。
XCSSET:
開発者のXcodeプロジェクトを汚染して感染を広げるマルウェア。感染したMac上で権限を昇格させ、Launch Daemonを利用して自身の隠しC2通信モジュールをroot権限で常時起動させていました。
Launch Daemonによる永続化は、KeepAlive 設定が有効になっていることが多く、「タスクマネージャー(アクティビティモニタ)で怪しいプロセスを見つけて強制終了しても、1秒後にOSが親切にroot権限で再起動してくる」というゾンビのような挙動を示します。
対処する際は、プロセスを殺す前にまずターミナルで sudo launchctl unload /Library/LaunchDaemons/[怪しいファイル].plist を実行してOSの自動起動設定を解除し、その後に対象の .plist ファイルと実行可能バイナリを削除する必要があります。