T1059.004

Unix Shell

Adversaries may abuse Unix shell commands and scripts for execution. Unix shells are the primary command prompt on Linux, macOS, and ESXi systems, though many variations exist (sh, ash, bash, zsh, etc.). Unix shells can control every aspect of a system, with certain commands requiring elevated privileges. Adversaries may abuse Unix shells to execute various commands or payloads, access interactive shells through C2 channels, leverage shell scripts for persistence, or use stripped-down shells via Busybox on embedded devices and ESXi servers.

Microsoft Sentinel / Defender
kusto
let SuspiciousPatterns = dynamic([
  "/dev/tcp/", "/dev/udp/",
  "bash -i >& /dev/tcp",
  "nc -e /bin/", "ncat -e", "socat exec:",
  "curl | bash", "curl | sh", "wget | bash", "wget | sh",
  "curl -s | bash", "wget -q | bash",
  "base64 -d", "base64 --decode",
  "python -c 'import socket", "python3 -c 'import socket",
  "perl -e 'use Socket",
  "mkfifo /tmp/", "mknod /tmp/",
  "chmod +s", "chmod 4755", "chmod u+s",
  "crontab -", "/etc/cron",
  "useradd", "usermod -aG",
  "iptables -F", "iptables -P ACCEPT"
]);
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName in~ ("bash", "sh", "zsh", "dash", "ash", "ksh", "csh", "tcsh", "busybox")
| where ProcessCommandLine has_any (SuspiciousPatterns)
| extend ReverseShell = ProcessCommandLine has_any ("/dev/tcp/", "nc -e", "ncat -e", "socat exec:")
| extend CurlPipe = ProcessCommandLine has_any ("curl | bash", "curl | sh", "wget | bash", "wget | sh", "curl -s | bash")
| extend Base64Decode = ProcessCommandLine has_any ("base64 -d", "base64 --decode")
| extend PrivEsc = ProcessCommandLine has_any ("chmod +s", "chmod 4755", "useradd", "usermod -aG")
| project Timestamp, DeviceName, AccountName, FileName, ProcessCommandLine,
         InitiatingProcessFileName, InitiatingProcessCommandLine,
         ReverseShell, CurlPipe, Base64Decode, PrivEsc
| sort by Timestamp desc
high severity high confidence

Data Sources

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

Required Tables

DeviceProcessEvents

False Positives

  • DevOps tools and CI/CD pipelines that use curl|bash patterns for software installation (e.g., install.sh scripts)
  • System administrators running legitimate setup scripts that decode base64-encoded configuration
  • Configuration management tools (Ansible, Chef, Puppet, SaltStack) executing shell commands remotely

Unlock Pro Content

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

Response PlaybookInvestigation GuideHunting QueriesAtomic Red Team TestsTuning Guidance

Related Detections