PowerShell For Threat Hunting

Process Tree

Purpose: hunt for malicious/suspicious process like powershell

Get-CimInstance Win32_Process | 
  Where-Object {$_.Name -match 'powershell|pwsh'} | 
  Select-Object ProcessId,ParentProcessId,CommandLine | 
  Sort-Object ParentProcessId

Hunt For:

  • explorer.exe β†’ cmd.exe β†’ powershell.exe chains

  • Parent processes like winword.exe spawning PowerShell

PowerShell Process Command Lines

Purpose: Uncover hidden execution parameters

Get-CimInstance Win32_Process | 
  Where-Object { $_.Name -match 'powershell|pwsh' -and $_.CommandLine -ne $null } | 
  Select-Object ProcessId,CommandLine | 
  Format-Table -Wrap

Hunt For:

  • -EncodedCommand with base64

  • IEX (New-Object Net.WebClient).DownloadString() patterns

  • Uncommon arguments like -nop -w hidden -ep bypass

Example:

PowerShell Binary Hashes

Purpose: Verify authentic PowerShell executables

Hunt For:

  • Hashes not matching Microsoft-signed binaries

  • PowerShell running from Temp or AppData

PowerShell Process Start Times

Purpose: Identify new/unexpected instances

Hunt For:

  • Processes started at odd hours (e.g., 2 AM)

  • Multiple instances spawned within seconds

PowerShell Network Connections

Purpose: Detect C2 communications

Hunt For:

  • Connections to cloud IPs (AWS/Azure DigitalOcean)

  • Ports 443, 8443, 4443 with no SSL handshake

  • Office apps (winword.exe) spawning PowerShell

  • explorer.exe β†’ cmd.exe β†’ powershell.exe chains

PowerShell Parent Processes

Purpose: Uncover injection chains

Hunt For:

  • Office apps (winword.exe) spawning PowerShell

  • explorer.exe β†’ cmd.exe β†’ powershell.exe chains

PowerShell Loaded Modules

Purpose: Detect in-memory injection

Hunt For:

  • DLLs loaded from Temp folders

  • Missing Microsoft-signed core modules

PowerShell Script Block Logs

Purpose: Extract executed code blocks

Hunt For:

  • Invoke-Expression with external URLs

  • AMSI bypass patterns ([Ref].Assembly.GetType())

PowerShell Process ACLs

Purpose: Check for suspicious ownership

Hunt For:

  • Processes owned by NT AUTHORITY\SYSTEM with network calls

  • Unknown user accounts running PowerShell

Check for Scheduled Tasks Created by PowerShell

Purpose: Detect if powershell.exe is used to create scheduled tasks, a common persistence technique.

Check for Files Added to Temp Folder by PowerShell

Purpose: Identify suspicious files (e.g., .ps1, .exe, .dll) created in the Temp folder, potentially by PowerShell.

Check for Files Added to AppData Folder by PowerShell

Purpose: Detect suspicious files in the AppData folder, a common drop location for PowerShell-dropped malware.

Hunt for Other Files Created by PowerShell

Purpose: Identify new files created system-wide (outside Temp/AppData) that might be PowerShell-related.

Hunt for PowerShell Activity in Event Logs

Purpose: Detect suspicious PowerShell commands (e.g., Invoke-Expression, DownloadString) that might indicate file creation or task scheduling.

Hunt for PowerShell Interaction with WMI

Purpose: check if powershell.exe is running, interacting with WMI, or calling WMI classes

Hunt for Newly Created User Accounts

Purpose: Identify recently created user accounts in Active Directory to detect potential malicious activity (e.g., unauthorized account creation for persistence or lateral movement) for threat hunting.

Hunt for int process of Network Connection

Purpose: Identify processes with anomalous network connections (e.g., spoofed IPs, unexpected outbound traffic, or impersonated system services) to detect potential malware or lateral movement.

Last updated