T1037.004

RC Scripts

Adversaries may establish persistence by modifying RC scripts, which are executed during a Unix-like system's startup. These files allow system administrators to map and start custom services at startup for different run levels. RC scripts require root privileges to modify. Adversaries may add malicious binary paths or shell commands to rc.local, rc.common, and other RC scripts. Upon reboot, the system executes the script's contents as root, resulting in persistence. This technique is especially effective on ESXi hypervisors, IoT devices, and embedded systems. Notable threat actors using this technique include HiddenWasp, UNC3886, APT29, Velvet Ant, Green Lambert, Cyclops Blink, and iKitten.

Microsoft Sentinel / Defender
kusto
let RCScriptPaths = dynamic([
  "/etc/rc.local",
  "/etc/rc.common",
  "/etc/rc.d/",
  "/etc/init.d/",
  "/etc/rc.local.d/",
  "/etc/rc.local.d/local.sh",
  "/etc/rc0.d/",
  "/etc/rc1.d/",
  "/etc/rc2.d/",
  "/etc/rc3.d/",
  "/etc/rc4.d/",
  "/etc/rc5.d/",
  "/etc/rc6.d/"
]);
let SuspiciousWriteProcesses = dynamic([
  "bash", "sh", "dash", "zsh", "python", "python3", "perl", "ruby",
  "curl", "wget", "nc", "netcat", "ncat", "tee", "dd"
]);
union
(
  DeviceFileEvents
  | where Timestamp > ago(24h)
  | where ActionType in ("FileCreated", "FileModified")
  | where FolderPath has_any (RCScriptPaths) or FileName in ("rc.local", "rc.common", "local.sh")
  | extend RiskReason = "RC script file created or modified"
),
(
  DeviceProcessEvents
  | where Timestamp > ago(24h)
  | where ProcessCommandLine has_any (RCScriptPaths)
  | where ProcessCommandLine has_any ("echo", "tee", "cat", "sed", "awk", ">>")
  | where FileName has_any (SuspiciousWriteProcesses)
  | extend RiskReason = "Process writing to RC script path"
)
| project Timestamp, DeviceName, AccountName, ActionType, FolderPath, FileName,
          InitiatingProcessFileName, InitiatingProcessCommandLine,
          ProcessCommandLine, RiskReason
| sort by Timestamp desc
high severity medium confidence

Data Sources

File: File Creation File: File Modification Process: Process Creation Command: Command Execution Microsoft Defender for Endpoint

Required Tables

DeviceFileEvents DeviceProcessEvents

False Positives

  • System administrators legitimately modifying rc.local to add startup services or mount points during system configuration
  • Package managers (apt, yum, rpm) writing init.d scripts during legitimate software installation
  • Configuration management tools (Ansible, Chef, Puppet, SaltStack) modifying RC scripts as part of automated provisioning
  • Monitoring agents or security tools that add themselves to rc.local during installation
  • ESXi administrators modifying local.sh to set persistent host configurations

Unlock Pro Content

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

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections