Almost every intrusion runs commands through an interpreter that is already installed, which means defenders cannot block T1059 outright and must instead control who can run what, and see what was run. MITRE ATT&CK tracks this as T1059 Command and Scripting Interpreter in the Execution tactic (TA0002). In ATT&CK v20 it has 13 sub-techniques and spans ten platforms, from Windows and Linux to network devices, hypervisors, containers, cloud APIs and identity providers. This guide covers that full breadth at the level of the ATT&CK descriptions, then concentrates on logging, constraint and detection for each interpreter family. PowerShell gets a short treatment here because it has its own deep guide. It is for detection engineers, endpoint, network and cloud platform teams.
Key takeaways
- It is a family, not one technique. Shells, script hosts, language runtimes, network device CLIs, hypervisor CLIs, container tooling and cloud APIs each need their own log source and their own controls.
- Logging the command is the foundation. Process creation with full command line, PowerShell script block logging and shell auditing turn T1059 from invisible to searchable; without them, every other analytic is guesswork.
- Constrain rather than remove. Constrained Language mode, Just Enough Administration, script signing and attack surface reduction rules shrink what an interpreter can do while leaving administrators productive.
- Context beats keywords. The best detections combine interpreter, parent process, user, host role and time, not lists of suspicious words that attackers can obfuscate.
- Non-human identities drive much of it. Service accounts, automation runbooks, CI runners and cloud access keys run interpreters at scale; their baselines are predictable, so deviations are high-signal.
How the attack works
ATT&CK describes T1059 as adversaries abusing command and script interpreters to execute commands, scripts or binaries. Most systems ship with at least one interpreter, and commands can be embedded in initial access payloads such as lure documents, downloaded as second stages from command and control, typed into interactive shells, or sent through remote services. The technique rarely stands alone: it is how attackers act on almost every other tactic, from discovery and credential access to collection and impact.
| ID | Name (ATT&CK v20) | Typical abuse | Primary log source |
|---|---|---|---|
| T1059.001 | PowerShell | Download cradles, in-memory loaders, discovery, AD and cloud administration modules | Script block logging (4104), 4688 or Sysmon Event ID 1 |
| T1059.002 | AppleScript | osascript prompts for credentials, AppleEvents to control apps | macOS unified log, EDR process events |
| T1059.003 | Windows Command Shell | cmd.exe and batch files chaining built-in utilities | 4688 with command line, Sysmon Event ID 1 |
| T1059.004 | Unix Shell | sh, bash, zsh and busybox for scripts and reverse shells on Linux, macOS, ESXi, network appliances | auditd execve records, EDR, shell history |
| T1059.005 | Visual Basic | VBA macros, VBScript run by wscript.exe or cscript.exe | Office telemetry, ASR events, process creation |
| T1059.006 | Python | Backdoors, downloaders and post-exploitation scripts, including on ESXi | Process creation, auditd |
| T1059.007 | JavaScript | JScript via Windows Script Host, HTA files, Node.js | Process creation, ASR events |
| T1059.008 | Network Device CLI | Configuration changes and packet capture via the device's native CLI | AAA command accounting (TACACS+), device syslog |
| T1059.009 | Cloud API | Cloud CLIs, cloud shells and SDKs issuing control plane calls | Cloud audit logs (for example AWS CloudTrail, Azure Activity and Entra logs) |
| T1059.010 | AutoHotKey & AutoIT | .ahk and .au3 scripts as loaders and keyloggers | Process creation, application control events |
| T1059.011 | Lua | Lua scripts in embedded or Lua-enabled applications | Process creation, application logs |
| T1059.012 | Hypervisor CLI | esxcli to change firewall rules or stop virtual machines before encryption | ESXi shell and host logs |
| T1059.013 | Container CLI/API | docker and kubectl against exposed or over-privileged APIs | Kubernetes audit log, container runtime events |
Where it shows up
- Exploited applications: web and AI application flaws often hand attackers an interpreter directly. The Langflow CVE-2025-3248 exploitation abused an unauthenticated endpoint that executed submitted Python code; attackers then ran
printenv, which exposes API keys and cloud credentials held in environment variables, and pulled down a botnet downloader. See the T1190 Exploit Public-Facing Application Defensive Guide. - Network infrastructure: ATT&CK records Salt Typhoon (G1045) running commands through native network device CLIs. The Salt Typhoon telecom intrusions mostly used legitimate credentials to change AAA and TACACS+ servers, ACLs and SNMP strings and to start SSH on high ports, all of which is visible only if command accounting is on.
- Hypervisors: ATT&CK lists Royal (S1073) and Cheerscrypt (S1096) ransomware using
esxclito list and stop virtual machines, and UNC3886 (G1048) using it to change firewall rules and remove artefacts. - Cloud control planes: Storm-0501 (G1053) and ShinyHunters (G1057) are recorded using cloud CLIs; the commands are legitimate API calls, so detection depends on who made them and from where. See the T1651 Cloud Administration Command Defensive Guide.
- Endpoints: macro documents, script files in archives and HTA files remain common first stages on Windows. See the Macro Malware Guide.
Impact
T1059 inherits the privileges of whoever runs the interpreter. On a workstation that is the user; on a server it is often a service account; on a network device or hypervisor it is frequently a full administrator; and in the cloud it is whatever role the access key or token holds. Interpreters also allow fileless execution, so payloads may never touch disk, and they let attackers use the same administration tools as the operations team, which slows triage. The realistic impact ranges from credential theft and data staging to configuration tampering on routers and mass shutdown of virtual machines before ransomware encryption.
Detection
Turn on the right telemetry
| Platform | Setting or source | Notes |
|---|---|---|
| Windows processes | Advanced Audit Policy "Audit Process Creation" plus Administrative Template "Include command line in process creation events" (Event ID 4688), or Sysmon Event ID 1 | Microsoft warns that command lines can contain passwords and that anyone who can read Security events can read them; restrict log access |
| PowerShell | Script block logging (Event ID 4104), module logging, transcription | Use Protected Event Logging, which encrypts the content with a certificate whose private key stays on the collector. See the PowerShell Security Guide |
| Office and script hosts | Attack surface reduction rules in audit mode | Audit action types such as AsrObfuscatedScriptAudited give a baseline before blocking |
| Linux | auditd syscall rules on execve keyed with -k, filtered with -F auid>=1000 -F auid!=unset for interactive users; EDR | Shell history files are attacker-editable and are supporting evidence only |
| Network devices | TACACS+ command accounting, remote syslog, configuration archive with diffing | Send to a collector the device's own admins cannot alter |
| ESXi | Forward host logs to a SIEM; alert on shell and SSH service being enabled | Keep the shell disabled when not in use |
| Cloud and containers | Cloud audit logs for all regions and accounts; Kubernetes API server audit policy | Record user agent, source IP and identity for every call |
Analytics that work
- Unusual parent: Office applications, browsers, PDF readers, web server worker processes (
w3wp.exe,httpd,java) or database engines spawningcmd.exe,powershell.exe,wscript.exe,bashorpython. A web server spawning a shell is one of the strongest signals of T1190 followed by T1059. - Encoded or obfuscated arguments: base64 encoded command parameters, long strings of concatenated characters, or script blocks that 4104 shows deobfuscated at run time.
- Interpreter plus network: an interpreter that makes an outbound connection or writes an executable within seconds of starting, which ATT&CK's Linux analytic describes as chaining shells with
curl,netcatorssh. - Wrong identity, wrong time: interpreters started by service accounts that never run them, or by admins outside change windows; for network devices, CLI sessions from unknown source addresses or uncommon accounts entering privileged mode.
- Cloud CLI from new places: CLI or SDK user agents for an access key that normally runs only from a pipeline, or calls from new autonomous systems.
- macOS:
osascriptlaunched by an application that is not user-initiated, particularly showing dialogs that ask for a password.
See the ATT&CK Detection Strategies and Analytics Guide for how MITRE structures these analytics in v20.
Metrics
- Percentage of Windows endpoints and servers sending 4688 with command line or Sysmon Event ID 1, and 4104 events, to the SIEM.
- Percentage of network devices with command accounting to a central AAA server.
- Percentage of hosts where PowerShell runs in Constrained Language mode for non-admin users under application control.
- Count of ASR rule audit hits per week for script rules, trending down as exclusions are cleaned up before enforcement.
- Mean time from an "Office or web server spawned a shell" alert to host isolation.
Prevention and hardening
| Control | ATT&CK mitigation | Concrete setting |
|---|---|---|
| Remove unneeded interpreters | M1042 Disable or Remove Feature or Program, M1033 Limit Software Installation | Remove PowerShell 2.0, AutoIT and Python from systems that do not need them; stop users installing runtimes |
| Constrain PowerShell | M1038 Execution Prevention | App Control for Business or AppLocker policy, so PowerShell runs in ConstrainedLanguage mode for anything not allowed by policy; Microsoft notes setting the mode by hand is not a security boundary |
| Delegate administration | M1026 Privileged Account Management | Just Enough Administration endpoints, which run in NoLanguage mode with only the cmdlets a role needs |
| Block script abuse from documents and downloads | M1040 Behavior Prevention on Endpoint | ASR rules "Block execution of potentially obfuscated scripts" (5beb7efe-fd9a-4556-801d-275e5ffc04cc), "Block JavaScript or VBScript from launching downloaded executable content" (d3e037e1-3eb8-44c8-a917-57927947596d), "Block all Office applications from creating child processes" (d4f940ab-401b-4efc-aadc-ad5f3c50688a), "Block Win32 API calls from Office macros" (92e97fa1-2edf-4476-bdd6-9dd0b4dddc7b) |
| Sign scripts | M1045 Code Signing | Signed scripts allowed by publisher in application control; unsigned scripts from user paths blocked |
| Restrict web content | M1021 Restrict Web-Based Content | Change the default handler for .js, .vbs, .hta and .wsf to a text editor; block these types at the mail gateway |
| Network and hypervisor CLIs | M1026, M1018 User Account Management | Per-user accounts through TACACS+ with command authorisation; ESXi shell and SSH disabled except during maintenance; lockdown mode on hosts |
| Inventory | M1047 Audit | Regular inventory of interpreters installed on servers and gold images |
Rollout order
- Telemetry first: enable command line process auditing, script block logging with Protected Event Logging, auditd execve rules and network device command accounting. This is low risk and gives the baseline every later step needs.
- ASR rules in audit mode: deploy script and Office rules in audit for two to four weeks; review the audited events and add narrow exclusions for genuine business macros or scripts.
- Enforce by ring: move to block on a pilot group, then on all standard users; keep the audit configuration as the documented rollback and test switching back once.
- Application control and Constrained Language mode: start on servers and privileged access workstations, where script use is known, then extend to the general estate. Sign internal admin scripts first, or they will break.
- Delegate with JEA and per-user device accounts: replace shared admin logons on servers and network devices so every command has an owner.
Small versus large organisations: a small team gets most value from command line logging, a handful of ASR rules in block mode and removing local admin. Large estates should treat Constrained Language mode under application control as a programme, prioritised by asset tier, because legacy admin scripts are the main blocker.
Where identity fits
Interpreters are the working tools of non-human identities: scheduled task accounts, automation runbooks, CI runners, configuration management agents and cloud access keys. Give each one its own identity, scope it to the commands and resources it needs, and alert when it runs an interpreter it has never used, from a host it has never used. On network devices, named accounts through central AAA replace shared enable passwords so command logs are attributable. See the Service Account Security Guide and the Windows Remote Management and WinRM/PowerShell Remoting Security Guide.
Lessons from incidents
- Exposed code execution leaks secrets first: in the Langflow case, the first post-exploitation commands targeted environment variables. Keep secrets out of interpreter environments of internet-facing applications and alert on
envorprintenvrun by web or AI application processes. - Infrastructure CLIs need the same logging as servers: the Salt Typhoon changes to AAA, ACLs and SNMP were made through ordinary CLI sessions with valid credentials; command accounting and configuration diffing are what make them visible.
Common failure patterns
- Keyword detection: rules that look for one cmdlet name or "-enc" are trivially evaded; parent, identity and behaviour hold up better.
- Execution policy treated as a control: ATT&CK itself notes there are ways to bypass PowerShell execution policy; it is a safety feature, not a security boundary.
- Logging without protection: command lines and script blocks containing secrets readable by anyone with log access.
- Endpoints only: no command logging on routers, firewalls, hypervisors or cloud control planes, which is exactly where several recent campaigns operated.
- Blanket exclusions: excluding whole script folders or admin tools from ASR and EDR, giving attackers a safe place to run.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | PR.PS-05, DE.CM-09, DE.AE-02 | Prevent unauthorised execution, monitor runtime environments, analyse events |
| NIST SP 800-53 Rev. 5 | CM-7(2), CM-7(5), AU-2, AU-12, SI-3, AC-6 | Prevent program execution, allow by exception, event logging, malicious code protection, least privilege |
| CIS Controls v8.1 | Safeguards 2.7 and 8.8 | Allowlist authorised scripts; collect command-line audit logs |
| ISO/IEC 27001:2022 Annex A | A.8.7, A.8.15, A.8.16, A.8.19 | Malware protection, logging, monitoring, software installation |
| MITRE D3FEND | D3-SEA Script Execution Analysis, D3-EAL Executable Allowlisting | Countermeasures for script analysis and allowlisting |
Practitioner checklist
- Enable 4688 with command line or Sysmon Event ID 1 on every Windows host, and restrict who can read those logs.
- Enable PowerShell script block logging with Protected Event Logging and remove PowerShell 2.0.
- Add auditd execve rules on Linux servers and forward them centrally.
- Turn on command accounting for every network device and forward ESXi and cloud audit logs.
- Deploy the script and Office ASR rules in audit, then block.
- Run PowerShell in Constrained Language mode under application control on servers and admin workstations first.
- Alert on web, database and Office processes spawning interpreters.
- Baseline interpreter use by each service account, runner and access key and alert on deviations.
Standards and references
- MITRE ATT&CK: Command and Scripting Interpreter (T1059)
- Microsoft Learn: Command line process auditing
- Microsoft Learn: about_Logging_Windows
- Microsoft Learn: about_Language_Modes
- Microsoft Learn: Attack surface reduction rules reference
- Linux man-pages: audit.rules(7)
- MITRE D3FEND: Script Execution Analysis
Related NHI Mgmt Group resources: ATT&CK Execution Tactic Guide · PowerShell Security Guide · Living off the Land Guide · Fileless Malware Guide