|
| 1 | +# Persistence via Pluggable Authentication Modules |
| 2 | + |
| 3 | +--- |
| 4 | + |
| 5 | +## Metadata |
| 6 | + |
| 7 | +- **Author:** Elastic |
| 8 | +- **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. |
| 9 | + |
| 10 | +- **UUID:** `2a3c46b8-7bd6-4bc4-a4a8-a1af114ea152` |
| 11 | +- **Integration:** [endpoint](https://docs.elastic.co/integrations/endpoint) |
| 12 | +- **Language:** `[ES|QL, SQL]` |
| 13 | +- **Source File:** [Persistence via Pluggable Authentication Modules](../queries/persistence_via_pluggable_authentication_module.toml) |
| 14 | + |
| 15 | +## Query |
| 16 | + |
| 17 | +```sql |
| 18 | +from logs-endpoint.events.file-* |
| 19 | +| where @timestamp > now() - 7 days |
| 20 | +| where host.os.type == "linux" and event.action in ("rename", "creation") and ( |
| 21 | + file.path like "/lib/security/*" or |
| 22 | + file.path like "/lib64/security/*" or |
| 23 | + file.path like "/usr/lib64/security/*" or |
| 24 | + file.path like "/usr/lib/x86_64-linux-gnu/security/*" or |
| 25 | + file.path like "/lib/x86_64-linux-gnu/security/*" or |
| 26 | + file.path like "/etc/pam.d/*" or |
| 27 | + file.path == "/etc/pam.conf" |
| 28 | +) |
| 29 | +| stats cc = count(), agent_count = count_distinct(agent.id) by file.path, process.executable |
| 30 | +| where agent_count <= 3 |
| 31 | +| sort cc asc |
| 32 | +| limit 100 |
| 33 | +``` |
| 34 | + |
| 35 | +```sql |
| 36 | +SELECT |
| 37 | + f.filename, |
| 38 | + f.path, |
| 39 | + u.username AS file_owner, |
| 40 | + g.groupname AS group_owner, |
| 41 | + datetime(f.atime, 'unixepoch') AS file_last_access_time, |
| 42 | + datetime(f.mtime, 'unixepoch') AS file_last_modified_time, |
| 43 | + datetime(f.ctime, 'unixepoch') AS file_last_status_change_time |
| 44 | + datetime(f.btime, 'unixepoch') AS file_created_time, |
| 45 | + f.size AS size_bytes |
| 46 | +FROM |
| 47 | + file f |
| 48 | +LEFT JOIN |
| 49 | + users u ON f.uid = u.uid |
| 50 | +LEFT JOIN |
| 51 | + groups g ON f.gid = g.gid |
| 52 | +WHERE |
| 53 | + f.path LIKE '/lib/security/%' |
| 54 | + OR f.path LIKE '/lib64/security/%' |
| 55 | + OR f.path LIKE '/usr/lib/security/%' |
| 56 | + OR f.path LIKE '/usr/lib64/security/%' |
| 57 | + OR f.path LIKE '/usr/lib/x86_64-linux-gnu/security/%' |
| 58 | + OR f.path LIKE '/lib/x86_64-linux-gnu/security/%' |
| 59 | + OR f.path like '/etc/pam.d/%' |
| 60 | + OR f.path = '/etc/pam.conf' |
| 61 | +``` |
| 62 | + |
| 63 | +```sql |
| 64 | +SELECT * FROM file |
| 65 | +WHERE ( |
| 66 | + path LIKE '/lib/security/%' |
| 67 | + OR path LIKE '/lib64/security/%' |
| 68 | + OR path LIKE '/usr/lib/security/%' |
| 69 | + OR path LIKE '/usr/lib64/security/%' |
| 70 | + OR path LIKE '/usr/lib/x86_64-linux-gnu/security/%' |
| 71 | + OR path LIKE '/lib/x86_64-linux-gnu/security/%' |
| 72 | + OR path like '/etc/pam.d/%' |
| 73 | + OR path = '/etc/pam.conf' |
| 74 | + ) |
| 75 | +AND (mtime > strftime('%s', 'now') - (7 * 86400)); -- Modified in the last 7 days |
| 76 | +``` |
| 77 | + |
| 78 | +## Notes |
| 79 | + |
| 80 | +- PAM modules are critical to Linux authentication workflows, but they can be abused to establish persistence or execute malicious actions. |
| 81 | +- This hunt identifies suspicious file creation or modification events in PAM directories, such as /etc/pam.d/, /lib/security/, and related paths. |
| 82 | +- Uses ES|QL queries to track file events and identify potentially malicious activity based on process activity and file paths. |
| 83 | +- Complemented by OSQuery queries to provide detailed file metadata for modified PAM-related files, including timestamps and ownership information. |
| 84 | +- The hunt focuses on minimizing false positives by excluding common legitimate processes while tagging unusual activity. |
| 85 | +- MITRE ATT&CK Technique T1556.003 (Modify Authentication Process: Pluggable Authentication Modules) is addressed in this hunt. |
| 86 | + |
| 87 | +## MITRE ATT&CK Techniques |
| 88 | + |
| 89 | +- [T1556.003](https://attack.mitre.org/techniques/T1556/003) |
| 90 | + |
| 91 | +## License |
| 92 | + |
| 93 | +- `Elastic License v2` |
0 commit comments