Systemd Timers
Last updated
Last updated
Adversaries may abuse systemd timers to perform task scheduling for initial or recurring execution of malicious code. Systemd timers are unit files with file extension .timer that control services. Timers can be set to run on a calendar event or after a time span relative to a starting point. They can be used as an alternative to Cron in Linux environments. Systemd timers may be activated remotely via the systemctl command line utility, which operates over SSH.
Each .timer file must have a corresponding .service file with the same name. Privileged timers are written in /etc/systemd/system and /usr/lib/systemd/system while user level are written to ~/.config/systemd/user/.
An adversary may use systemd timers to execute malicious code at system startup or on a scheduled basis for persistence. Timers installed using the privileged path may be used to maintain root level persistence. Adversaries may also install user level timers to achieve user level persistence.
At a user level notice in the image below the path I've created to set a timer to run as a User, the action I want it to do when it Boots, to be active every 24 hours, and to run on a specific calendar time, in this case from Mon - Fri at 09:06am and finally create the service file which will point to the script or command we want it to execute, remember the file needs to have execution permission
With this set we can simply start the service to make sure it is working and can enable so we don't have to start it every time to execute