r/PowerShell • u/boostedchaos • Jul 17 '26
Script Sharing I open-sourced my PowerShell 7 fleet CVE scanner. The hard part was runspace-safe state and NVD rate limiting
I’m the author. This is free, Apache-2.0-licensed software. There’s no paid product or hosted service behind it.
For several months I iterated on a PowerShell CVE scanner that ran weekly against a Windows fleet. I recently released a sanitized, clean-room port:
https://github.com/boostedchaos/fleet-cve-scanner
It accepts inventory from NinjaOne or a CSV export, correlates the installed software against NVD, KEV, EPSS, SSVC, MSRC, and endoflife.date, then writes per-device CSV results, SQLite history, and a self-contained HTML dashboard.
The vulnerability logic is one part of it. The PowerShell concurrency problems were just as interesting.
The main scan uses ForEach-Object -Parallel to process unique software/version pairs. That exposed a few issues I had underestimated:
- Shared mutable state needs thread-safe types
The parallel runspaces need to coordinate a result collection, cache, deduplication keys, progress state, request timestamps, and cache-flush counters.
The shared pieces ended up using concurrent .NET collections and SemaphoreSlim rather than ordinary lists, dictionaries, queues, or non-atomic counters. Reads are easy. Coordinated mutation is where the bugs hide.
2. A sliding-window rate limiter still allowed bursts
NVD limits aren’t handled well by saying “N requests per 30 seconds” and calling it done. A window bucket allowed the first few requests to launch together and trigger 429s before the bucket was exhausted.
The current limiter has two gates:
- minimum spacing between request starts
- a sliding-window budget as a backstop
The lock is held only while checking and updating the shared timing state. It’s released before sleeping.
3. Correct launch spacing didn’t prevent overlapping requests
Even when calls started at the right interval, slower NVD responses left multiple requests in flight. That still produced 429s.
The scanner now holds a separate SemaphoreSlim across each NVD request, so only one request is on the wire at a time. Cache hits and the rest of the result processing remain parallel.
It sounds contradictory to parallelize the scanner and then serialize the API calls, but the parallelism still helps with cached products, version evaluation, deduplication, and result construction.
4. Functions and state have to exist inside the parallel runspace
Helper functions from the caller’s scope aren’t automatically available inside the parallel block. The runspace-local helpers have to be defined before their first possible call site.
I managed to hit the “function defined later in the script” failure more than once. One runspace can terminate while the others keep going, which makes the failure easier to miss in noisy output.
5. Cache checkpoints need their own concurrency discipline
A killed scan used to lose every NVD result fetched since startup because the cache was only written after the parallel block completed.
The scanner now checkpoints every configurable number of completed items. A non-blocking semaphore prevents multiple runspaces from flushing simultaneously, and the file is written to a temporary path before being moved into place.
There’s also a failure-state rule I consider load-bearing: an NVD request failure must never become a negative cache entry. A failed call returns a distinct CALL_FAILED sentinel, gets skipped for that run, and is retried next time. A successful response containing zero results can be cached normally.
The repository includes eight test suites, offline fixtures, a sanitization gate, and a known-limitations document that is intentionally less flattering than the README.
I’d particularly value review from people who have built larger ForEach-Object -Parallel pipelines:
- Would you structure the global rate limiter differently?
- Is serializing only the outbound NVD call the right boundary?
- Are there better patterns for safely checkpointing shared state from parallel runspaces?
- Has anyone used the CSV path against SCCM, Intune, or another RMM export?
This does not replace a commercial scanner with a curated detection catalog. CPE coverage and matching quality are the main ceiling. I’m more interested in cases where the script gives an operator the wrong level of confidence than whether the dashboard looks good.
2
u/MonkeyNin Jul 17 '26
Small notes:
1.) Join-Path is used in places, but not others
It ensures you don't get accidental path errors. Like
Only the first argument of
Join-Pathhas to exist. the right hand does not.2.) ArrayList can be simplified to List: Invoke-Release.ps1
I usually use this pattern:
You can treat it basically the same. You don't have the
+=copy issue. Another bonus is you don't have to void or null when you add to it.31
u/LALLANAAAAAA Jul 17 '26 •
I wonder if you guys are aware how identical all your post templates are and don't give a shit or if you're truly not aware
Or if you're even a human
I'm not sure which is worse honestly
Anyway can last person on Reddit turn the lights out when they leave, cheers
0
u/boostedchaos Jul 17 '26
A few direct links for anyone reviewing the implementation:
- Main script:
https://github.com/boostedchaos/fleet-cve-scanner/blob/main/fleet-cve-scan.ps1
- Engineering history and failure modes:
https://github.com/boostedchaos/fleet-cve-scanner/blob/main/docs/HISTORY.md
- Known limitations:
https://github.com/boostedchaos/fleet-cve-scanner/blob/main/docs/known-limitations.md
- How the scan works:
https://github.com/boostedchaos/fleet-cve-scanner/blob/main/docs/how-it-works.md
- CSV input and adapter notes:
https://github.com/boostedchaos/fleet-cve-scanner/blob/main/docs/rmm-adapters.md
The smallest offline test uses a CSV containing hostname,software,version:
Copy-Item config.example.json config.json
# Set output.report_dir in config.json.
# Add an NVD API key if you have one.
pwsh -File fleet-cve-scan.ps1 -InputCsv inventory.csv
A free NVD API key is strongly recommended for anything beyond a tiny test. Anonymous limits work, but they’re painfully slow for fleet-sized inventory.
7
u/[deleted] Jul 17 '26
[removed] — view removed comment