T1546.004

Unix Shell Configuration Modification

Adversaries may establish persistence through executing malicious commands triggered by a user's shell. User Unix shells execute several configuration scripts whenever a shell session is opened. Malicious content can be inserted into these shell configuration files — such as ~/.bashrc, ~/.bash_profile, ~/.bash_login, ~/.profile, /etc/profile, /etc/bashrc, ~/.zshrc, and ~/.zprofile — to execute adversary payloads when a user opens a terminal or logs in. The payload will execute in the user's context each time the shell is started.

Microsoft Sentinel / Defender
kusto
let ShellConfigPaths = dynamic([
    ".bashrc", ".bash_profile", ".bash_login", ".profile",
    ".zshrc", ".zprofile", ".zshenv", ".zlogin",
    ".tcshrc", ".cshrc",
    "profile", "bashrc", "bash.bashrc",
    ".config/fish/config.fish"
  ]);
DeviceFileEvents
| where Timestamp > ago(24h)
| where FileName has_any (ShellConfigPaths)
  or FolderPath has_any ("/etc/profile.d/", "/etc/bash_completion.d/")
| where ActionType in ("FileCreated", "FileModified")
| extend IsEtcFile = FolderPath startswith "/etc/"
| extend IsUserProfile = FolderPath has_any ("/home/", "/root/", "Users")
| project Timestamp, DeviceName, AccountName, ActionType, FileName, FolderPath,
         IsEtcFile, IsUserProfile,
         InitiatingProcessFileName, InitiatingProcessCommandLine
| sort by Timestamp desc
medium severity medium confidence

Data Sources

File: File Creation File: File Modification Microsoft Defender for Endpoint

Required Tables

DeviceFileEvents

False Positives

  • Package managers (apt, yum, dnf, brew) that modify /etc/profile.d/ or /etc/bashrc when installing packages that add environment variables or aliases
  • Configuration management tools (Ansible, Chef, Puppet, Salt) that manage shell configuration files as part of system baseline enforcement
  • Users legitimately modifying their own .bashrc or .zshrc to add aliases, set PATH, or configure their prompt
  • Developer toolchains (rbenv, pyenv, nvm, sdkman) that append initialization code to shell config files during installation

Unlock Pro Content

Get the full detection package for T1546.004 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections