The PowerShell Operator’s Guide

From "Living-off-the-Land" to Advanced Forensics

Core Philosophy: PowerShell is not just a scripting language; it is the direct interface to the Windows API and .NET Framework.

  • The Operator's Mindset: Everything is an Object. Text parsing (grep/awk) is secondary to object manipulation (Select, Where).

  • The Golden Rule: "Living off the Land" (LotL) means using native tools to avoid triggering EDR/AV solutions.


Part 1: The Environment & Fundamentals

Before executing, establish control and understand the engine.

1.1 Session Hygiene & OpSec

Professional operators do not rely on global settings; they configure the current session to be stealthy or verbose as needed.

Red Team (Stealth Configuration):

Avoid changing registry keys—bypass restrictions only for the running process.

# 1. Bypass Execution Policy (Scope: Process Only)
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force

# 2. Disable History Logging (Prevents artifacts in $env:APPDATA)
Set-PSReadlineOption -HistorySaveStyle SaveNothing

# 3. Suppress Error Noise (cleaner output during recon)
$ErrorActionPreference = "SilentlyContinue"

Blue Team (Visibility Configuration):

Enable logging to capture attacker activity.

1.2 The Object Pipeline (The Engine)

Mastering Get-Member (gm) is the difference between a novice and a pro.

Cmdlet

Alias

Function

Get-Member

gm

Crucial. Reveals properties (data) and methods (actions) of an object.

Where-Object

?

Filters the pipeline based on object properties.

Select-Object

select

Extracts specific properties to display or export.

ForEach-Object

%

Iterates through items in the pipeline.

The Workflow:

  1. Get the object.

  2. Filter (?) the object.

  3. Select (select) the data you need.


Part 2: Red Team Operations (Offence)

Focus: Enumeration, Evasion, and Lateral Movement.

2.1 Host Reconnaissance (LotL)

Gathering intelligence using native WMI/CIM classes (No external tools).

2.2 Network Discovery (The "Quiet" Scan)

Using .NET sockets to map the network without dropping Nmap.

2.3 Active Directory (The "No-Module" Method)

Attackers often land on workstations without RSAT tools. Use the [ADSISearcher] accelerator.

2.4 "Fileless" Execution (Download Cradles)

Loading scripts directly into RAM to bypass file scanning.


Part 3: Blue Team Operations (Defence)

Focus: Hunting, Hardening, and Auditing.

3.1 Threat Hunting (Event Logs)

Get-WinEvent is superior to Get-EventLog. Use FilterHashtable for speed.

Hunting Brute Force (Credential Access):

Hunting Lateral Movement (Pass-the-Hash):

3.2 Integrity Checking

Verifying system state against known baselines.


Part 4: Incident Response (The Kill Chain)

Scenario: Alert received. Ransomware or C2 active. Immediate Triage.

Image of cyber attack kill chainShutterstock

4.1 Isolation (Surgical Firewalling)

Cut the host off from the internet/LAN, but keep your management port open.

4.2 Volatile Data Capture

Capture RAM artifacts before the system crashes or reboots.

4.3 Malware Analysis (Decoding Payloads)

Attackers use Base64 to hide. Decode it.


Part 5: Modular Warfare (External Tools)

Do not reinvent the wheel. Use community-standard modules.

5.1 How to Load Modules (Safe vs. Unsafe)

  • Safe (Blue Team): Install-Module from PSGallery.

  • Stealth (Red Team): Load directly into memory via IEX (WebClient) to avoid disk artifacts.

5.2 The "Red" Modules (Offence)

Module

Purpose

Critical Commands

PowerView (PowerSploit)

AD Recon. The standard for mapping domains.

Get-NetDomain

Get-NetUser

Find-LocalAdminAccess (Finds where you are admin)

Get-NetSession (Finds where Domain Admins are logged in)

PowerUp

PrivEsc. Audits local vulnerabilities.

Invoke-AllChecks (Runs full audit)

Get-ServiceUnquoted (Finds unquoted paths)

Nishang

Exploitation. Shells and scanners.

Invoke-PowerShellTcp (Reverse Shell)

Invoke-PortScan

Example: Memory Loading PowerView

5.3 The "Blue" Modules (Forensics)

Module

Purpose

Critical Commands

PowerForensics

Disk Forensics. Reads raw NTFS/MFT.

Get-ForensicFileRecord (Reads MFT)

Invoke-ForensicDD (Bit-level copy of locked files like SAM)

NTFSSecurity

ACL Auditing. Readable permissions.

Get-NTFSOwner

Get-NTFSAccess (Audit who can read/write files)

MicroBurst

Cloud. Azure AD auditing.

Get-AzDomainInfo

Get-AzStorageKeys

Example: Recovering Deleted Files with PowerForensics


Part 6: Advanced Scripting & Automation

Professionalising your scripts.

6.1 Error Handling (Try/Catch)

Essential for scripts that run across hundreds of machines.

6.2 Data Export (JSON/CSV)

Never screenshot the console. Export to usable formats.


Part 7: The "Must-Have" Cheat Sheet

Task

Command / Syntax

Download File

Invoke-WebRequest -Uri $url -OutFile $file

Search Content

Get-ChildItem -Recurse | Select-String "password"

Base64 Encode

[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($str))

Base64 Decode

[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($b64))

Port Scan

Test-NetConnection -ComputerName $ip -Port $port

System Info

Get-ComputerInfo

User Info

whoami /all or Get-ADUser

Process Kill

Stop-Process -Id $pid -Force

History View

Get-Content (Get-PSReadlineOption).HistorySavePath

Last updated