Fix: detect CA availability via RPC (TCP 135) instead of ICMP ping#290
Open
1junh wants to merge 1 commit into
Open
Fix: detect CA availability via RPC (TCP 135) instead of ICMP ping#2901junh wants to merge 1 commit into
1junh wants to merge 1 commit into
Conversation
Set-AdditionalCAProperty gates live-CA reads with an ICMP echo (Test-Connection -Quiet). When inbound ICMPv4 Echo is blocked (the Windows Firewall default), a reachable CA is wrongly marked 'CA Unavailable', triggering runtime errors and false ESC findings during the CA scan. Probe TCP 135 (the RPC endpoint mapper AD CS actually uses) so reachable CAs are read instead of being falsely skipped.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates CA “availability” detection in Set-AdditionalCAProperty to better reflect how AD CS is actually contacted, avoiding false “CA Unavailable” results when ICMP is blocked but RPC is reachable.
Changes:
- Replaces ICMP echo reachability checks (
Test-Connection) with an RPC Endpoint Mapper TCP check (Test-NetConnectionto port 135).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+132
to
133
| $ping = if ($CAHostFQDN) { Test-NetConnection -ComputerName $CAHostFQDN -Port 135 -InformationLevel Quiet -WarningAction SilentlyContinue } else { Write-Warning "Unable to resolve $($_.Name) Fully Qualified Domain Name (FQDN)" } | ||
| if ($ping) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Set-AdditionalCAPropertygates all live-CA reads (certutil -getreg) behindan ICMP echo test:
Windows Firewall does not allow inbound ICMPv4 Echo by default (the
"File and Printer Sharing (Echo Request - ICMPv4-In)" rule is disabled out of
the box). On such hosts the CA is fully reachable over RPC/DCOM, yet this ping
fails, so the CA is reported as "CA Unavailable". This yields false positives
and runtime errors:
.Translate()throws IdentityNotMappedException on the"CA Unavailable" placeholder, and
$Issue.IdentityReferenceSID.ToString()isthen called on the resulting null SID (InvokeMethodOnNull).
Fix
Test TCP reachability on 135 (RPC Endpoint Mapper), matching the actual
transport. Unreachable-CA cases remain handled by the existing per-
certutiltry/catch.
Compatibility
Test-NetConnection is part of the inbox NetTCPIP module, documented for
Windows Server 2016 and later (with
-Portand-InformationLevel Quiet):https://learn.microsoft.com/powershell/module/nettcpip/test-netconnection?view=windowsserver2016-ps
Testing
In an environment where inbound ICMP echo is blocked (the Windows Firewall
default) but the CA is reachable over RPC, the current code logs runtime errors
during the CA scan and reports the DETECT/ESC6/ESC7/ESC11/ESC16 checks as
"CA Unavailable". With this change the scan completes cleanly with no errors,
and those checks are evaluated against the real CA configuration — identical to
a run where ICMP is allowed, but without changing the firewall.
Scope notes
Tests/Invoke-TSS.ps1(line 408), but Iwasn't sure whether it should be fixed too, so I've left it unchanged.
References
https://learn.microsoft.com/troubleshoot/windows-server/networking/service-overview-and-network-port-requirements#certificate-services
https://learn.microsoft.com/archive/blogs/pki/firewall-rules-for-active-directory-certificate-services