Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Last active October 5, 2026 04:26
Show Gist options
  • Select an option

  • Save primaryobjects/6d47dd003f0193feb86c3b52edee965f to your computer and use it in GitHub Desktop.

Select an option

Save primaryobjects/6d47dd003f0193feb86c3b52edee965f to your computer and use it in GitHub Desktop.
Windows 11 Post‑Execution Triage Script for anyone testing suspicious software in a VM, Oracle VirtualBox, Hypervisor, or PC. https://github.com/primaryobjects/snapshotdelta

PostRunCheck — Lightweight Post‑Execution Triage Script for Sandbox VMs

A small, hardened PowerShell triage script designed for virtual machines used to test suspicious software. It collects targeted, high‑value indicators after running an installer, EXE, or game — without dumping huge logs or weakening VM security.

This script is ideal for:

  • Malware‑analysis VMs
  • Suspicious installers
  • Unsafe software evaluation
  • Hardened VirtualBox / VMware environments

It runs safely using ExecutionPolicy Bypass (per‑run), which does not persist or weaken the VM.

What the script checks

The script gathers only the most relevant forensic indicators:

Processes & Services Running processes (sorted by CPU)

Running services Useful for spotting anything that stays resident after execution.

Startup & Persistence HKCU/HKLM Run keys

Scheduled tasks (filtered to essentials) Helps detect persistence mechanisms.

Network Activity Established TCP connections Shows if the program phoned home.

Hosts File Detects tampering or redirection.

Windows Defender Current protection status

Any threat detections logged during execution

Installed Programs Quick list of newly installed software

All results are saved into a timestamped folder like:

C:\PostRunChecks_20261004_1217\

How to run (safest method)

  1. Inside your VM, run PowerShell as Administrator and run the script.
    powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\PostRunCheck.ps1
  2. Run suspect program.
  3. Run the script again.
    powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\PostRunCheck.ps1
  4. Run a diff between the logs and compare results.
    powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Compare-Triage.ps1 -BaselinePath "C:\PostRunChecks_20261004_1230" -AfterPath "C:\PostRunChecks_20261004_1245"

Script Output

The script creates a folder containing:

processes.txt
services.txt
startup_hklm.txt
startup_hkcu.txt
schtasks.txt
netstat.txt
hosts.txt
defender_status.txt
defender_detections.txt
installed_programs.txt

These files provide a fast, focused snapshot of system state after running suspicious software.

Recommended VM Usage

This script is designed for hardened VMs.

  • No Guest Additions
  • No shared folders
  • No clipboard integration
  • No drag‑and‑drop
  • No GPU acceleration
  • No host integration
  • Snapshots enabled

Run suspicious software → run this script → review output → revert snapshot.

# Compare-TriageSmart.ps1
# Creates a human-readable report of meaningful changes between two triage runs
param(
[Parameter(Mandatory=$true)]
[string]$BaselinePath,
[Parameter(Mandatory=$true)]
[string]$AfterPath
)
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$outFile = "$AfterPath\SuspiciousChangesReport_$timestamp.txt"
function Compare-Files {
param($name)
$baseFile = Join-Path $BaselinePath $name
$afterFile = Join-Path $AfterPath $name
# Safely load baseline content
if (Test-Path $baseFile) {
$baseContent = Get-Content $baseFile
if ($baseContent -eq $null) { $baseContent = @() }
} else {
$baseContent = @()
}
# Safely load after-run content
if (Test-Path $afterFile) {
$afterContent = Get-Content $afterFile
if ($afterContent -eq $null) { $afterContent = @() }
} else {
$afterContent = @()
}
# Compare only new items
$diff = Compare-Object $baseContent $afterContent |
Where-Object { $_.SideIndicator -eq "=>" } |
Select-Object -ExpandProperty InputObject
return $diff
}
$sections = @{
"New Processes" = "processes.txt"
"New Services" = "services.txt"
"New Startup (HKLM)" = "startup_hklm.txt"
"New Startup (HKCU)" = "startup_hkcu.txt"
"New Scheduled Tasks" = "schtasks.txt"
"New Network Connections" = "netstat.txt"
"Hosts File Changes" = "hosts.txt"
"New Installed Programs" = "installed_programs.txt"
"New Defender Detections" = "defender_detections.txt"
}
"Suspicious Changes Report ($timestamp)" | Out-File $outFile
"======================================" | Out-File $outFile -Append
foreach ($section in $sections.Keys) {
$file = $sections[$section]
$changes = Compare-Files $file
"`n$section`:" | Out-File $outFile -Append
"------------------------" | Out-File $outFile -Append
if ($changes.Count -eq 0) {
"No changes detected." | Out-File $outFile -Append
} else {
$changes | Out-File $outFile -Append
}
}
Write-Host "Done. Review $outFile"
# PostRunCheck.ps1 (Normalized Version)
# Produces stable, diff-friendly triage output for hardened VMs
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$outDir = "C:\PostRunChecks_$timestamp"
New-Item -ItemType Directory -Path $outDir | Out-Null
Write-Host "Saving normalized triage output to $outDir"
# -----------------------------
# Normalized Processes
# -----------------------------
Get-Process |
Select-Object -ExpandProperty ProcessName |
Sort-Object |
Out-File "$outDir\processes.txt"
# -----------------------------
# Normalized Services
# -----------------------------
Get-Service |
Select-Object -ExpandProperty Name |
Sort-Object |
Out-File "$outDir\services.txt"
# -----------------------------
# Normalized Startup (HKLM)
# -----------------------------
Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" |
Get-Member -MemberType NoteProperty |
Select-Object -ExpandProperty Name |
Sort-Object |
Out-File "$outDir\startup_hklm.txt"
# -----------------------------
# Normalized Startup (HKCU)
# -----------------------------
Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" |
Get-Member -MemberType NoteProperty |
Select-Object -ExpandProperty Name |
Sort-Object |
Out-File "$outDir\startup_hkcu.txt"
# -----------------------------
# Normalized Scheduled Tasks
# -----------------------------
schtasks /query /fo LIST |
Select-String "TaskName:" |
ForEach-Object { ($_ -split ":")[1].Trim() } |
Sort-Object |
Out-File "$outDir\schtasks.txt"
# -----------------------------
# Normalized Network Connections
# -----------------------------
netstat -n |
Select-String "TCP" |
ForEach-Object {
# Extract remote IP only (ignore ephemeral ports)
$parts = ($_ -split "\s+")
if ($parts.Length -ge 4) {
($parts[3] -split ":")[0]
}
} |
Sort-Object |
Out-File "$outDir\netstat.txt"
# -----------------------------
# Hosts File (Normalized)
# -----------------------------
Get-Content "C:\Windows\System32\drivers\etc\hosts" |
Where-Object { $_ -notmatch "^#" -and $_.Trim() -ne "" } |
Sort-Object |
Out-File "$outDir\hosts.txt"
# -----------------------------
# Installed Programs (Normalized)
# -----------------------------
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object -ExpandProperty DisplayName |
Where-Object { $_ -and $_.Trim() -ne "" } |
Sort-Object |
Out-File "$outDir\installed_programs.txt"
# -----------------------------
# Defender Status (Normalized)
# -----------------------------
Get-MpComputerStatus |
Select-Object AMServiceEnabled, AntispywareEnabled, AntivirusEnabled, RealTimeProtectionEnabled |
Format-List |
Out-File "$outDir\defender_status.txt"
# -----------------------------
# Defender Detections (Normalized)
# -----------------------------
Get-MpThreatDetection |
Select-Object ThreatName, ActionSuccess, InitialDetectionTime |
Sort-Object ThreatName |
Out-File "$outDir\defender_detections.txt"
Write-Host "Done."
# PostRunCheckDetail.ps1
# Detailed post-execution triage script for Windows VMs including full paths and descriptions of processes and files
# Collects targeted evidence after running suspicious software
# Create output folder with timestamp
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$outDir = "C:\PostRunChecks_$timestamp"
New-Item -ItemType Directory -Path $outDir | Out-Null
Write-Host "Saving results to $outDir"
# --- Process and services ---
Get-Process | Select-Object Id,ProcessName,CPU,Path |
Sort-Object CPU -Descending |
Out-File "$outDir\processes.txt"
Get-Service | Where-Object {$_.Status -eq 'Running'} |
Select-Object Name,DisplayName |
Out-File "$outDir\services.txt"
# --- Startup and scheduled tasks ---
Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" |
Out-File "$outDir\startup_hklm.txt"
Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" |
Out-File "$outDir\startup_hkcu.txt"
schtasks /Query /FO LIST /V |
Select-String "TaskName|Next Run Time|Status" |
Out-File "$outDir\schtasks.txt"
# --- Network activity ---
netstat -ano | Select-String "ESTABLISHED" |
Out-File "$outDir\netstat.txt"
# --- Hosts file ---
Get-Content C:\Windows\System32\drivers\etc\hosts |
Out-File "$outDir\hosts.txt"
# --- Defender status and detections ---
Get-MpComputerStatus | Out-File "$outDir\defender_status.txt"
Get-MpThreatDetection | Out-File "$outDir\defender_detections.txt"
# --- Installed programs (short list) ---
Get-WmiObject Win32_Product | Select-Object Name,Version |
Out-File "$outDir\installed_programs.txt"
Write-Host "Post-run checks complete. Review files in $outDir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment