Join our Newsletter — 33% off our NHI Course
Home› Guides› T1059 Command and Scripting Interpreter Defensive Guide: Logging,…
Guide Attack Techniques & Malware

T1059 Command and Scripting Interpreter Defensive Guide: Logging, Constraining and Detecting Interpreter Abuse

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 13 min read
On this page

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.

IDName (ATT&CK v20)Typical abusePrimary log source
T1059.001PowerShellDownload cradles, in-memory loaders, discovery, AD and cloud administration modulesScript block logging (4104), 4688 or Sysmon Event ID 1
T1059.002AppleScriptosascript prompts for credentials, AppleEvents to control appsmacOS unified log, EDR process events
T1059.003Windows Command Shellcmd.exe and batch files chaining built-in utilities4688 with command line, Sysmon Event ID 1
T1059.004Unix Shellsh, bash, zsh and busybox for scripts and reverse shells on Linux, macOS, ESXi, network appliancesauditd execve records, EDR, shell history
T1059.005Visual BasicVBA macros, VBScript run by wscript.exe or cscript.exeOffice telemetry, ASR events, process creation
T1059.006PythonBackdoors, downloaders and post-exploitation scripts, including on ESXiProcess creation, auditd
T1059.007JavaScriptJScript via Windows Script Host, HTA files, Node.jsProcess creation, ASR events
T1059.008Network Device CLIConfiguration changes and packet capture via the device's native CLIAAA command accounting (TACACS+), device syslog
T1059.009Cloud APICloud CLIs, cloud shells and SDKs issuing control plane callsCloud audit logs (for example AWS CloudTrail, Azure Activity and Entra logs)
T1059.010AutoHotKey & AutoIT.ahk and .au3 scripts as loaders and keyloggersProcess creation, application control events
T1059.011LuaLua scripts in embedded or Lua-enabled applicationsProcess creation, application logs
T1059.012Hypervisor CLIesxcli to change firewall rules or stop virtual machines before encryptionESXi shell and host logs
T1059.013Container CLI/APIdocker and kubectl against exposed or over-privileged APIsKubernetes 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 esxcli to 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

PlatformSetting or sourceNotes
Windows processesAdvanced Audit Policy "Audit Process Creation" plus Administrative Template "Include command line in process creation events" (Event ID 4688), or Sysmon Event ID 1Microsoft warns that command lines can contain passwords and that anyone who can read Security events can read them; restrict log access
PowerShellScript block logging (Event ID 4104), module logging, transcriptionUse 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 hostsAttack surface reduction rules in audit modeAudit action types such as AsrObfuscatedScriptAudited give a baseline before blocking
Linuxauditd syscall rules on execve keyed with -k, filtered with -F auid>=1000 -F auid!=unset for interactive users; EDRShell history files are attacker-editable and are supporting evidence only
Network devicesTACACS+ command accounting, remote syslog, configuration archive with diffingSend to a collector the device's own admins cannot alter
ESXiForward host logs to a SIEM; alert on shell and SSH service being enabledKeep the shell disabled when not in use
Cloud and containersCloud audit logs for all regions and accounts; Kubernetes API server audit policyRecord 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 spawning cmd.exe, powershell.exe, wscript.exe, bash or python. 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, netcat or ssh.
  • 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: osascript launched 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

ControlATT&CK mitigationConcrete setting
Remove unneeded interpretersM1042 Disable or Remove Feature or Program, M1033 Limit Software InstallationRemove PowerShell 2.0, AutoIT and Python from systems that do not need them; stop users installing runtimes
Constrain PowerShellM1038 Execution PreventionApp 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 administrationM1026 Privileged Account ManagementJust Enough Administration endpoints, which run in NoLanguage mode with only the cmdlets a role needs
Block script abuse from documents and downloadsM1040 Behavior Prevention on EndpointASR 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 scriptsM1045 Code SigningSigned scripts allowed by publisher in application control; unsigned scripts from user paths blocked
Restrict web contentM1021 Restrict Web-Based ContentChange the default handler for .js, .vbs, .hta and .wsf to a text editor; block these types at the mail gateway
Network and hypervisor CLIsM1026, M1018 User Account ManagementPer-user accounts through TACACS+ with command authorisation; ESXi shell and SSH disabled except during maintenance; lockdown mode on hosts
InventoryM1047 AuditRegular inventory of interpreters installed on servers and gold images

Rollout order

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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 env or printenv run 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

FrameworkReferenceRelevance
NIST CSF 2.0PR.PS-05, DE.CM-09, DE.AE-02Prevent unauthorised execution, monitor runtime environments, analyse events
NIST SP 800-53 Rev. 5CM-7(2), CM-7(5), AU-2, AU-12, SI-3, AC-6Prevent program execution, allow by exception, event logging, malicious code protection, least privilege
CIS Controls v8.1Safeguards 2.7 and 8.8Allowlist authorised scripts; collect command-line audit logs
ISO/IEC 27001:2022 Annex AA.8.7, A.8.15, A.8.16, A.8.19Malware protection, logging, monitoring, software installation
MITRE D3FENDD3-SEA Script Execution Analysis, D3-EAL Executable AllowlistingCountermeasures 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

Related NHI Mgmt Group resources: ATT&CK Execution Tactic Guide · PowerShell Security Guide · Living off the Land Guide · Fileless Malware Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.