Monitoring Unauthorized Modifications to Unix Shell Configuration Files
Detection of unauthorized modifications to shell configuration files (e.g., .bashrc, .profile) used by attackers for persistence and privilege escalation on Linux systems.
This detection focuses on unauthorized access or modifications to critical Unix shell configuration files, including but not limited to .bashrc, .profile, and files within /etc/profile.d/. These files are responsible for defining the user environment and executing commands upon session initialization. Adversaries frequently target these scripts to achieve persistence, execute malicious payloads automatically when a user logs in, or escalate privileges by injecting code into scripts executed by privileged accounts.
The analytic identifies this activity by monitoring Linux Auditd logs specifically for path and current working directory events that reference shell initialization scripts. Because administrators and deployment tools also interact with these files for legitimate automation, the detection logic relies on auditd's ability to provide process and user context, allowing security teams to differentiate between authorized maintenance and malicious tampering. This monitoring is essential for uncovering "living-off-the-land" techniques where legitimate system tools are repurposed for persistent access.
Impact
Successful manipulation of shell configuration files provides attackers with a reliable, long-term foothold on compromised Linux hosts. If left undetected, this technique allows for the consistent execution of malicious code, the potential for lateral movement, and the silent exfiltration of data by capturing environment variables or intercepting user activity at every login.
Recommendation
- Enable and configure
auditdto capturePATH,CWD,SYSCALL,EXECVE, andPROCTITLEevents to provide the necessary telemetry for identifying processes modifying sensitive configuration files. - Implement the provided Auditd monitoring logic in your SIEM to flag modifications to files listed in the
matched_pathsregex, including all user-specific home directory shell profiles. - Correlate detection events with
EXECVEorPROCTITLElogs to identify the specific process or user responsible for the modification. - Establish a baseline for authorized configuration management (e.g., Ansible, Puppet) to filter out legitimate automation activities and reduce false positives.
Immediate actions
Enable auditd logging for shell configuration paths
Threat Hunt
Search for unauthorized write/append operations to /home/ directories shell profiles
Data: Auditd Path/Cwd events
Mitigations
Implement file integrity monitoring (FIM) for sensitive configuration files
T1546.004
Detection coverage 1
Detect Unauthorized Modification of Unix Shell Configuration
mediumDetects modifications to common Unix/Linux shell configuration files (e.g., .bashrc, .profile) using Linux Auditd logs.
Detection queries are available on the platform. Get full rules →