Windows Health Monitor: Endpoint Posture Checks for the SIEM

The third part of the series. The privilege-escalation lab showed how an attacker moves up on a Windows host; the Splunk lab showed how to catch it. This module covers the state of the host itself: is Defender actually on, are the firewall profiles up, is the machine patching, has anyone cleared the logs. It checks, judges each result against a threshold, and writes the findings to the Windows event log, where the same Splunk forwarder picks them up.

Scope: a PowerShell module I rebuilt from a 2025 script. It is tested in CI on Windows PowerShell 5.1 and PowerShell 7 (50 Pester tests), and run for real on my own Windows 11 laptop, including as a SYSTEM scheduled task. All output on this page is from that laptop. It is a lab and portfolio tool: lightweight and auditable, not a replacement for an RMM or EDR.

Source on GitHub · Release v2.0.0

From Check to Alert

Collecting facts and judging them are separate steps. Collectors only gather data; a pure function compares it with the thresholds. That split is what makes the logic testable without a Windows host, and it means a saved snapshot can be judged again later with different thresholds.

Collect → judge → write → forward → alert 12 collectors CIM, registry Thresholds OK / Warn / Crit JSONL + CSV ProgramData Application log EID 1000-4012 Forwarder Splunk UF Alert SPL Runs every 15 minutes as SYSTEM from an admin-only folder. A check that fails to run reports Unknown, never OK.

What It Checks

CheckSourceWarning / Critical
CPU, memory, diskCIM (Win32_Processor, Win32_OperatingSystem, fixed disks only)85 / 95% used; 15 / 5% free
UptimeLastBootUpTime30 / 60 days: restart-dependent updates not applied
NetworkGet-NetAdapter -PhysicalWarning if no physical link is up
DefenderGet-MpComputerStatusRTP off is Critical; Tamper Protection off is Warning; signatures 2 / 7 days
FirewallGet-NetFirewallProfile -PolicyStore ActiveStoreAny profile off is Critical
Pending rebootCBS and Windows Update registry keysWarning
Patch ageGet-HotFix, newest install35 / 60 days
Logs clearedSecurity 1102, System 104Any in 24 hours is Critical
BitLockerWin32_EncryptableVolume on the OS driveProtection off is Critical

Two details carry most of the value. ActiveStore reads the effective firewall policy, including Group Policy; the default store shows local settings only and can report a profile as on when GPO turned it off. And Unknown is never OK: if a collector fails (module removed, access denied, not elevated), that check is reported as Unknown with the reason. An attacker who breaks a check raises a flag instead of producing a clean report.

A Real Run

From my laptop, elevated, with my threshold override applied (see the BitLocker finding below). The one Warning is a Windows Update waiting for a restart.

PS> Get-HealthSnapshot | Test-HealthSnapshot -Threshold $override | Format-Table Check, Status, Message Check Status Message ----- ------ ------- Cpu OK CPU load 4% (1-second sample; one high reading is not a trend). Memory OK Memory 73.9% used (4.02 GB free of 15.42 GB). Disk OK C: 59.2% free (281.5 GB of 475.9 GB). Uptime OK Up 2.07 days since 2026-11-11T18:41:46.5000000Z. Network OK 1 physical adapter(s) up: WiFi. DefenderRealTime OK Real-time protection on, Tamper Protection True (mode: Normal). DefenderSignature OK Antivirus signatures are 0 day(s) old. Firewall OK All firewall profiles enabled (effective policy). PendingReboot Warning Reboot pending: WindowsUpdate. PatchAge OK Last update KB5132061 installed 3 day(s) ago. LogCleared OK No event log clearing in the last 24 h. BitLocker OK Not required by threshold config.

And what the SYSTEM task wrote to the Application log on its first scheduled run, before the override, when BitLocker was still a Critical:

PS> Get-WinEvent -FilterHashtable @{ LogName='Application'; ProviderName='WindowsHealthMonitor' } TimeCreated Id Level Message ----------- -- ----- ------- 13/11/2026 20:16:40 3012 Error BitLocker Critical: BitLocker protection OFF for C: 13/11/2026 20:16:40 2009 Warning PendingReboot Warning: Reboot pending: WindowsUpdate. 13/11/2026 20:16:40 1000 Information Health run complete. Worst status: Critical. Critical: 1, Warning: 1, Unknown: 0.

Event ID = severity base (1000 OK, 2000 Warning, 3000 Critical, 4000 Unknown) + check number, so 3012 always means "BitLocker, Critical". EID 1000 is a heartbeat written on every run.

The Splunk Side

# Critical findings, last 24 hours index=wineventlog SourceName="WindowsHealthMonitor" EventCode>=3000 EventCode<4000 | stats latest(_time) AS last_seen values(Message) AS findings BY host

Posture alerts

Defender off (3006), a firewall profile off (3008) and logs cleared (3011) are the ones worth paging on. The rest feed a daily report.

# Monitor went quiet: no heartbeat in 45 min index=wineventlog SourceName="WindowsHealthMonitor" EventCode=1000 earliest=-7d | stats latest(_time) AS last_heartbeat BY host | where last_heartbeat < relative_time(now(), "-45m")

Heartbeat gap

An attacker with admin rights can stop the task. They can't make it keep sending heartbeats. The gap is the control for that, and it only works off the host.

What an Attacker Does to These Checks

TechniqueModule reportsNative evidenceATT&CK
Turn off Defender RTP3006 CriticalDefender Operational 5001, 5007T1562.001
Turn off a firewall profile3008 CriticalSecurity 4950 (needs MPSSVC auditing)T1562.004
Clear event logs3011 CriticalSecurity 1102, System 104T1070.001
Stop or delete the monitorHeartbeat gapSecurity 4699, Task Scheduler 141T1562.001
Swap the files a SYSTEM task loadsRefuses to registerSecurity 4698 / 4702T1053.005

The last row is the one I built defences for in the module itself. A SYSTEM scheduled task that loads code from a folder an ordinary user can write to is a direct privilege escalation: replace the file, wait for the next run. It is the same misconfiguration class as the weak service permissions in the privilege-escalation lab. So Register-HealthMonitorTask checks every file SYSTEM will load and refuses to register if anyone other than SYSTEM, Administrators or TrustedInstaller can write to it, or owns it: an owner can always rewrite the permissions.

What It Found on a Real Machine

Task creation was not audited

After registering the task, Security EID 4698 (scheduled task created) was missing: "Audit Other Object Access Events" is off by default on Windows 11. An attacker's persistence task would have left no trace either. Fix: auditpol /set /subcategory:"{0CCE9227-69AE-11D9-BED3-505054503030}" /success:enable, or the same setting through GPO Advanced Audit Policy in a domain.

BitLocker was never enabled

manage-bde -status confirmed the Critical: fully decrypted, no key protectors. It is a personal device, so I accepted the risk, but recorded it in a threshold override (RequireBitLocker = $false) installed under the same admin-only ACL, instead of leaving a permanent red that teaches you to ignore red.

The guard caught a bug in my own installer

The installer locked down folders with icacls /inheritance:r /grant:r. In CI, the permission guard refused a folder that should have passed, and the ACL dump showed why: runneradmin:(OI)(CI)(F) with no (I) flag. That icacls pattern removes inherited entries and replaces the accounts it names, but an explicit entry for any other account survives. On a real machine, that would have left the module writable by the admin account that installed it, from an unelevated process. The fix sets the exact descriptor instead (O:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;0x1200a9;;;BU)), and the installer and the task now share that one function, so CI tests the code that actually ships.

How It Is Built

  • PowerShell module, compatible with Windows PowerShell 5.1 and PowerShell 7, no dependencies.
  • 50 Pester tests: fixture-driven unit tests for the judging logic, plus Windows integration tests (event log, ACL guard, task registration with -WhatIf).
  • GitHub Actions: PSScriptAnalyzer on Ubuntu, Pester on Windows in both PowerShell editions.
  • Output: JSONL (full snapshot), CSV (one summary row per run), Application event log with stable IDs.
  • The task command line is plain -Command with full paths, not -EncodedCommand, so it reads clearly in 4688 and Sysmon process logs and does not look like an attacker's encoded launcher.

What This Project Demonstrates

The original was a 2025 script with a bug that made every memory figure 1024 times too small, no error handling and an endless loop. Rebuilding it properly meant treating a monitoring tool as something an attacker will target: failures must be visible, silence must be alertable, and the tool must not become the privilege escalation it is meant to spot. CI caught two bugs that would have broken it on real machines, and the real-machine run found two gaps CI never could. That is the approach I take to everything I build: build it, harden it, and know how it gets attacked and detected.

Tooling Used

PowerShell • Pester • PSScriptAnalyzer • GitHub Actions • CIM/WMI • Microsoft Defender • Windows Firewall • BitLocker • Task Scheduler • Windows Event Log • Splunk

Skills Demonstrated

Endpoint Hardening • Security Posture Monitoring • Windows ACLs and SDDL • Privilege Escalation Prevention • Audit Policy • SIEM Integration • PowerShell Engineering • Automated Testing • CI/CD • MITRE ATT&CK

View on GitHub Back to Projects