T1546.004: Unix Shell 配置修改
摘要
攻击者可能通过执行由用户 shell 触发的恶意命令来建立持久化。用户 [Unix Shell](https://attack.mitre.org/techniques/T1059/004) 根据事件在会话的不同时间点执行若干配置脚本。例如,当用户打开命令行界面或远程登录(如通过 SSH)时,会启动一个登录 shell。登录 shell 从系统(<code>/etc</code>)和用户主目录(<code>~/</code>)执行脚本以配置环境。系统上所有登录 shell 在启动时都使用 /etc/profile。这些配置脚本以其目录的权限级别运行,通常用于设置环境变量、创建别名以及自定义用户环境。当 shell 退出或终止时,会执行额外的 shell 脚本以确保 shell 正确退出。 攻击者可能试图通过将命令插入到由 shell 自动执行的脚本中来建立持久化。以大多数 GNU/Linux 系统的默认 shell bash 为例,攻击者可能将启动恶意二进制文件的命令添加到 <code>/etc/profile</code> 和 <code>/etc/profile.d</code> 文件中。(Citation: intezer-kaiji-malware)(Citation: bencane blog bashrc) 这些文件通常需要 root 权限才能修改,并且系统上每次启动任何 shell 时都会执行。对于用户级权限,攻击者可以将恶意命令插入 <code>~/.bash_profile</code>、<code>~/.bash_login</code> 或 <code>~/.profile</code>,这些文件在用户打开命令行界面或远程连接时被加载。(Citation: anomali-rocke-tactics)(Citation: Linux manual bash invocation) 由于系统只按所列顺序执行第一个存在的文件,攻击者已使用 <code>~/.bash_profile</code> 来确保执行。攻击者还利用了 <code>~/.bashrc</code> 文件,如果连接是远程建立的或打开了额外的交互式 shell(如命令行界面中的新选项卡),该文件也会被额外执行。(Citation: Tsunami)(Citation: anomali-rocke-tactics)(Citation: anomali-linux-rabbit)(Citation: Magento) 一些恶意软件以程序终止为触发执行的目标,攻击者可以使用 <code>~/.bash_logout</code> 文件在会话结束时执行恶意命令。 对于 macOS,此技术的功能类似,但可能利用 zsh,即 macOS 10.15+ 的默认 shell。当打开 Terminal.app 时,应用程序启动一个 zsh 登录 shell 和一个 zsh 交互式 shell。登录 shell 使用 <code>/etc/profile</code>、<code>/etc/zshenv</code>、<code>/etc/zprofile</code> 和 <code>/etc/zlogin</code> 配置系统环境。(Citation: ScriptingOSX zsh)(Citation: PersistentJXA_leopitt)(Citation: code_persistence_zsh)(Citation: macOS MS office sandbox escape) 登录 shell 随后使用 <code>~/.zprofile</code> 和 <code>~/.zlogin</code> 配置用户环境。交互式 shell 使用 <code>~/.zshrc</code> 配置用户环境。退出时,会执行 <code>/etc/zlogout</code> 和 <code>~/.zlogout</code>。对于旧版程序,macOS 在启动时执行 <code>/etc/bashrc</code>。
来源归属
来源:MITRE ATT&CK · 置信度:high
平台
- Linux
- macOS
战术
权限提升
参考来源
- https://attack.mitre.org/techniques/T1546/004
- https://www.anomali.com/blog/pulling-linux-rabbit-rabbot-malware-out-of-a-hat
- https://www.anomali.com/blog/illicit-cryptomining-threat-actor-rocke-changes-tactics-now-more-difficult-to-detect
- https://wiki.archlinux.org/index.php/Bash#Invocation
- https://scriptingosx.com/2019/06/moving-to-zsh-part-2-configuration-files/
- https://web.archive.org/web/20220316014323/http://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/
- https://cedowens.medium.com/macos-ms-office-sandbox-brain-dump-4509b5fed49a
- https://blog.sucuri.net/2018/05/shell-logins-as-a-magento-reinfection-vector.html
- https://unit42.paloaltonetworks.com/unit42-new-iotlinux-malware-targets-dvrs-forms-botnet/
- https://posts.specterops.io/persistent-jxa-66e1c3cd1cf5
- https://github.com/D00MFist/PersistentJXA/blob/master/BashProfilePersist.js
- https://objective-see.com/blog/blog_0x48.html
- https://www.intezer.com/blog/research/kaiji-new-chinese-linux-malware-turning-to-golang/