T1569.003

Systemctl

Adversaries may abuse systemctl to execute commands or programs as systemd services on Linux systems. Systemctl is the primary interface for systemd, the Linux init system and service manager. By crafting malicious service unit files and using systemctl start, enable, and daemon-reload, adversaries can execute arbitrary code immediately and establish persistent execution across reboots. Real-world abuse patterns include TeamTNT deploying cryptocurrency mining services, threat actors writing reverse shell service units pointing to payloads in /dev/shm or /tmp, and web shell compromise chains where an attacker-controlled web process creates a privileged service for lateral movement or persistence. Common subcommands used in attacks include: systemctl start, systemctl enable, systemctl daemon-reload, and systemctl link.

Microsoft Sentinel / Defender
kusto
let PackageManagers = dynamic(["dpkg", "apt", "apt-get", "rpm", "yum", "dnf", "snap", "packagekitd", "zypper", "pacman", "pip", "pip3", "conda", "flatpak"]);
let SuspiciousParents = dynamic(["apache2", "nginx", "httpd", "php-fpm", "php", "node", "nodejs", "java", "python", "python3", "ruby", "perl", "gunicorn", "uwsgi", "lighttpd", "caddy", "haproxy"]);
let SuspiciousServiceContentPatterns = dynamic(["/tmp/", "/dev/shm/", "/var/tmp/", "wget ", "curl ", " nc ", "bash -i", "sh -i", "python -c", "perl -e", "ruby -e", "base64 -d", "xmrig", "minerd", "cpuminer", "mkfifo", "/dev/tcp/"]);
// Branch 1: systemctl invoked directly from web server, application server, or interpreter process
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "systemctl"
| where ProcessCommandLine has_any ("start", "enable", "daemon-reload", "link")
| where InitiatingProcessFileName has_any (SuspiciousParents)
    or InitiatingProcessParentFileName has_any (SuspiciousParents)
| extend DetectionBranch = "WebApp_Process_Spawned_Systemctl"
| project Timestamp, DeviceName, AccountName, ProcessCommandLine,
          InitiatingProcessFileName, InitiatingProcessCommandLine,
          InitiatingProcessParentFileName, DetectionBranch
| union (
    // Branch 2: New .service unit file written to systemd directories by non-package-manager
    DeviceFileEvents
    | where Timestamp > ago(24h)
    | where FolderPath has_any ("/etc/systemd/system/", "/lib/systemd/system/", "/usr/lib/systemd/system/", "/run/systemd/system/")
    | where FileName endswith ".service"
    | where not (InitiatingProcessFileName has_any (PackageManagers))
    | where InitiatingProcessFileName has_any (SuspiciousParents)
        or InitiatingProcessCommandLine has_any (SuspiciousServiceContentPatterns)
        or InitiatingProcessParentFileName has_any (SuspiciousParents)
    | extend DetectionBranch = "Suspicious_Service_Unit_File_Created"
    | project Timestamp, DeviceName, AccountName=InitiatingProcessAccountName,
              ProcessCommandLine=InitiatingProcessCommandLine,
              InitiatingProcessFileName, InitiatingProcessCommandLine,
              InitiatingProcessParentFileName, DetectionBranch
)
| union (
    // Branch 3: systemctl run by non-root non-admin user with enable or link (escalation attempt)
    DeviceProcessEvents
    | where Timestamp > ago(24h)
    | where FileName =~ "systemctl"
    | where ProcessCommandLine has_any ("enable", "link", "daemon-reload")
    | where AccountName !in~ ("root", "_", "systemd", "daemon")
    | where not (InitiatingProcessFileName has_any (PackageManagers))
    | where InitiatingProcessParentFileName !in~ ("sshd", "login", "su", "sudo", "tmux", "screen")
    | extend DetectionBranch = "Unprivileged_Systemctl_Service_Enable"
    | project Timestamp, DeviceName, AccountName, ProcessCommandLine,
              InitiatingProcessFileName, InitiatingProcessCommandLine,
              InitiatingProcessParentFileName, DetectionBranch
)
| sort by Timestamp desc
high severity medium confidence

Data Sources

Process: Process Creation File: File Creation Command: Command Execution Microsoft Defender for Endpoint (Linux)

Required Tables

DeviceProcessEvents DeviceFileEvents

False Positives

  • System administrators manually creating or enabling services via SSH sessions — parent process will be bash/sh spawned from sshd, not a web process, but may still trigger Branch 3
  • Configuration management tools (Ansible, Chef, Puppet, SaltStack) that connect over SSH and run systemctl to manage services — typically run as root with known service names
  • Software installation scripts (npm postinstall, Python setup.py, Go install) that register services as part of legitimate package installation
  • CI/CD pipeline agents (Jenkins, GitLab Runner, GitHub Actions self-hosted) that build and deploy software including service registration steps
  • Container build processes that pre-populate systemd units inside container images as part of Docker RUN steps

Unlock Pro Content

Get the full detection package for T1569.003 including response playbook, investigation guide, and atomic red team tests.

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections