Cron Job
Cron Job Analysis in Incident Response (Linux Systems)
Cron jobs are a key component of Linux systems for automating tasks, but they can be exploited by attackers to establish persistence. Here's a comprehensive guide to analyzing, detecting, and eradicating malicious cron jobs during an incident response.
Understanding Cron and Crontab
Cron: The daemon that executes scheduled tasks.
Cron Job: A scheduled task defined in a crontab file.
Crontab: A configuration file that specifies cron jobs.
Crontab File Structure
Each crontab entry has the following format:
Examples:
Every 5 minutes:
*/5 * * * * /root/check_system.sh
Daily at 2 AM:
0 2 * * * /usr/local/bin/backup.sh
Every Monday at 10 AM:
0 10 * * 1 /usr/bin/cleanup.sh
Incident Response Steps
1. List All Cron Jobs
System-Wide Cron Jobs
System-wide cron jobs are configured for the entire system:
Cron Jobs in Drop-In Directories
Cron jobs may be defined in:
User-Specific Cron Jobs
Each user’s crontab can be found in:
Or:
To list the current user’s cron jobs:
To list another user's cron jobs:
2. Analyze Historical Cron Job Data
Attackers may delete cron jobs after execution. Logs provide valuable insights.
Using Syslog
Example Output:
Using Journalctl
For a specific timeframe:
3. Analyze Cron Jobs
Focus on these indicators:
Execution Timing: Frequent or odd execution times (e.g., every minute).
Commands/Scripts:
Scripts or binaries running from unusual locations like
/tmp
,/dev/shm
, or/var/tmp
.Suspicious filenames:
backdoor.sh
,rev.sh
,script.sh
.
Reverse Shells:
4. Determine Execution History
To confirm if the malicious cron job was executed, search for the specific script or command in the logs:
Or:
Eradication Steps
1. Remove Malicious Cron Jobs
Edit the crontab to remove the malicious entry:
For user-specific cron jobs:
2. Delete Malicious Scripts
Identify and remove the associated malicious scripts:
3. Reload Cron Daemon
Ensure cron reloads the updated configuration:
4. Validate the Changes
Recheck for active cron jobs:
Post-Incident Actions
Audit File Permissions: Ensure only authorized users can modify crontab files.
Limit User Access: Restrict the ability to create or edit cron jobs to specific users.
Monitor for Unauthorized Changes: Use file integrity monitoring tools like Tripwire or AIDE to track modifications in cron directories.
Centralize Log Analysis: Set up centralized logging to detect anomalies across systems.
Key Points
Cron jobs are a powerful tool but can be exploited by attackers for persistence. By systematically listing, analyzing, and removing unauthorized cron jobs, you can neutralize these threats and secure your system. Regular audits and proactive monitoring are essential to prevent future incidents.
Last updated