T1059.001 - PowerShell
MITRE ATT&CK Technique: T1059.001 - PowerShell. Detections, visibility, use cases and real world attack insights.
PowerShell is a versatile and flexible automation and configuration management framework built on top of the .NET Common Language Runtime (CLR), which expands its capabilities far beyond other common command-line and scripting languages. Included by default in modern versions of Windows, it is widely used by system administrators to automate tasks, perform remote management, and configure enterprise environments at scale.
This ubiquity is precisely what makes PowerShell so attractive to adversaries. Its versatility minimizes the need to customize payloads or drop overtly malicious tools on a target system, as a native, trusted binary does the heavy lifting instead.
Malicious Objectives for PowerShell
Adversaries abuse PowerShell across every phase of an attack to achieve a wide range of objectives:
Execute commands - Run arbitrary instructions on compromised systems using a powerful, fully-featured scripting environment.
Evade detection - Operate within a trusted, signed Windows binary that blends into normal administrative activity.
Obfuscate malicious activity - Encode, encrypt, or mangle commands to defeat signature-based detection and complicate analysis.
Spawn additional processes - Launch child processes, interpreters, or payloads as part of a multi-stage attack chain.
Download and execute remote code - Retrieve and run binaries or scripts directly from the internet without writing to disk.
Gather information - Query the system, Active Directory, cloud environments, and running processes for reconnaissance.
Change system configurations - Modify security settings, disable defenses, or alter persistence mechanisms.
Mechanisms of PowerShell
Encoded and Obfuscated Commands
One of the most frequently observed PowerShell abuse patterns is the use of encoded or obfuscated commands to evade detection. Adversaries commonly rely on Base64 encoding combined with the -EncodedCommand switch, or variations of it such as -e, -en, -enc, to pass commands that would otherwise be flagged by signature-based controls.
Beyond Base64, adversaries use more sophisticated obfuscation techniques including string concatenation, character substitution, escape character insertion, and ScriptBlock manipulation to produce commands that are syntactically valid but visually unrecognizable. Tools like Invoke-Obfuscation document many of these techniques in depth.
Ingress Tool Transfer
PowerShell is one of the most common tools used to download payloads from remote infrastructure. Adversaries frequently invoke .NET methods such as (New-Object Net.WebClient).DownloadString() or DownloadFile() alongside cmdlets like Invoke-Expression (iex) to pull remote code directly into memory and execute it, often without ever writing a file to disk. This enables fileless execution that sidesteps many traditional endpoint controls.
Offensive Toolkits and Frameworks
PowerShell serves as the runtime backbone for a wide range of offensive security tools and post-exploitation frameworks, including Mimikatz (via PowerSploit), Empire, PoShC2, and Cobalt Strike. These tools use PowerShell to load malicious .NET assemblies in memory, facilitate process injection, perform credential dumping, and carry out lateral movement, all within the context of a trusted system binary.
Cloud and Identity Attacks
Adversaries increasingly leverage PowerShell modules designed for Azure and Microsoft 365 environments to conduct attacks against identity, cloud, and SaaS infrastructure. Upon compromising an Entra ID identity, adversaries use modules such as:
AzureAD / Microsoft.Graph - Query and modify Entra ID users, groups, and roles
AADInternals - Abuse Entra ID and Azure AD internals for token theft and backdoor creation
GraphRunner - Enumerate and abuse Microsoft Graph API permissions
PowerZure - Enumerate and exploit Azure resources
MicroBurst - Azure-focused security assessment and exploitation
AzureHound - Graph-based attack path enumeration for Azure environments
For these cloud-focused attacks, detection should focus on Entra ID sign-in logs and audit logs rather than endpoint telemetry.
Disabling Security Controls
Adversaries also use PowerShell to weaken defenses before executing further payloads. Common patterns include using the Set-MpPreference cmdlet to disable Windows Defender, modifying exclusion policies, and disabling tamper protection, all achievable with a single line of PowerShell if tamper protection is not enforced.
ATT&CK Technique Co-occurrences
PowerShell frequently co-occurs with:
Obfuscated Files or Information (T1027) - Encoded commands are the norm, not the exception
Ingress Tool Transfer (T1105) - Downloading remote payloads via WebClient or
Invoke-WebRequestProcess Injection (T1055) - Loading and injecting .NET assemblies into running processes
Windows Management Instrumentation (T1047) - Spawning PowerShell via WMI for lateral movement
Actions That Need to be Taken
The most effective protection against PowerShell tradecraft is implementing and enforcing a strong Windows App Control policy, which places PowerShell into Constrained Language Mode. This mitigates a wide array of PowerShell-based tradecraft by restricting access to .NET types, COM objects, and other powerful language features that adversaries depend on.
For organizations using Microsoft Defender products, enabling Tamper Protection is critical. With Tamper Protection enabled, the Set-MpPreference cmdlet cannot be used to disable Defender or create rule exceptions, blocking one of the most common PowerShell abuse patterns observed in the wild.
Visibility
Process Creation and Metadata
Process execution and parent-child relationships are among the most valuable telemetry sources for detecting malicious PowerShell activity. Monitoring process starts and stops alongside lineage gives defenders the context to distinguish legitimate administrative use from post-exploitation chains, particularly when combined with command-line parameters or network connection data.
Command Execution
Command-line parameters are an effective and widely available source of telemetry for detecting suspicious PowerShell behavior. They are especially powerful when used in conjunction with process lineage and network telemetry. Many of the highest-fidelity PowerShell detections are built on combinations of process starts, command-line content, and outbound connections observed together.
Network Communication and Connection Creation
Since adversaries routinely use PowerShell to download tools and establish reverse shells, network telemetry is an essential component of any PowerShell detection strategy. One of the most reliable detection patterns is monitoring for PowerShell invoking expressions that download content over HTTP, a signal that appears consistently across a broad range of threats.
Detection Technology
Windows Security Event ID 1101: Antimalware Scan Interface (AMSI)
AMSI provides telemetry on both on-disk and in-memory execution of PowerShell and other scripting languages including VBScript, JScript, and WMI. AMSI events are accessed through Event Tracing for Windows (ETW) rather than standard Windows event logging. Importantly, many PowerShell payloads include AMSI bypass attempts, and because AMSI logs the bypass attempt itself, robust detection of AMSI bypass activity should be a core part of any PowerShell detection strategy.
Windows Security Event ID 4104: Script Block Logging
Script block logging operates at two levels. Automatic logging (enabled by default) captures PowerShell script code containing suspicious terms, covering the majority of commonly abused cmdlets and .NET APIs. Global logging must be explicitly enabled and captures all PowerShell activity without restriction. Both write to Event ID 4104 in the Microsoft-Windows-PowerShell/Operational log. Note: script block logging is only available in PowerShell version 5 and above.
Windows Security Event ID 400: PowerShell Command-Line Logging
For environments where adversaries may downgrade to PowerShell version 2 to evade modern logging, Event ID 400 in the classic Windows PowerShell event log provides command-line logging for PowerShell host process starts, available since PowerShell version 2.
Windows Security Event IDs 800 and 4103: Module Loading and Add-Type Logging
Module logging (Event ID 800) logs all loaded PowerShell modules and must be explicitly enabled. It also captures source code supplied to the Add-Type cmdlet, which adversaries commonly use to compile and execute C# code at runtime. In PowerShell version 5 and above, Add-Type context is additionally captured in Event ID 4103 in the Microsoft-Windows-PowerShell/Operational log.
Sysmon Event ID 1 and 7: Process Creation and Image Loaded
Sysmon Event ID 1 captures PowerShell process creation events. Event ID 7 (Image Loaded) is particularly valuable as it records any process that loads System.Management.Automation.dll or System.Management.Automation.ni.dll, catching PowerShell execution even when it runs within other processes or through unusual host applications.
Endpoint Detection and Response (EDR) Tools
A comprehensive EDR product provides visibility into all the telemetry sources listed above, including process creation, command lines, network connections, module loads, and cross-process activity, in a single queryable data stream. EDR is the most practical and complete data source for detecting adversaries abusing PowerShell at scale.
Possible Use Cases
Detecting the -EncodedCommand Switch
PowerShell accepts shortened variations of -EncodedCommand, and anything from -e onward is valid. Monitoring for all variations prevents adversaries from evading detection by abbreviating the flag.
process == powershell.exe
&&
command_includes ('-e' || '-en' || '-enc' || '-enco' || [any variation of the encoded command switch])Test command - encoded command printing to console:
cmd
powershell.exe -encod VwByAGkAdABlAC0ASABvAHMAdAAgACIAdAB3AGUAZQB0ACwAIAB0AHcAZQBlAHQAIQAiAA==Detecting Base64 Encoding
Base64 encoding is not inherently malicious, but in the context of PowerShell execution it is a consistent indicator worth alerting on. Consider pairing this with a decoder like CyberChef in your investigation workflow to quickly surface the decoded content.
process == powershell.exe
&&
command_includes ('base64')Test command - Base64-encoded execution:
powershell
Invoke-Expression -Command ([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('VwByAGkAdABlAC0ASABvAHMAdAAgACIAdAB3AGUAZQB0ACwAIAB0AHcAZQBlAHQAIQAiAA==')))Detecting Obfuscation and Escape Characters
Obfuscation techniques disrupt detection logic by inserting characters that PowerShell ignores but that break signature matches. Monitoring for unusually high densities of metacharacters in PowerShell command lines provides coverage across a wide range of obfuscation styles.
process == powershell.exe
&&
command_includes [high counts of] ('^' || '+' || '
{"blogPost":{"id":"9cdf0288-223a-488c-8416-9062fa1d6484","title":"T1059.001 - PowerShell","slug":"t1059001-powershell","excerpt":"MITRE ATT&CK Technique: T1059.001 - PowerShell. Detections, visibility, use cases and real world attack insights.","tags":["detection","mitre-attack"],"content_json":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"italic"}],"text":"PowerShell is a versatile and flexible automation and configuration management framework built on top of the .NET Common Language Runtime (CLR), which expands its capabilities far beyond other common command-line and scripting languages. Included by default in modern versions of Windows, it is widely used by system administrators to automate tasks, perform remote management, and configure enterprise environments at scale."}]},{"type":"paragraph","content":[{"type":"text","marks":[{"type":"italic"}],"text":"This ubiquity is precisely what makes PowerShell so attractive to adversaries. Its versatility minimizes the need to customize payloads or drop overtly malicious tools on a target system, as a native, trusted binary does the heavy lifting instead."}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Malicious Objectives for PowerShell"}]},{"type":"paragraph","content":[{"type":"text","text":"Adversaries abuse PowerShell across every phase of an attack to achieve a wide range of objectives:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Execute commands"},{"type":"text","text":" - Run arbitrary instructions on compromised systems using a powerful, fully-featured scripting environment."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Evade detection"},{"type":"text","text":" - Operate within a trusted, signed Windows binary that blends into normal administrative activity."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Obfuscate malicious activity"},{"type":"text","text":" - Encode, encrypt, or mangle commands to defeat signature-based detection and complicate analysis."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Spawn additional processes"},{"type":"text","text":" - Launch child processes, interpreters, or payloads as part of a multi-stage attack chain."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Download and execute remote code"},{"type":"text","text":" - Retrieve and run binaries or scripts directly from the internet without writing to disk."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Gather information"},{"type":"text","text":" - Query the system, Active Directory, cloud environments, and running processes for reconnaissance."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Change system configurations"},{"type":"text","text":" - Modify security settings, disable defenses, or alter persistence mechanisms."}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Mechanisms of PowerShell"}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Encoded and Obfuscated Commands"}]},{"type":"paragraph","content":[{"type":"text","text":"One of the most frequently observed PowerShell abuse patterns is the use of encoded or obfuscated commands to evade detection. Adversaries commonly rely on Base64 encoding combined with the "},{"type":"text","marks":[{"type":"code"}],"text":"-EncodedCommand"},{"type":"text","text":" switch, or variations of it such as "},{"type":"text","marks":[{"type":"code"}],"text":"-e"},{"type":"text","text":", "},{"type":"text","marks":[{"type":"code"}],"text":"-en"},{"type":"text","text":", "},{"type":"text","marks":[{"type":"code"}],"text":"-enc"},{"type":"text","text":", to pass commands that would otherwise be flagged by signature-based controls."}]},{"type":"paragraph","content":[{"type":"text","text":"Beyond Base64, adversaries use more sophisticated obfuscation techniques including string concatenation, character substitution, escape character insertion, and ScriptBlock manipulation to produce commands that are syntactically valid but visually unrecognizable. Tools like "},{"type":"text","marks":[{"type":"link","attrs":{"href":"https://github.com/danielbohannon/Invoke-Obfuscation","target":"_blank","rel":"noopener noreferrer nofollow","class":"underline underline underline-offset-2 decoration-1 decoration-current/40 hover:decoration-current focus:decoration-current","title":null}}],"text":"Invoke-Obfuscation"},{"type":"text","text":" document many of these techniques in depth."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Ingress Tool Transfer"}]},{"type":"paragraph","content":[{"type":"text","text":"PowerShell is one of the most common tools used to download payloads from remote infrastructure. Adversaries frequently invoke .NET methods such as "},{"type":"text","marks":[{"type":"code"}],"text":"(New-Object Net.WebClient).DownloadString()"},{"type":"text","text":" or "},{"type":"text","marks":[{"type":"code"}],"text":"DownloadFile()"},{"type":"text","text":" alongside cmdlets like "},{"type":"text","marks":[{"type":"code"}],"text":"Invoke-Expression"},{"type":"text","text":" ("},{"type":"text","marks":[{"type":"code"}],"text":"iex"},{"type":"text","text":") to pull remote code directly into memory and execute it, often without ever writing a file to disk. This enables fileless execution that sidesteps many traditional endpoint controls."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Offensive Toolkits and Frameworks"}]},{"type":"paragraph","content":[{"type":"text","text":"PowerShell serves as the runtime backbone for a wide range of offensive security tools and post-exploitation frameworks, including Mimikatz (via PowerSploit), Empire, PoShC2, and Cobalt Strike. These tools use PowerShell to load malicious .NET assemblies in memory, facilitate process injection, perform credential dumping, and carry out lateral movement, all within the context of a trusted system binary."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Cloud and Identity Attacks"}]},{"type":"paragraph","content":[{"type":"text","text":"Adversaries increasingly leverage PowerShell modules designed for Azure and Microsoft 365 environments to conduct attacks against identity, cloud, and SaaS infrastructure. Upon compromising an Entra ID identity, adversaries use modules such as:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"AzureAD / Microsoft.Graph"},{"type":"text","text":" - Query and modify Entra ID users, groups, and roles"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"AADInternals"},{"type":"text","text":" - Abuse Entra ID and Azure AD internals for token theft and backdoor creation"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"GraphRunner"},{"type":"text","text":" - Enumerate and abuse Microsoft Graph API permissions"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"PowerZure"},{"type":"text","text":" - Enumerate and exploit Azure resources"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"MicroBurst"},{"type":"text","text":" - Azure-focused security assessment and exploitation"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"AzureHound"},{"type":"text","text":" - Graph-based attack path enumeration for Azure environments"}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"For these cloud-focused attacks, detection should focus on Entra ID sign-in logs and audit logs rather than endpoint telemetry."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Disabling Security Controls"}]},{"type":"paragraph","content":[{"type":"text","text":"Adversaries also use PowerShell to weaken defenses before executing further payloads. Common patterns include using the "},{"type":"text","marks":[{"type":"code"}],"text":"Set-MpPreference"},{"type":"text","text":" cmdlet to disable Windows Defender, modifying exclusion policies, and disabling tamper protection, all achievable with a single line of PowerShell if tamper protection is not enforced."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"ATT&CK Technique Co-occurrences"}]},{"type":"paragraph","content":[{"type":"text","text":"PowerShell frequently co-occurs with:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Obfuscated Files or Information (T1027)"},{"type":"text","text":" - Encoded commands are the norm, not the exception"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Ingress Tool Transfer (T1105)"},{"type":"text","text":" - Downloading remote payloads via WebClient or "},{"type":"text","marks":[{"type":"code"}],"text":"Invoke-WebRequest"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Process Injection (T1055)"},{"type":"text","text":" - Loading and injecting .NET assemblies into running processes"}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Windows Management Instrumentation (T1047)"},{"type":"text","text":" - Spawning PowerShell via WMI for lateral movement"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Actions That Need to be Taken"}]},{"type":"paragraph","content":[{"type":"text","text":"The most effective protection against PowerShell tradecraft is implementing and enforcing a strong "},{"type":"text","marks":[{"type":"link","attrs":{"href":"https://learn.microsoft.com/en-us/windows/security/application-security/application-control/app-control-for-business/appcontrol-and-applocker-overview","target":"_blank","rel":"noopener noreferrer nofollow","class":"underline underline underline-offset-2 decoration-1 decoration-current/40 hover:decoration-current focus:decoration-current","title":null}},{"type":"bold"}],"text":"Windows App Control"},{"type":"text","text":" policy, which places PowerShell into "},{"type":"text","marks":[{"type":"link","attrs":{"href":"https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/","target":"_blank","rel":"noopener noreferrer nofollow","class":"underline underline underline-offset-2 decoration-1 decoration-current/40 hover:decoration-current focus:decoration-current","title":null}},{"type":"bold"}],"text":"Constrained Language Mode"},{"type":"text","text":". This mitigates a wide array of PowerShell-based tradecraft by restricting access to .NET types, COM objects, and other powerful language features that adversaries depend on."}]},{"type":"paragraph","content":[{"type":"text","text":"For organizations using Microsoft Defender products, enabling "},{"type":"text","marks":[{"type":"link","attrs":{"href":"https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/prevent-changes-to-security-settings-with-tamper-protection?view=o365-worldwide","target":"_blank","rel":"noopener noreferrer nofollow","class":"underline underline underline-offset-2 decoration-1 decoration-current/40 hover:decoration-current focus:decoration-current","title":null}},{"type":"bold"}],"text":"Tamper Protection"},{"type":"text","text":" is critical. With Tamper Protection enabled, the "},{"type":"text","marks":[{"type":"code"}],"text":"Set-MpPreference"},{"type":"text","text":" cmdlet cannot be used to disable Defender or create rule exceptions, blocking one of the most common PowerShell abuse patterns observed in the wild."}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Visibility"}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Process Creation and Metadata"}]},{"type":"paragraph","content":[{"type":"text","text":"Process execution and parent-child relationships are among the most valuable telemetry sources for detecting malicious PowerShell activity. Monitoring process starts and stops alongside lineage gives defenders the context to distinguish legitimate administrative use from post-exploitation chains, particularly when combined with command-line parameters or network connection data."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Command Execution"}]},{"type":"paragraph","content":[{"type":"text","text":"Command-line parameters are an effective and widely available source of telemetry for detecting suspicious PowerShell behavior. They are especially powerful when used in conjunction with process lineage and network telemetry. Many of the highest-fidelity PowerShell detections are built on combinations of process starts, command-line content, and outbound connections observed together."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Network Communication and Connection Creation"}]},{"type":"paragraph","content":[{"type":"text","text":"Since adversaries routinely use PowerShell to download tools and establish reverse shells, network telemetry is an essential component of any PowerShell detection strategy. One of the most reliable detection patterns is monitoring for PowerShell invoking expressions that download content over HTTP, a signal that appears consistently across a broad range of threats."}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Detection Technology"}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Windows Security Event ID 1101: Antimalware Scan Interface (AMSI)"}]},{"type":"paragraph","content":[{"type":"text","text":"AMSI provides telemetry on both on-disk and in-memory execution of PowerShell and other scripting languages including VBScript, JScript, and WMI. AMSI events are accessed through Event Tracing for Windows (ETW) rather than standard Windows event logging. Importantly, many PowerShell payloads include AMSI bypass attempts, and because AMSI logs the bypass attempt itself, robust detection of AMSI bypass activity should be a core part of any PowerShell detection strategy."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Windows Security Event ID 4104: Script Block Logging"}]},{"type":"paragraph","content":[{"type":"text","text":"Script block logging operates at two levels. "},{"type":"text","marks":[{"type":"bold"}],"text":"Automatic logging"},{"type":"text","text":" (enabled by default) captures PowerShell script code containing suspicious terms, covering the majority of commonly abused cmdlets and .NET APIs. "},{"type":"text","marks":[{"type":"bold"}],"text":"Global logging"},{"type":"text","text":" must be explicitly enabled and captures all PowerShell activity without restriction. Both write to Event ID 4104 in the "},{"type":"text","marks":[{"type":"code"}],"text":"Microsoft-Windows-PowerShell/Operational"},{"type":"text","text":" log. Note: script block logging is only available in PowerShell version 5 and above."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Windows Security Event ID 400: PowerShell Command-Line Logging"}]},{"type":"paragraph","content":[{"type":"text","text":"For environments where adversaries may downgrade to PowerShell version 2 to evade modern logging, Event ID 400 in the classic "},{"type":"text","marks":[{"type":"code"}],"text":"Windows PowerShell"},{"type":"text","text":" event log provides command-line logging for PowerShell host process starts, available since PowerShell version 2."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Windows Security Event IDs 800 and 4103: Module Loading and Add-Type Logging"}]},{"type":"paragraph","content":[{"type":"text","text":"Module logging (Event ID 800) logs all loaded PowerShell modules and must be explicitly enabled. It also captures source code supplied to the "},{"type":"text","marks":[{"type":"code"}],"text":"Add-Type"},{"type":"text","text":" cmdlet, which adversaries commonly use to compile and execute C# code at runtime. In PowerShell version 5 and above, Add-Type context is additionally captured in Event ID 4103 in the "},{"type":"text","marks":[{"type":"code"}],"text":"Microsoft-Windows-PowerShell/Operational"},{"type":"text","text":" log."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Sysmon Event ID 1 and 7: Process Creation and Image Loaded"}]},{"type":"paragraph","content":[{"type":"text","text":"Sysmon Event ID 1 captures PowerShell process creation events. Event ID 7 (Image Loaded) is particularly valuable as it records any process that loads "},{"type":"text","marks":[{"type":"code"}],"text":"System.Management.Automation.dll"},{"type":"text","text":" or "},{"type":"text","marks":[{"type":"code"}],"text":"System.Management.Automation.ni.dll"},{"type":"text","text":", catching PowerShell execution even when it runs within other processes or through unusual host applications."}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Endpoint Detection and Response (EDR) Tools"}]},{"type":"paragraph","content":[{"type":"text","text":"A comprehensive EDR product provides visibility into all the telemetry sources listed above, including process creation, command lines, network connections, module loads, and cross-process activity, in a single queryable data stream. EDR is the most practical and complete data source for detecting adversaries abusing PowerShell at scale."}]},{"type":"heading","attrs":{"level":2},"content":[{"type":"text","text":"Possible Use Cases"}]},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Detecting the "},{"type":"text","marks":[{"type":"code"}],"text":"-EncodedCommand"},{"type":"text","text":" Switch"}]},{"type":"paragraph","content":[{"type":"text","text":"PowerShell accepts shortened variations of "},{"type":"text","marks":[{"type":"code"}],"text":"-EncodedCommand"},{"type":"text","text":", and anything from "},{"type":"text","marks":[{"type":"code"}],"text":"-e"},{"type":"text","text":" onward is valid. Monitoring for all variations prevents adversaries from evading detection by abbreviating the flag."}]},{"type":"codeBlock","attrs":{"language":null},"content":[{"type":"text","text":"process == powershell.exe\n&&\ncommand_includes ('-e' || '-en' || '-enc' || '-enco' || [any variation of the encoded command switch])"}]},{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Test command"},{"type":"text","text":" - encoded command printing to console:"}]},{"type":"paragraph","content":[{"type":"text","text":"cmd"}]},{"type":"codeBlock","attrs":{"language":"cmd"},"content":[{"type":"text","text":"powershell.exe -encod VwByAGkAdABlAC0ASABvAHMAdAAgACIAdAB3AGUAZQB0ACwAIAB0AHcAZQBlAHQAIQAiAA=="}]},{"type":"horizontalRule"},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Detecting Base64 Encoding"}]},{"type":"paragraph","content":[{"type":"text","text":"Base64 encoding is not inherently malicious, but in the context of PowerShell execution it is a consistent indicator worth alerting on. Consider pairing this with a decoder like "},{"type":"text","marks":[{"type":"link","attrs":{"href":"https://github.com/gchq/CyberChef","target":"_blank","rel":"noopener noreferrer nofollow","class":"underline underline underline-offset-2 decoration-1 decoration-current/40 hover:decoration-current focus:decoration-current","title":null}}],"text":"CyberChef"},{"type":"text","text":" in your investigation workflow to quickly surface the decoded content."}]},{"type":"codeBlock","attrs":{"language":null},"content":[{"type":"text","text":"process == powershell.exe\n&&\ncommand_includes ('base64')"}]},{"type":"paragraph","content":[{"type":"text","marks":[{"type":"bold"}],"text":"Test command"},{"type":"text","text":" - Base64-encoded execution:"}]},{"type":"paragraph","content":[{"type":"text","text":"powershell"}]},{"type":"codeBlock","attrs":{"language":"powershell"},"content":[{"type":"text","text":"Invoke-Expression -Command ([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('VwByAGkAdABlAC0ASABvAHMAdAAgACIAdAB3AGUAZQB0ACwAIAB0AHcAZQBlAHQAIQAiAA==')))"}]},{"type":"horizontalRule"},{"type":"heading","attrs":{"level":3},"content":[{"type":"text","text":"Detecting Obfuscation and Escape Characters"}]},{"type":"paragraph","content":[{"type":"text","text":"Obfuscation techniques disrupt detection logic by inserting characters that PowerShell ignores but that break signature matches. Monitoring for unusually high densities of metacharacters in PowerShell command lines provides coverage across a wide range of obfuscation styles."}]},{"type":"codeBlock","attrs":{"language":null},"content":[{"type":"text","text":"process == powershell.exe\n&&\ncommand_includes [high counts of] ('^' || '+' || '