MaxPatrol SIEM

Detects cyberincidents that undermine cyber resilience of a company

T1543.002: Systemd Service

Adversaries may create or modify systemd services to repeatedly execute malicious payloads as part of persistence. Systemd is a system and service manager commonly used for managing background daemon processes (also known as services) and other system resources. Systemd is the default initialization (init) system on many Linux distributions replacing legacy init systems, including SysVinit and Upstart, while remaining backwards compatible.

Systemd utilizes unit configuration files with the .service file extension to encode information about a service's process. By default, system level unit files are stored in the /systemd/system directory of the root owned directories (/). User level unit files are stored in the /systemd/user directories of the user owned directories ($HOME).

Inside the .service unit files, the following directives are used to execute commands:

  • ExecStart, ExecStartPre, and ExecStartPost directives execute when a service is started manually by systemctl or on system start if the service is set to automatically start.
  • ExecReload directive executes when a service restarts.
  • ExecStop, ExecStopPre, and ExecStopPost directives execute when a service is stopped.

Adversaries have created new service files, altered the commands a .service file’s directive executes, and modified the user directive a .service file executes as, which could result in privilege escalation. Adversaries may also place symbolic links in these directories, enabling systemd to find these payloads regardless of where they reside on the filesystem.

The .service file’s User directive can be used to run service as a specific user, which could result in privilege escalation based on specific user/group permissions.

Positive Technologies products that cover the technique

MaxPatrol SIEM knowledge base

unix_mitre_attck_persistence: PT-CR-1671: Unix_Systemd_Service_Modify: Persistence on a host was gained by changing a system service file. Attackers can create or modify systemd services to repeatedly execute malicious payloads.

Detection

IDDS0022Data source and componentFile: File CreationDescription

Systemd service unit files may be detected by auditing file creation and modification events within the /etc/systemd/system, /usr/lib/systemd/system/, and /home//.config/systemd/user/ directories, as well as associated symbolic links

IDDS0017Data source and componentCommand: Command ExecutionDescription

Suspicious systemd services can also be identified by comparing results against a trusted system baseline. Malicious systemd services may be detected by using the systemctl utility to examine system wide services: systemctl list-units -–type=service –all. Auditing the execution and command-line arguments of the 'systemctl' utility, as well related utilities such as /usr/sbin/service may reveal malicious systemd service execution.

IDDS0022Data source and componentFile: File ModificationDescription

Systemd service unit files may be detected by auditing file creation and modification events within the /etc/systemd/system, /usr/lib/systemd/system/, and /home//.config/systemd/user/ directories, as well as associated symbolic links

IDDS0019Data source and componentService: Service CreationDescription

Monitor for new constructed systemd services to repeatedly execute malicious payloads as part of persistence.

IDDS0019Data source and componentService: Service ModificationDescription

Analyze the contents of .service files present on the file system and ensure that they refer to legitimate, expected executables.

IDDS0009Data source and componentProcess: Process CreationDescription

Suspicious processes or scripts spawned in this manner will have a parent process of ‘systemd’, a parent process ID of 1, and will usually execute as the ‘root’ user.

Mitigation

IDM1033NameLimit Software InstallationDescription

Restrict software installation to trusted repositories only and be cautious of orphaned software packages.

IDM1018NameUser Account ManagementDescription

Limit user access to system utilities such as systemctl to only users who have a legitimate need.

IDM1022NameRestrict File and Directory PermissionsDescription

Restrict read/write access to systemd unit files to only select privileged users who have a legitimate need to manage system services.

IDM1026NamePrivileged Account ManagementDescription

The creation and modification of systemd service unit files is generally reserved for administrators such as the Linux root user and other users with superuser privileges.