Security Tool
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.
Design
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.
Coverage
What It Checks
| Check | Source | Warning / Critical |
|---|---|---|
| CPU, memory, disk | CIM (Win32_Processor, Win32_OperatingSystem, fixed disks only) | 85 / 95% used; 15 / 5% free |
| Uptime | LastBootUpTime | 30 / 60 days: restart-dependent updates not applied |
| Network | Get-NetAdapter -Physical | Warning if no physical link is up |
| Defender | Get-MpComputerStatus | RTP off is Critical; Tamper Protection off is Warning; signatures 2 / 7 days |
| Firewall | Get-NetFirewallProfile -PolicyStore ActiveStore | Any profile off is Critical |
| Pending reboot | CBS and Windows Update registry keys | Warning |
| Patch age | Get-HotFix, newest install | 35 / 60 days |
| Logs cleared | Security 1102, System 104 | Any in 24 hours is Critical |
| BitLocker | Win32_EncryptableVolume on the OS drive | Protection 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.
Evidence
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.
And what the SYSTEM task wrote to the Application log on its first scheduled run, before the override, when BitLocker was still a Critical:
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.
Detection
The Splunk Side
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.
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.
Attack, Detect, Harden
What an Attacker Does to These Checks
| Technique | Module reports | Native evidence | ATT&CK |
|---|---|---|---|
| Turn off Defender RTP | 3006 Critical | Defender Operational 5001, 5007 | T1562.001 |
| Turn off a firewall profile | 3008 Critical | Security 4950 (needs MPSSVC auditing) | T1562.004 |
| Clear event logs | 3011 Critical | Security 1102, System 104 | T1070.001 |
| Stop or delete the monitor | Heartbeat gap | Security 4699, Task Scheduler 141 | T1562.001 |
| Swap the files a SYSTEM task loads | Refuses to register | Security 4698 / 4702 | T1053.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.
Findings
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.
Engineering
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
-Commandwith full paths, not-EncodedCommand, so it reads clearly in 4688 and Sysmon process logs and does not look like an attacker's encoded launcher.
Reflection
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.
Tools
Tooling Used
Skills