This hunt identifies potential persistence mechanisms via modifications to shell profile files on Linux systems. It monitors file creation or modification events in system-wide and user-specific profile files, which can indicate attempts to establish persistence through shell modifications. It also monitors processes started by SSH daemons to detect suspicious activity related to SSH logins.
"""
integration=["endpoint"]
uuid="20a02fad-2a09-44c0-a8ce-ce4502859c8a"
name="Shell Modification Persistence"
language=["ES|QL","SQL"]
license="Elastic License v2"
notes=[
"Monitors for file creation or modification events in system-wide and user-specific profile files, such as /etc/profile, /etc/bash.bashrc, /home/*/.bashrc, and others.",
"Excludes modifications made by expected update processes such as package managers to reduce false positives.",
"Uses EVAL to tag potential persistence events and counts occurrences to identify unusual activity.",
"Monitors processes started by SSH daemons (sshd) to detect suspicious activity related to SSH logins.",
"OSQuery query is provided to retrieve detailed file information related to profile files."
]
mitre=["T1546.004","T1053.005"]
query=[
'''
from logs-endpoint.events.file-*
| where @timestamp > now() - 30 day
| where host.os.type == "linux" and event.type in ("creation", "change") and (
// System-wide profile files
file.path in ("/etc/profile", "/etc/bash.bashrc", "/etc/bash.bash_logout") or