Enable credentialed pre-port discovery
Credentialed pre-port discovery authenticates to a host with credentials you already manage and asks the operating system which TCP and UDP ports it is listening on. Pre-port discovery replaces network port inferences with an answer from the host itself.
Credentialed pre-port discovery is a scan template property, so you enable it per scan configuration (default is off). On a host where it succeeds, the network port scan is skipped and the engine moves straight to examining the discovered ports. On a host with no matching credential, or where authentication does not succeed, the scan falls back to a network port scan and that fallback is not reported as an error.
Everything after port discovery is unchanged. Service identification, fingerprinting, vulnerability checks, and policy evaluation run exactly as they do today against the ports that discovery returned.
Pre-port discovery limitations and best uses
Pre-port discovery is most valuable when the scan engine has broad network reachability to the hosts it scans and the goal is faster or more accurate port discovery. Two situations favor a network port scan instead:
- Heavily segmented networks — When the engine can reach only a handful of ports on each host, pre-port discovery still reports every port the host is listening on. The engine then spends time trying to reach ports a firewall blocks, the scan runs slower, and you get no results for the blocked ports.
- Results that must stay within a fixed set of ports — Pre-port discovery ignores the port range and excluded ports in your scan template and reports every port the host is listening on. If a compliance requirement means a host’s results must stay within a specific list of ports, scan it with a template that has pre-port discovery turned off.
For how pre-port discovery treats your template’s port settings, see Understand credentialed pre-port discovery.
Before you begin
Use the following checks before you enable credentialed pre-port discovery:
Confirm the engine can reach the services on the hosts you plan to scan (test reachability)
Pre-port discovery reports the ports a host is listening on, and the scan engine then connects to each one in turn. A port the engine cannot reach costs you both scan time and coverage, so test reachability before you enable the option rather than after.
Log in to the scan engine host and try the connection yourself with a representative sample rather than every port (one or two of the service ports you expect on each network segment you plan to scan this way):
Where you run the command matters
Run the following commands from the engine host rather than from your own machine because the engine’s path to a target can differ from yours and the engine’s result is the one that matters. If the connection fails from the engine, the cause is in the network path rather than in pre-port discovery.
# Linux or macOS
nc -vz <host> <port>
# Windows PowerShell
Test-NetConnection -ComputerName <host> -Port <port>Check which hosts your credentials actually cover
Pre-port discovery applies to a host only when at least one in-scope credential matches it. Three things determine the matching process:
- Address restrictions - A credential scoped to specific addresses or ranges is never tried against a host outside that scope.
- Credential scope - A site-scoped credential applies only to its own site, and a shared credential has to be enabled for the site being scanned.
- Host type - SSH credentials drive pre-port discovery on Linux, macOS, and other Unix-like hosts. A Windows host needs a Scan Assistant or Windows credentials.
Set a port restriction if a service is on a non-standard port
The default ports are TCP 22 for SSH and TCP 21047 for the Scan Assistant. If the service listens somewhere else, set that port on the credential’s port restriction. A credential’s port restriction is a single port, so there is no range to get wrong.
A credential left on the default while the service listens elsewhere fails to authenticate and falls back to a network port scan. For example, an SSH credential restricted to port 2222 is tried on 2222 but not on 22.
Understand credentialed pre-port discovery
When pre-port discovery is enabled, the engine uses whichever of your existing credentials fit each host:
| Credential type | Works on | Notes |
|---|---|---|
| Scan Assistant | Windows, Linux, macOS | Uses the Scan Assistant you have already deployed. Reachable on TCP 21047 by default. |
| SSH | Linux, macOS, other Unix-like hosts | Password or key-based SSH credentials. Connects on TCP 22 by default. |
| Windows | Windows | Uses your existing Windows credentials directly, when a Scan Assistant is not in play. Contacts the host on TCP 135, then continues on a dynamically negotiated port. |
You do not have to choose a method. The engine picks the best available option for each host from the credentials the scan already has. There is nothing new to deploy because pre-port discovery reuses the same credentials you already configure for authenticated scanning.
When more than one credential would work on a host, they are tried in this priority order:
- Scan Assistant
- SSH
- A direct Windows connection
The first credential that connects and authenticates is used. A credential that fails does not prevent the others from being tried. Once one succeeds, the rest are not attempted, so a host with several working credentials is authenticated to only once.
Which port each credential is tried on
Pre-port discovery has to choose a port before it can authenticate, and it chooses one per credential:
- By default it uses the standard port for the method: TCP
21047for the Scan Assistant, TCP22for SSH. - A credential restricted to a single port is tried on that port instead. This is how you cover a service on a non-standard port.
- Credentials with different port restrictions are each tried in turn. If you have one Scan Assistant credential on the default port and another restricted to a custom port, the engine attempts each until one authenticates.
Windows credentials are different
A port restriction on a Windows credential decides only whether the credential applies. It does not change the connection port.
What the scan template port settings control
Your scan template’s port settings under Service Discovery tell the engine which ports to probe over the network. This includes the port range you have chosen and any additional or excluded ports. A host that pre-port discovery has already asked directly is not probed that way, so those settings do not limit its results.
- Results can include ports outside your configured range. Pre-port discovery reports what the host is listening on, and all of it is kept.
- An excluded port is still reported on that host. If you rely on an exclusion to keep a port out of your results, pre-port discovery does not apply it.
- Hosts that fall back to a network port scan are unaffected. They honor the template exactly as before.
If you need a host’s results confined to a specific set of ports, scan it with a template that has pre-port discovery turned off.
How pre-port discovery is affected by reachability
“Reported open” and “reachable” are not equivalent. Pre-port discovery reads the list of listening ports from the host itself, and from the host’s own perspective those ports genuinely are open. What the host cannot know is whether a firewall, security group, or other network control sits between it and your scan engine. Ports that a host exposes only to itself, and never to other machines, are excluded from the results.
A network port scan could never detect this because it reports a port as open only if the engine could actually reach it. Pre-port discovery deliberately trades that outside-in view for the host’s authoritative inside-out view.
It is therefore entirely possible for pre-port discovery to report a port as open that your scan engine cannot connect to. Consider a host listening on a database port across all interfaces, while a firewall permits that port only from your application servers and not from the scan engine’s subnet. Pre-port discovery reports the port as open because from the host’s point of view it is.
To learn more about reachability, see the FAQ.
Enable pre-port discovery
Pre-port discovery is a property of the scan template, which means you enable it per scan configuration. You can enable pre-port discovery in your scan templates using the console or using the REST API. Note that when pre-port discovery is on:
- A host the scan engine authenticates to is treated as live.
- The network port scan is skipped for that host, and the engine examines the ports the host reported.
- Any host that pre-port discovery does not cover goes through the usual host discovery and network port scan.
Built-in templates cannot be edited
Trying to edit a built-in template won’t work. However, you can copy a built-in template, rename it, and use that instead.
To enable pre-port discovery in the console:
- From the Security Console, go to Administration > Scan Templates and edit or copy the template you want to change.
- Go to the Asset Discovery section.
- Select Use credentialed pre-port discovery.
- Save the template and assign it to the sites or scans where you want it used.
To enable pre-port discovery using the REST API:
- Retrieve a template using
GET /api/3/scan_templates/{id}. - Set
discovery.asset.prePortDiscoverytotruein the template you retrieved. - Send the updated body as a request using
PUT /api/3/scan_templates/{id}.
PUT replaces a template
A PUT operation replaces a whole template rather than patching it. Any setting you leave out of the body is written as its default value, not left at its current value, so always send the template you retrieved with the one property changed.
- Verify the update worked using
GET /api/3/scan_templates/{id}again.
Verify configuration
Rapid7 recommends initially updating and verifying one scan template. The simplest way to verify your configuration works as expected:
- Update a single custom template.
- Assign that template to a representative group of hosts, covering each host type and each network segment you plan to include.
- Run a scan, and compare the results against those hosts’ previous results: ports found, services identified, scan duration, and any new findings.
If the scan worked as expected, then slowly expand to a few templates at a time. The gains are largest where network port scanning has been slow, such as hardened or rate-limited hosts and large port ranges. A responsive host on a fast network may show little difference, so choose your comparison group with that in mind.
Use the scan log
Check the scan log to quickly see if pre-port discovery worked. If pre-port discovery succeeds, the log names the method that worked and the number of ports it returned:
# The method appears as ssh, scan-assistant, or wmi for a direct Windows connection.
[10.4.90.12] Pre-discovered via ssh: 14 TCP, 3 UDP ports.If pre-port discovery did not work, the logs will not mention pre-discovery, which usually means it is a credentials or port restrictions issue. If pre-discovery is present in the log but some discovered ports could not be reached, discovery worked and reachability is the issue.
To see each unreachable port individually, turn on Enhanced Logging in the scan template so the scan log runs at debug level. The per-port detail is produced by the scan target monitor, which is enabled by default; if it has been turned off, the log still points to a firewall or network restriction as a possible cause but does not list the individual ports.
# With Enhanced Logging on, the scan target monitor names each unreachable port (host and port).
[10.4.90.12:5432] Port was found open during pre-port discovery but failed during liveness probing. The connection did not succeed within 30000ms after 3 attempt(s); a host-level firewall or similar network restriction may be blocking external access to the port.If issues persist, consult Troubleshooting and the FAQ.
Troubleshooting
SSH credentials are configured, but ports were found by the network port scan
Work through these in order. The first accounts for most cases:
- SSH is not listening on port
22. With no port restriction on the credential, pre-port discovery tries only the standard port. Ifsshdlistens on2222, set the credential’s port restriction to2222. The same applies to a Scan Assistant on anything other than TCP21047. - An address restriction excludes the host. A credential scoped to specific addresses or ranges is never tried against a host outside that scope.
- The credential is not in scope for the scan. A site-scoped credential applies only to its own site, and a shared credential has to be enabled for the site being scanned.
- Authentication is not succeeding. A credential that works elsewhere can still fail on this host or this port. The scan log records the attempt.
- The scan is not using the template you edited. Confirm that the site or scan runs the template you changed, and that you edited a custom template. Built-in templates cannot be modified.
- The host is not Unix-like. SSH credentials drive pre-port discovery only on Linux, macOS, and other Unix-like hosts. A Windows host needs a Scan Assistant or Windows credentials.
In each of these cases, the host falls back to a normal network port scan. The result therefore looks the same as it did before you enabled the option, rather than appearing as an error.
Scanning got slower on some hosts or a host reports unreachable ports
Pre-port discovery found ports on the host that the scan engine cannot reach. The engine skips those ports and continues assessing the host’s reachable services, so the host is still scanned. What you lose is coverage of the unreachable ports themselves and some scan time, because the engine tries each unreachable port before moving on. The scan log names a host-level firewall or similar network restriction as the likely cause.
To find the unreachable ports, turn on Enhanced Logging in the scan template and rescan. The scan log then names each one with its host and port. See Use the scan log for the exact lines to look for.
To fix it, adjust your firewall or security-group rules so the engine can reach those services on the host. For hosts that are intentionally segmented off, use a template with pre-port discovery turned off instead.
Pre-port discovery found fewer ports than the previous network port scan
There are two common reasons:
- A device in front of the host, such as a load balancer, address translation rule, or port forward, may have been answering on ports the host itself is not listening on.
- A network port scan saw those ports, and the host does not report them.
Ports bound only to loopback are also excluded because no other machine can reach them. If you need to know what answers at an address from the outside, scan it with a template that has pre-port discovery turned off.
A port was reported open, but no service was identified on it
Discovery and service identification are separate steps. Pre-port discovery asks the host which ports are listening, and service identification then connects to each port from the engine.
A discovered port with no service identified can mean the engine could not reach it, so test that port from the engine host.
Your results include ports that the template’s port range does not cover
Pre-port discovery keeps what the host reports it is listening on, so a port range and excluded ports do not narrow the results for a host it has asked directly. For more information, see Understand credentialed pre-port discovery.
Your results list ports that you know are blocked by a firewall
This is expected. Pre-port discovery reports what the host is listening on, and a network control between the engine and the host does not change what the host is listening on.
Decide which view you want for that host: leave pre-port discovery on and allow the engine through, or scan the host with a template that has the option turned off.
Windows authenticated scanning works, but pre-port discovery over Windows does not
Direct Windows discovery needs more of the network path open than a basic connection does. After an initial handshake, the session continues on a dynamically negotiated port, so make sure your firewall permits that negotiated range between the engine and the host and not only the initial port.
Deploying a Scan Assistant avoids this entirely because it uses a single, predictable port.
Pre-port discovery FAQs
Does pre-port discovery replace authenticated scanning?
Pre-port discovery replaces the network port scan step only. Service identification, vulnerability checks, and policy evaluation run afterwards exactly as they do today, using the same credentials.
Does this change how weak ciphers, expired certificates, or default credentials are found?
Pre-port discovery does not change how weak ciphers, expired certificates, or default credentials are found. Pre-port discovery produces the list of ports, and everything that examines those ports is unchanged. The engine still identifies the service on each one, analyzes TLS configuration and certificates, and runs default-credential checks.
When the engine can reach a port that a network port scan would have missed, the same checks run against the port.
Do I need to create or change any credentials?
The one change worth making is on hosts where SSH or Scan Assistant runs on a non-standard port: set that port on the credential’s restriction. See Restrict credentials for details.
Which ports does the scan engine need to reach for pre-port discovery itself?
TCP 21047 for the Scan Assistant, TCP 22 for SSH or the port set on the credential’s restriction, and TCP 135 plus a dynamically negotiated port for a direct Windows connection. If the engine cannot reach the relevant one, the host falls back to a network port scan.
What happens if a host has more than one usable credential?
Credentials are tried in priority order (Scan Assistant, SSH, then a direct Windows connection), and the first to authenticate is used. Others are not attempted.
Any attempt that fails does not prevent the others from being tried.
Does enabling pre-port discovery change anything on hosts without credentials?
Enabling pre-port discovery does not change anything on hosts without credentials. Hosts without credentials and hosts where authentication fails are scanned exactly as before. That is why turning the option on costs you nothing on those hosts and why the fallback is not reported as an error.
What are the trade-offs when some ports are unreachable?
After discovery, the scan engine moves on to examine each open port, which works by connecting to the port from the engine. When the engine tries to reach a port that a firewall is blocking, the connection times out.
This has two consequences for the host:
- No service is identified on a port the engine cannot reach, so nothing running behind that port is checked.
- Each unreachable port has to time out before the engine moves on, so the host takes longer to scan than it otherwise would.
The engine does not stop scanning a host just because some of its pre-discovered ports are unreachable. It records the unreachable ports, logs a warning that names a host-level firewall or similar network restriction as the likely cause, and continues assessing the host’s reachable services.
A port the engine cannot reach is one a network port scan would never have reported as open, so nothing would have tried to connect to it. Pre-port discovery reports it, and the engine then spends time attempting it. What this costs you is the coverage of that one port and the time spent trying, not the whole host. The discovery itself was accurate. What you see is the mismatch between what the host is listening on and what your network path allows the engine to reach.
A host that has no matching credential falls back to a network port scan. That host is not pre-discovered, so repeated connection failures can still stop its scan early.
What controls can block the scan engine’s path to a port?
In each case, the host is reporting its listening ports correctly, and something in the path prevents the engine from connecting. A firewall rule is the most familiar example, but it is not the only kind of control that can sit between the scan engine and a host. Any of the following can stop the engine reaching a port that the host is listening on:
- On the host itself. A local firewall can drop the connection even when the network path is open, and a service bound to an interface or address other than the one you are scanning does not answer there.
- In the network. Cloud security groups, network access control lists, VLANs and microsegmentation policy, and intrusion prevention or rate limiting can all allow a port from some networks and not others.
- In front of the host. Address translation, a port forward, or a load balancer means the engine is talking to something other than the host that reported the port.
If you are unsure whether the engine can reach a given port, test it from the engine host. To learn more about testing reachability, see Before you begin.
To decide whether pre-port discovery is the correct choice for a site, see Pre-port discovery limitations and best uses.