|
| 1 | +# Persistence via NetworkManager Dispatcher Script |
| 2 | + |
| 3 | +--- |
| 4 | + |
| 5 | +## Metadata |
| 6 | + |
| 7 | +- **Author:** Elastic |
| 8 | +- **Description:** This hunt identifies potential persistence mechanisms leveraging NetworkManager Dispatcher scripts on Linux systems. NetworkManager Dispatcher scripts are executed automatically when the network state changes, making them an interesting target for attackers seeking to persist or execute malicious actions during network transitions. This hunt monitors suspicious activity involving the creation or modification of dispatcher scripts, tracks processes spawned by `nm-dispatcher` or scripts in `/etc/NetworkManager/dispatcher.d/`, and retrieves metadata for files in these directories for deeper analysis. The approach enables analysts to identify and respond to NetworkManager dispatcher script persistence techniques. |
| 9 | + |
| 10 | +- **UUID:** `8f3bf096-2f3b-4d38-9925-0eb120323da3` |
| 11 | +- **Integration:** [endpoint](https://docs.elastic.co/integrations/endpoint) |
| 12 | +- **Language:** `[ES|QL, SQL]` |
| 13 | +- **Source File:** [Persistence via NetworkManager Dispatcher Script](../queries/persistence_via_network_manager_dispatcher_script.toml) |
| 14 | + |
| 15 | +## Query |
| 16 | + |
| 17 | +```sql |
| 18 | +sql |
| 19 | +from logs-endpoint.events.process-* |
| 20 | +| keep @timestamp, host.os.type, event.type, event.action, process.parent.executable, process.parent.name, process.command_line, process.executable, agent.id |
| 21 | +| where @timestamp > now() - 30 day |
| 22 | +| where host.os.type == "linux" and event.type == "start" and event.action == "exec" and ( |
| 23 | + process.parent.executable like "/etc/NetworkManager/dispatcher.d/*" or process.parent.name == "nm-dispatcher" |
| 24 | +) |
| 25 | +| stats cc = count(), agent_count = count_distinct(agent.id) by process.command_line, process.executable, process.parent.executable |
| 26 | +| where agent_count <= 3 and cc < 15 |
| 27 | +| sort cc asc |
| 28 | +| limit 100 |
| 29 | +``` |
| 30 | + |
| 31 | +```sql |
| 32 | +sql |
| 33 | +from logs-endpoint.events.file-* |
| 34 | +| keep @timestamp, host.os.type, event.type, event.action, file.path, file.extension, process.name, process.executable, agent.id |
| 35 | +| where @timestamp > now() - 30 day |
| 36 | +| where host.os.type == "linux" and event.type in ("creation", "change") and file.path like "/etc/NetworkManager/dispatcher.d/*" |
| 37 | + and not ( |
| 38 | + file.extension in ("swp", "dpkg-new") or |
| 39 | + process.name in ("dnf", "yum", "dpkg") |
| 40 | +) |
| 41 | +| stats cc = count(), agent_count = count_distinct(agent.id) by file.path, process.executable |
| 42 | +| where agent_count <= 3 |
| 43 | +| sort cc asc |
| 44 | +| limit 100 |
| 45 | +``` |
| 46 | + |
| 47 | +```sql |
| 48 | +sql |
| 49 | +SELECT |
| 50 | + f.filename, |
| 51 | + f.path, |
| 52 | + u.username AS file_owner, |
| 53 | + g.groupname AS group_owner, |
| 54 | + datetime(f.atime, 'unixepoch') AS file_last_access_time, |
| 55 | + datetime(f.mtime, 'unixepoch') AS file_last_modified_time, |
| 56 | + datetime(f.ctime, 'unixepoch') AS file_last_status_change_time, |
| 57 | + datetime(f.btime, 'unixepoch') AS file_created_time, |
| 58 | + f.size AS size_bytes |
| 59 | +FROM |
| 60 | + file f |
| 61 | +LEFT JOIN |
| 62 | + users u ON f.uid = u.uid |
| 63 | +LEFT JOIN |
| 64 | + groups g ON f.gid = g.gid |
| 65 | +WHERE f.path LIKE '/etc/NetworkManager/dispatcher.d/%' |
| 66 | +AND (mtime > strftime('%s', 'now') - (7 * 86400)); -- Modified in the last 7 days |
| 67 | +``` |
| 68 | + |
| 69 | +## Notes |
| 70 | + |
| 71 | +- Monitors processes executed by `nm-dispatcher` or scripts located in `/etc/NetworkManager/dispatcher.d/`, identifying unauthorized or anomalous executions. |
| 72 | +- Tracks file creations and modifications within the `/etc/NetworkManager/dispatcher.d/` directory to detect potential tampering or malicious additions. |
| 73 | +- Retrieves metadata for NetworkManager Dispatcher scripts, including ownership, access times, and modification timestamps, to highlight unauthorized changes or suspicious file attributes. |
| 74 | +- Focuses on recent changes to dispatcher scripts within the last 7 days to ensure timely detection of potential persistence mechanisms. |
| 75 | + |
| 76 | +## MITRE ATT&CK Techniques |
| 77 | + |
| 78 | +- [T1546](https://attack.mitre.org/techniques/T1546) |
| 79 | + |
| 80 | +## License |
| 81 | + |
| 82 | +- `Elastic License v2` |
0 commit comments