On Linux and macOS systems, multiple methods are supported for creating pre-scheduled and periodic background jobs: cron, (Citation: Die.net Linux crontab Man Page) at, (Citation: Die.net Linux at Man Page) and launchd. (Citation: AppleDocs Scheduling Timed Jobs) Unlike [Scheduled Task](https://attack.mitre.org/techniques/T1053) on Windows systems, job scheduling on Linux-based systems cannot be done remotely unless used in conjunction within an established remote session, like secure shell (SSH).System-wide cron jobs are installed by modifying
/etc/crontab
file,/etc/cron.d/
directory or other locations supported by the Cron daemon, while per-user cron jobs are installed using crontab with specifically formatted crontab files. (Citation: AppleDocs Scheduling Timed Jobs) This works on macOS and Linux systems.Those methods allow for commands or scripts to be executed at specific, periodic intervals in the background without user interaction. An adversary may use job scheduling to execute programs at system startup or on a scheduled basis for Persistence, (Citation: Janicab) (Citation: Methods of Mac Malware Persistence) (Citation: Malware Persistence on OS X) (Citation: Avast Linux Trojan Cron Persistence) to conduct Execution as part of Lateral Movement, to gain root privileges, or to run a process under the context of a specific account.
The at program is another means on POSIX-based systems, including macOS and Linux, to schedule a program or script job for execution at a later date and/or time, which could also be used for the same purposes.
Each launchd job is described by a different configuration property list (plist) file similar to Launch Daemon or Launch Agent, except there is an additional key called
StartCalendarInterval
with a dictionary of time values. (Citation: AppleDocs Scheduling Timed Jobs) This only works on macOS and OS X.
echo "* * * * * #{command}" > #{tmp_cron} && crontab #{tmp_cron}
echo "#{command}" > /etc/cron.daily/#{cron_script_name}
at now + 1 minute -f script.sh
echo "shutdown -h now" | at -m 23:5
at now + 1 minute | ping -c 4 google.com > /home/ec2-user/google6.txt
/var/log/cron
bash_history
- bash_history : track the command "crontab" - you may need to look for the commands crontab
index=linux sourcetype=bash_history bash_command="crontab *" | table host, user_name, bash_command
- /var/log/cron : look for "crontab" & "REPLACE" in the cron logs
index=linux crontab replace
- /var.log/cron - track CMD command
cat /var/log/cron | grep CMD | cut -d " " -f 9 |sort | uniq -c | sort -rn will give you all the jobs which run in the environment with its number starting from high to low. You can look for a suspecious job/s which are not a part of a whitelisted jobs.
- index=linux sourcetype=bash_history at