Skip to content
Menu

Is This PC Exposing RDP, SMB or Other Risky Ports Through the Firewall

Lists the TCP ports this PC listens on beyond itself, asks the Windows firewall who can reach each, and alerts when a risky port is open to any address, including when the firewall is off.

Is this PC exposing RDP, SMB or other risky ports through the firewall is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Is this PC exposing RDP, SMB or other risky ports through the firewall. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1, administrator rights, the NetTCPIP and NetSecurity modules
Read-onlyReads, changes nothing

What It Does

The script is read-only and looks only at this PC. It lists the TCP ports the PC is listening on, leaving out sockets that only accept connections from the PC itself, with the program and, when there is only one, the Windows service behind each.

For each port it reads the Windows firewall on every current network profile, or Public when it cannot tell. It matches enabled inbound rules by profile, TCP and local port, and by the program or service when the rule names one. Within a profile, a matching block rule wins. With no matching rules, the default inbound action applies. The row shows the widest reach across profiles, including when a profile firewall is off.

It alerts, with exit 1, when a port on RiskyPorts is reachable from any address, which includes a firewall that is off. A risky port that is listening but blocked is reported on its row and does not alert. A port reachable only from the local network or from named addresses alerts only when AlertOnRestricted is true. Ports in AllowedPorts never alert.

Not covered: UDP and rules that name a dynamic RPC range instead of a port, and what a router in front of the PC forwards from the internet. A port can be reachable here and still not be reachable from the internet, so to test what the internet sees, use a scanner outside the network. It needs administrator rights, because it reads the firewall and every process.

Before You Run It

  • Set RiskyPorts to the ports that matter for this client, and put the ports a server is meant to offer in AllowedPorts, such as 3389 on a terminal server.
  • Leave AlertOnRestricted off at first. Turn it on when you want a risky port open to the local network to count too.
  • Run it as an administrator or SYSTEM. It reads the firewall and every process.
  • Remember a port reachable here is not proven reachable from the internet. Check the router, or use a scanner outside the network.
  • Schedule it in your RMM and alert on exit 1.

Type and Risk

  • Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: 10 to 60 seconds.
  • Example answer: "2 risky port(s) reachable: 3389 RDP (any address), 445 SMB (any address)"
  • Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • RiskyPorts: TCP ports that alert when reachable, separated by commas. Default 21,23,445,3389,5900,5985,5986 (FTP, Telnet, SMB, RDP, VNC, WinRM and WinRM over HTTPS).
  • AllowedPorts: Ports that are meant to be open on this PC and never alert, separated by commas. Default none.
  • AlertOnRestricted: true also alerts when a risky port is reachable only from the local network or from named addresses. Default false.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

test-exposed-ports.ps1 · 1064 lines · 55.5 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.