-
Notifications
You must be signed in to change notification settings - Fork 518
/
Copy pathpersistence_via_pluggable_authentication_module.toml
79 lines (78 loc) · 3.22 KB
/
persistence_via_pluggable_authentication_module.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
[hunt]
author = "Elastic"
description = """
This hunt identifies potential persistence mechanisms leveraging Pluggable Authentication Modules (PAM) on Linux systems. PAM is a powerful framework for managing authentication-related tasks, but its flexibility can be abused by attackers to introduce malicious modules or modify configurations to gain unauthorized access or establish persistence. This hunt monitors for modifications to PAM-related files, directories, and modules.
"""
integration = ["endpoint"]
uuid = "2a3c46b8-7bd6-4bc4-a4a8-a1af114ea152"
name = "Persistence via Pluggable Authentication Modules (PAM)"
language = ["ES|QL", "SQL"]
license = "Elastic License v2"
notes = [
"PAM modules are critical to Linux authentication workflows, but they can be abused to establish persistence or execute malicious actions.",
"This hunt identifies suspicious file creation or modification events in PAM directories, such as /etc/pam.d/, /lib/security/, and related paths.",
"Uses ES|QL queries to track file events and identify potentially malicious activity based on process activity and file paths.",
"Complemented by OSQuery queries to provide detailed file metadata for modified PAM-related files, including timestamps and ownership information."
]
mitre = ["T1556.003"]
query = [
'''
from logs-endpoint.events.file-*
| keep @timestamp, host.os.type, event.type, event.action, file.path, process.executable, agent.id
| where @timestamp > now() - 7 days
| where host.os.type == "linux" and event.action in ("rename", "creation") and (
file.path like "/lib/security/*" or
file.path like "/lib64/security/*" or
file.path like "/usr/lib64/security/*" or
file.path like "/usr/lib/x86_64-linux-gnu/security/*" or
file.path like "/lib/x86_64-linux-gnu/security/*" or
file.path like "/etc/pam.d/*" or
file.path == "/etc/pam.conf"
)
| stats cc = count(), agent_count = count_distinct(agent.id) by file.path, process.executable
| where agent_count <= 3
| sort cc asc
| limit 100
''',
'''
SELECT
f.filename,
f.path,
u.username AS file_owner,
g.groupname AS group_owner,
datetime(f.atime, 'unixepoch') AS file_last_access_time,
datetime(f.mtime, 'unixepoch') AS file_last_modified_time,
datetime(f.ctime, 'unixepoch') AS file_last_status_change_time
datetime(f.btime, 'unixepoch') AS file_created_time,
f.size AS size_bytes
FROM
file f
LEFT JOIN
users u ON f.uid = u.uid
LEFT JOIN
groups g ON f.gid = g.gid
WHERE
f.path LIKE '/lib/security/%'
OR f.path LIKE '/lib64/security/%'
OR f.path LIKE '/usr/lib/security/%'
OR f.path LIKE '/usr/lib64/security/%'
OR f.path LIKE '/usr/lib/x86_64-linux-gnu/security/%'
OR f.path LIKE '/lib/x86_64-linux-gnu/security/%'
OR f.path like '/etc/pam.d/%'
OR f.path = '/etc/pam.conf'
''',
'''
SELECT * FROM file
WHERE (
path LIKE '/lib/security/%'
OR path LIKE '/lib64/security/%'
OR path LIKE '/usr/lib/security/%'
OR path LIKE '/usr/lib64/security/%'
OR path LIKE '/usr/lib/x86_64-linux-gnu/security/%'
OR path LIKE '/lib/x86_64-linux-gnu/security/%'
OR path like '/etc/pam.d/%'
OR path = '/etc/pam.conf'
)
AND (mtime > strftime('%s', 'now') - (7 * 86400)); -- Modified in the last 7 days
'''
]