Skip to content

Commit b13d6bf

Browse files
authored
[New Hunt] Persistence via NetworkManager Dispatcher Script (#4408)
1 parent be54140 commit b13d6bf

4 files changed

+153
-0
lines changed

hunting/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Here are the queries currently available:
5050
- [Persistence via Initramfs](./linux/docs/persistence_via_initramfs.md) (ES|QL)
5151
- [Persistence via Loadable Kernel Modules](./linux/docs/persistence_via_loadable_kernel_modules.md) (ES|QL)
5252
- [Persistence via Message-of-the-Day](./linux/docs/persistence_via_message_of_the_day.md) (ES|QL)
53+
- [Persistence via NetworkManager Dispatcher Script](./linux/docs/persistence_via_network_manager_dispatcher_script.md) (ES|QL)
5354
- [Persistence via Package Manager](./linux/docs/persistence_via_package_manager.md) (ES|QL)
5455
- [Persistence via Pluggable Authentication Modules (PAM)](./linux/docs/persistence_via_pluggable_authentication_module.md) (ES|QL)
5556
- [Persistence via PolicyKit](./linux/docs/persistence_via_policykit.md) (ES|QL)

hunting/index.yml

+5
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ linux:
250250
path: ./linux/queries/persistence_via_malicious_docker_container.toml
251251
mitre:
252252
- T1610
253+
8f3bf096-2f3b-4d38-9925-0eb120323da3:
254+
name: Persistence via NetworkManager Dispatcher Script
255+
path: ./linux/queries/persistence_via_network_manager_dispatcher_script.toml
256+
mitre:
257+
- T1546
253258
2223bbda-b931-4f33-aeb4-0e0732a370dd:
254259
name: Persistence via Desktop Bus (D-Bus)
255260
path: ./linux/queries/persistence_via_desktop_bus.toml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[hunt]
2+
author = "Elastic"
3+
description = """
4+
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.
5+
"""
6+
integration = ["endpoint"]
7+
uuid = "8f3bf096-2f3b-4d38-9925-0eb120323da3"
8+
name = "Persistence via NetworkManager Dispatcher Script"
9+
language = ["ES|QL", "SQL"]
10+
license = "Elastic License v2"
11+
notes = [
12+
"Monitors processes executed by `nm-dispatcher` or scripts located in `/etc/NetworkManager/dispatcher.d/`, identifying unauthorized or anomalous executions.",
13+
"Tracks file creations and modifications within the `/etc/NetworkManager/dispatcher.d/` directory to detect potential tampering or malicious additions.",
14+
"Retrieves metadata for NetworkManager Dispatcher scripts, including ownership, access times, and modification timestamps, to highlight unauthorized changes or suspicious file attributes.",
15+
"Focuses on recent changes to dispatcher scripts within the last 7 days to ensure timely detection of potential persistence mechanisms."
16+
]
17+
mitre = ["T1546"]
18+
query = [
19+
'''sql
20+
from logs-endpoint.events.process-*
21+
| keep @timestamp, host.os.type, event.type, event.action, process.parent.executable, process.parent.name, process.command_line, process.executable, agent.id
22+
| where @timestamp > now() - 30 day
23+
| where host.os.type == "linux" and event.type == "start" and event.action == "exec" and (
24+
process.parent.executable like "/etc/NetworkManager/dispatcher.d/*" or process.parent.name == "nm-dispatcher"
25+
)
26+
| stats cc = count(), agent_count = count_distinct(agent.id) by process.command_line, process.executable, process.parent.executable
27+
| where agent_count <= 3 and cc < 15
28+
| sort cc asc
29+
| limit 100
30+
''',
31+
'''sql
32+
from logs-endpoint.events.file-*
33+
| keep @timestamp, host.os.type, event.type, event.action, file.path, file.extension, process.name, process.executable, agent.id
34+
| where @timestamp > now() - 30 day
35+
| where host.os.type == "linux" and event.type in ("creation", "change") and file.path like "/etc/NetworkManager/dispatcher.d/*"
36+
and not (
37+
file.extension in ("swp", "dpkg-new") or
38+
process.name in ("dnf", "yum", "dpkg")
39+
)
40+
| stats cc = count(), agent_count = count_distinct(agent.id) by file.path, process.executable
41+
| where agent_count <= 3
42+
| sort cc asc
43+
| limit 100
44+
''',
45+
'''sql
46+
SELECT
47+
f.filename,
48+
f.path,
49+
u.username AS file_owner,
50+
g.groupname AS group_owner,
51+
datetime(f.atime, 'unixepoch') AS file_last_access_time,
52+
datetime(f.mtime, 'unixepoch') AS file_last_modified_time,
53+
datetime(f.ctime, 'unixepoch') AS file_last_status_change_time,
54+
datetime(f.btime, 'unixepoch') AS file_created_time,
55+
f.size AS size_bytes
56+
FROM
57+
file f
58+
LEFT JOIN
59+
users u ON f.uid = u.uid
60+
LEFT JOIN
61+
groups g ON f.gid = g.gid
62+
WHERE f.path LIKE '/etc/NetworkManager/dispatcher.d/%'
63+
AND (mtime > strftime('%s', 'now') - (7 * 86400)); -- Modified in the last 7 days
64+
'''
65+
]

0 commit comments

Comments
 (0)