winPEAS: Fix network scanning (arg parsing, race condition, port scanner, auto-mode crash)#612
Conversation
- Fix auto-mode NullReferenceException: change plain 'if' to 'else if' for IPAddressNetmask/IPAddressList branches in NetworkScanner.Scan(), so the auto path no longer falls through and calls AddRange(null) - Fix HostsAlive race condition in NetPinger: replace List<string> with ConcurrentBag<string> so concurrent async ping callbacks don't corrupt the collection - Fix unbound parallelism: cap outer host loop at MaxDegreeOfParallelism=5 and inner port loop at 50; create a PortScanner per host to remove shared-state concerns - Fix port scan output bypassing Beaprint: replace raw Console.WriteLine with Beaprint.GoodPrint so open-port results are colour-highlighted and respect -nocolor - Move network scan into NetworkInfo.PrintInfo(): add PrintNetworkScan() method, wire it into the check list when IsNetworkScan is true, remove the detached scan block from RunChecks(), expose NetworkScanOptions and PortScannerPorts as public, and remove the now-unused using directive
…x shim, fix Vault enum/struct casing
There was a problem hiding this comment.
Pull request overview
Fixes and refactors the winPEAS -network scanning flow (argument parsing, scan-mode selection, concurrency limits, and output formatting), and additionally introduces unrelated build/vault/linPEAS changes.
Changes:
- Normalize
-network/-portsCLI args to support space-separated values and move network scan execution into theNetworkInfocheck pipeline. - Improve network scan reliability: fix auto-mode branch selection, mitigate ping result race conditions, cap host/port scan parallelism, and route output through
Beaprint. - Add Linux MSBuild satellite-resource shim, add missing Vault structs/enums, and add linPEAS
-zthreads flag + regression tests.
Reviewed changes
Copilot reviewed 8 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| winPEAS/winPEASexe/winPEAS/KnownFileCreds/Vault/Structs/VAULT_ITEM_WIN8.cs | Adds Vault Win8 struct used by Vault dumping code. |
| winPEAS/winPEASexe/winPEAS/KnownFileCreds/Vault/Structs/VAULT_ITEM_WIN7.cs | Adds Vault Win7 struct used by Vault dumping code. |
| winPEAS/winPEASexe/winPEAS/KnownFileCreds/Vault/Structs/VAULT_ITEM_ELEMENT.cs | Adds Vault element header struct for value parsing. |
| winPEAS/winPEASexe/winPEAS/KnownFileCreds/Vault/Enums/VAULT_SCHEMA_ELEMENT_ID.cs | Adds Vault schema element ID enum. |
| winPEAS/winPEASexe/winPEAS/KnownFileCreds/Vault/Enums/VAULT_ELEMENT_TYPE.cs | Adds Vault element type enum. |
| winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/PortScanner.cs | Caps port-scan concurrency and routes open-port output through Beaprint. |
| winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/NetworkScanner.cs | Fixes auto-mode branch fallthrough and caps per-host scanning concurrency. |
| winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/NetPinger.cs | Fixes HostsAlive race by using ConcurrentBag and routes output through Beaprint. |
| winPEAS/winPEASexe/winPEAS/Checks/NetworkInfo.cs | Wires network scan into the structured NetworkInfo.PrintInfo() pipeline. |
| winPEAS/winPEASexe/winPEAS/Checks/Checks.cs | Normalizes -network/-ports parsing and removes detached scan invocation from RunChecks(). |
| winPEAS/winPEASexe/Directory.Build.targets | Adds non-Windows MSBuild shim to skip satellite resource generation/copy. |
| linPEAS/tests/test_builder.py | Adds regression tests ensuring -z is parsed and documented in built linPEAS script. |
| linPEAS/builder/linpeas_parts/linpeas_base/0_variables_base.sh | Adds -z threads flag parsing/help and fixes THREADS fallback validation. |
Comments suppressed due to low confidence (1)
winPEAS/winPEASexe/winPEAS/Checks/Checks.cs:403
- Network scan is now only executed as part of the
NetworkInfosystem check. If a user selects a subset of checks (e.g.systeminfo) while also passing-network=...,networkinfowon’t run and the scan will be skipped (previously the scan ran wheneverIsNetworkScanwas true). Consider ensuring the scan runs wheneverChecks.IsNetworkScanis set (e.g., force-selectnetworkinfo, add a dedicatednetworkscansystem check, or restore a separate scan execution path that still goes throughCheckRunner).
private static void RunChecks(bool isAllChecks, bool wait)
{
for (int i = 0; i < _systemChecks.Count; i++)
{
var systemCheck = _systemChecks[i];
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/PortScanner.cs
Outdated
Show resolved
Hide resolved
winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/NetPinger.cs
Outdated
Show resolved
Hide resolved
… wait handle, remove stale AsyncCallback+TcpPortState
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 15 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/PortScanner.cs
Outdated
Show resolved
Hide resolved
winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/PortScanner.cs
Outdated
Show resolved
Hide resolved
winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/PortScanner.cs
Outdated
Show resolved
Hide resolved
winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/NetPinger.cs
Outdated
Show resolved
Hide resolved
… resource exhaustion on large ranges
… sweep; surface errors in debug mode
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 16 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
winPEAS/winPEASexe/winPEAS/Info/NetworkInfo/NetworkScanner/PortScanner.cs
Outdated
Show resolved
Hide resolved
…ervedTaskException
…s to prevent test cross-talk
…GreatPrint from NetworkScanner.Scan()
…Info sub-checks when -network is passed with a subset

Summary
This PR fixes several bugs in the winPEAS network scanning feature (
-networkflag) and improves the overall reliability and output quality of host/port discovery.Changes
Bug Fixes
1. CLI argument parsing — space-separated values now accepted
The argument parser iterated over
argswith aforeach, so-network 10.0.0.0/24would hand the parser only the bare-networktoken with no value, causing the "not a valid option" error. Converted to aforloop that coerces space-separated flags intokey=valueform before any other logic runs. Both of these now work:2. Auto-mode
NullReferenceException(NetworkScanner.Scan())The
if / if / ifchain forIPAddressNetmask/IPAddressListbranches meant theautopath fell through and calledAddRange(null). Changed toelse ifso only one branch executes.3.
HostsAliverace condition inNetPingerConcurrent async ping callbacks were writing to a plain
List<string>, causing intermittent corruption / lost results. Replaced withConcurrentBag<string>.4. Unbound parallelism
The outer host loop and inner port loop had no concurrency cap, causing thread exhaustion on large subnets. Host loop is now capped at
MaxDegreeOfParallelism=5, port loop at 50. APortScannerinstance is created per host to eliminate shared-state concerns.5. Port scan output bypassing Beaprint
Open-port results were written via raw
Console.WriteLine, bypassing colour formatting and the-notcolorflag. Replaced withBeaprint.GoodPrint.6. Network scan wired into
NetworkInfo.PrintInfo()The scan block was previously a detached call in
RunChecks()outside the structured check pipeline. Moved into a newPrintNetworkScan()method onNetworkInfoand wired in whenIsNetworkScan == true, so it respects logging, timing, and-notcolorlike every other check.Testing
.\winPEAS.exe -network 10.154.9.0/24— no longer errors.\winPEAS.exe -network=auto— no longer crashes with NullReferenceException-notcolor