MITRE ATT&CKsub-technique
T1546.004 Unix Shell Configuration Modification
- Domain
- enterprise
- Tactics
- Privilege Escalation, Persistence
- Platforms
- Linux, macOS
- Version
- 2.2
- Created
- 2020-01-24
Description
Adversaries may establish persistence through executing malicious commands triggered by a user’s shell. User Unix Shells execute several configuration scripts at different points throughout the session based on events. For example, when a user opens a command-line interface or remotely logs in (such as via SSH) a login shell is initiated. The login shell executes scripts from the system (/etc) and the user’s home directory (~/) to configure the environment. All login shells on a system use /etc/profile when initiated. These configuration scripts run at the permission level of their directory and are often used to set environment variables, create aliases, and customize the user’s environment. When the shell exits or terminates, additional shell scripts are executed to ensure the shell exits appropriately.
Adversaries may attempt to establish persistence by inserting commands into scripts automatically executed by shells. Using bash as an example, the default shell for most GNU/Linux systems, adversaries may add commands that launch malicious binaries into the /etc/profile and /etc/profile.d files. These files typically require root permissions to modify and are executed each time any shell on a system launches. For user level permissions, adversaries can insert malicious commands into ~/.bash_profile, ~/.bash_login, or ~/.profile which are sourced when a user opens a command-line interface or connects remotely. Since the system only executes the first existing file in the listed order, adversaries have used ~/.bash_profile to ensure execution. Adversaries have also leveraged the ~/.bashrc file which is additionally executed if the connection is established remotely or an additional interactive shell is opened, such as a new tab in the command-line interface. Some malware targets the termination of a program to trigger execution, adversaries can use the ~/.bash_logout file to execute malicious commands at the end of a session.
For macOS, the functionality of this technique is similar but may leverage zsh, the default shell for macOS 10.15+. When the Terminal.app is opened, the application launches a zsh login shell and a zsh interactive shell. The login shell configures the system environment using /etc/profile, /etc/zshenv, /etc/zprofile, and /etc/zlogin. The login shell then configures the user environment with ~/.zprofile and ~/.zlogin. The interactive shell uses the ~/.zshrc to configure the user environment. Upon exiting, /etc/zlogout and ~/.zlogout are executed. For legacy programs, macOS executes /etc/bashrc on startup.
Related
Subtechnique of · MITRE ATT&CK (1)
- T1546 Event Triggered Execution technique
Referenced by MITRE ATT&CK · mitigates (1)
- M1022 Restrict File and Directory Permissions mitigation
Referenced by MITRE ATT&CK · uses (7)
Referenced by CAPEC · att&ck technique (1)
- CAPEC-19 Embedding Scripts within Scripts attack pattern
Referenced by Compliance · mitigates (8)
- NIST-AC-3 Access Enforcement NIST 800-53 control
- NIST-AC-6 Least Privilege NIST 800-53 control
- NIST-CA-7 Continuous Monitoring NIST 800-53 control
- NIST-CM-2 Baseline Configuration NIST 800-53 control
- NIST-CM-6 Configuration Settings NIST 800-53 control
- NIST-SI-3 Malicious Code Protection NIST 800-53 control
- NIST-SI-4 System Monitoring NIST 800-53 control
- NIST-SI-7 Software, Firmware, and Information Integrity NIST 800-53 control
References
- https://www.anomali.com/blog/pulling-linux-rabbit-rabbot-malware-out-of-a-hat anomali-linux-rabbit
- https://www.anomali.com/blog/illicit-cryptomining-threat-actor-rocke-changes-tactics-now-more-difficult-to-detect anomali-rocke-tactics
- https://wiki.archlinux.org/index.php/Bash#Invocation Linux manual bash invocation
- https://scriptingosx.com/2019/06/moving-to-zsh-part-2-configuration-files/ ScriptingOSX zsh
- https://web.archive.org/web/20220316014323/http://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/ bencane blog bashrc
- https://cedowens.medium.com/macos-ms-office-sandbox-brain-dump-4509b5fed49a macOS MS office sandbox escape
- https://blog.sucuri.net/2018/05/shell-logins-as-a-magento-reinfection-vector.html Magento
- https://unit42.paloaltonetworks.com/unit42-new-iotlinux-malware-targets-dvrs-forms-botnet/ Tsunami
- https://posts.specterops.io/persistent-jxa-66e1c3cd1cf5 PersistentJXA_leopitt
- https://github.com/D00MFist/PersistentJXA/blob/master/BashProfilePersist.js code_persistence_zsh
- https://objective-see.com/blog/blog_0x48.html ESF_filemonitor
- https://www.intezer.com/blog/research/kaiji-new-chinese-linux-malware-turning-to-golang/ intezer-kaiji-malware