Skip to content
Caleb SmithCyberSecurityWithSmitti
Browse PowerShell example contentPowerShell example

Inbound firewall-rule review

Collect active-store inbound allow rules with related ports, addresses and programs.

How to use it

.\Get-SocFirewallExposureReview.ps1 -MaxRules 1000

Platform and permissions

Windows NetSecurity module; appropriate policy-read rights.

What changes / what is read

Reads configuration only; no rule or profile is changed.

Scope and interpretation

Rule configuration is not proof of end-to-end reachability. Listening state, block rules, active profiles, IPsec, routing and upstream controls need separate checks.

Practice task

Compare an allow rule with local listening state, then explain why neither alone proves internet exposure.

Reference

Microsoft documentation. Review the documentation for your installed version and use only an authorised learning or investigation environment.

This is personal educational material. Review the complete code and your signing policy before use. PowerShell code is displayed and downloaded as text; WordPress does not run it. Collection caps limit rows/files, not every provider’s wall-clock execution time.

PowerShell · PowerShell 5.1+ syntax target; Windows collectors require the stated Windows modules. Full Windows acceptance testing remains required.Download .ps1
#requires -Version 5.1
[CmdletBinding()]
param([ValidateRange(10,5000)][int]$MaxRules=1000)
if($env:OS -ne 'Windows_NT'){throw 'Windows NetSecurity is required.'}
$profiles=@(Get-NetFirewallProfile -ErrorAction Stop | Select-Object Name,Enabled,DefaultInboundAction,DefaultOutboundAction)
$rules=@(Get-NetFirewallRule -PolicyStore ActiveStore -Enabled True -Direction Inbound -Action Allow -ErrorAction Stop | Select-Object -First ($MaxRules+1))
$rows=@(foreach($rule in ($rules | Select-Object -First $MaxRules)){
    try {
        $ports=@($rule | Get-NetFirewallPortFilter -ErrorAction Stop)
        $addresses=@($rule | Get-NetFirewallAddressFilter -ErrorAction Stop)
        $apps=@($rule | Get-NetFirewallApplicationFilter -ErrorAction Stop)
        [pscustomobject]@{Name=$rule.Name;DisplayName=$rule.DisplayName;Profile=[string]$rule.Profile;Protocol=($ports.Protocol -join ',');LocalPort=($ports.LocalPort -join ',');RemoteAddress=($addresses.RemoteAddress -join ',');Program=($apps.Program -join ',');BroadRemoteAddressHint=($addresses.RemoteAddress -contains 'Any');Error=$null}
    } catch {[pscustomobject]@{Name=$rule.Name;Error=$_.Exception.Message}}
})
[pscustomobject]@{CollectedUtc=[datetime]::UtcNow;Profiles=$profiles;InboundAllowRules=$rows;ReachedRuleCap=($rules.Count -gt $MaxRules);Note='Configuration review only. Does not prove a listening service, effective end-to-end reachability or internet exposure. Routing, active profiles, IPsec, block rules and other controls require separate analysis. No firewall setting is changed.'}

Example code is displayed as text. Review it and test in your own lab before use.