Summery

Linux’s job scheduler is known as cron. Scheduled tasks are listed in three main places:

  1. The /etc/cron sub-directories, where * represents the frequency at which the task will run. For example, tasks that will be run daily can be found under /etc/cron.daily. It’s usually used by system packages and administrators.
  2. /etc/crontab and /etc/cron.d/. These tasks should be inspected carefully for insecure file permissions. System administrators often add their own scheduled tasks here.
  3. /var/spool/cron/crontabs/<username> (depends on distro). Each user has their own cron file which they can edit with crontab -e. This is where most regular users hold their tasks.

To enumerate cron fully, here’s a short cheatsheet:

  1. ls -lah /etc/cron* - Enumerate all cron jobs from the sub-directories.
  2. Read both /etc/crontab and /etc/cron.d/*.
  3. Run crontab -l to view the current user’s scheduled jobs.
  4. Additionally, you can check for existance of both cat /var/log/cron.log and grep "CRON" /var/log/syslog.

When these tasks are misconfigured, or the user-created files are left with insecure permissions, we can modify these files that will be executed by the scheduling system at a high privilege level.

We can confirm that a cron job is running using pspy, a command-line tool used to view running processes without the need for root privileges. We can use it to see commands run by other users, cron jobs, etc. It works by scanning procfs. Example - ./pspy64 -pf -i 1000.

How to read time

* * * * * 
│ │ │ │ │ 
│ │ │ │ └─ day of week 
│ │ │ └─── month 
│ │ └───── day of month 
│ └─────── hour 
└───────── minute

Examples:

3 * * * * # At xx:03 every hour 
*/3 * * * * # At xx:00, xx:03, xx:06, xx:09, ... every hour