Bash_rc & Bash_profile
Analyzing .bashrc
and .bash_profile
Files for Persistence
.bashrc
and .bash_profile
Files for PersistenceAttackers often modify user-specific startup files such as .bashrc
and .bash_profile
to maintain persistence. These files are executed during shell sessions, making them ideal for embedding malicious commands that run automatically.
Key Concepts
.bashrc
: Executes commands for non-login interactive shells. Commonly used for session customizations like aliases or environment variables..bash_profile
: Executes commands for login shells. Typically sets environment variables and runs startup commands.
Incident Response Steps
1. Identify .bashrc
and .bash_profile
Files
.bashrc
and .bash_profile
FilesTo locate all relevant files on the system:
2. Analyze File Contents
Examine the contents of each file for suspicious entries.
Command:
What to Look For:
Reverse Shell Commands:
Hidden Scripts: Commands referencing unusual or hidden scripts (e.g.,
/tmp/.hidden_script
).Suspicious Aliases: Aliases overriding standard commands to execute malicious payloads.
Malicious Environment Variable Manipulations: Modifying
PATH
or other critical environment variables to execute malicious binaries.
3. Cross-Check with User Activity
Determine if malicious commands were executed and track the timeline of changes.
Check Last Modification Time:
Correlate with User Logins: Review logs to see if and when these files were executed during user sessions.
4. Review Shell Activity Logs
Analyze user shell commands to identify unauthorized or unusual behavior:
Eradication
1. Remove Malicious Entries
Edit the affected .bashrc
and .bash_profile
files to remove unauthorized commands.
Command:
2. Reset Permissions
Ensure these files have correct permissions to prevent unauthorized edits:
Command:
Verify ownership:
3. Investigate Malicious Scripts
If references to external scripts are found:
Locate the scripts:
Remove them securely:
4. Inform and Educate Users
Advise users:
To regularly review their startup files.
Avoid running unknown or unverified commands.
Key Points
.bashrc
and .bash_profile
are common persistence points for attackers. By thoroughly analyzing these files for all users, responders can uncover hidden backdoors, remove malicious commands, and secure the system against future attacks. Regular monitoring and permission enforcement are essential to maintaining system integrity.
Last updated