Systemd Service
Adversaries may create or modify systemd services to repeatedly execute malicious payloads as part of persistence. Systemd is the default initialization system on many Linux distributions. Adversaries create new .service unit files or modify existing ones, placing them in /etc/systemd/system/, /lib/systemd/system/, or user-level ~/.config/systemd/user/ directories. The ExecStart, ExecStartPre, ExecReload, and ExecStop directives within service files execute commands when services start, reload, or stop. Threat actors including TeamTNT, Rocke, and Scattered Spider have leveraged systemd services for persistence and privilege escalation.
let SystemdServicePaths = dynamic([
"/etc/systemd/system/",
"/lib/systemd/system/",
"/usr/lib/systemd/system/",
"/run/systemd/system/",
".config/systemd/user/",
"/etc/systemd/user/"
]);
let SuspiciousServiceNames = dynamic([
"syslogd", "systemd-network", "systemd-resolve", "kthreadd",
"netns", "cron2", "update-rc", "sshd2", "rsyslogd"
]);
// Detection 1: New service file created in systemd directories
DeviceFileEvents
| where Timestamp > ago(24h)
| where ActionType in ("FileCreated", "FileModified")
| where FolderPath has_any (SystemdServicePaths)
| where FileName endswith ".service"
| extend IsUserLevelService = FolderPath contains ".config/systemd/user"
| extend IsSuspiciousName = FileName has_any (SuspiciousServiceNames)
| project Timestamp, DeviceName, AccountName, ActionType, FolderPath, FileName,
InitiatingProcessFileName, InitiatingProcessCommandLine, InitiatingProcessAccountName,
IsUserLevelService, IsSuspiciousName
| sort by Timestamp desc
// Detection 2: systemctl enable/start on newly created services
// Uncomment and union with above for broader coverage:
// union (
// DeviceProcessEvents
// | where Timestamp > ago(24h)
// | where FileName =~ "systemctl"
// | where ProcessCommandLine has_any ("enable", "start", "daemon-reload")
// | where ProcessCommandLine matches regex @"systemctl.*(enable|start).*\.service"
// ) Data Sources
Required Tables
False Positives
- Package managers (apt, yum, dnf, rpm) installing legitimate software that includes systemd service units
- System administrators manually creating or modifying service files for legitimate infrastructure automation
- Configuration management tools (Ansible, Chef, Puppet, SaltStack) deploying service configurations
- Docker or container runtime installations that register systemd services
- Development environments where developers create test services locally
References (10)
- https://attack.mitre.org/techniques/T1543/002/
- https://www.freedesktop.org/software/systemd/man/systemd.service.html
- http://man7.org/linux/man-pages/man1/systemd.1.html
- https://www.anomali.com/blog/rocke-evolves-its-arsenal-with-a-new-malware-family-written-in-golang
- https://www.elastic.co/security-labs/primer-on-persistence-mechanisms
- https://pberba.github.io/security/2022/01/30/linux-threat-hunting-for-persistence-systemd-timers-cron/
- https://pberba.github.io/security/2022/02/07/linux-threat-hunting-for-persistence-systemd-generators/
- https://redcanary.com/blog/attck-t1501-understanding-systemd-service-persistence/
- https://symantec-enterprise-blogs.security.com/threat-intelligence/troll-stealer-lazarus-group
- https://www.rapid7.com/db/modules/exploit/linux/local/service_persistence
Unlock Pro Content
Get the full detection package for T1543.002 including response playbook, investigation guide, and atomic red team tests.