How to Run a VNC Internet Exposure Audit on Your Own Networks

To check a VNC deployment for direct internet exposure, scan your own public addresses from outside with nmap's vnc-info script, note every port that answers and what it asks for, then trace each one to the process and firewall rule behind it. Close it where it's published, on the host, the router or the cloud firewall, then re-run the same scan and keep both result files.

Two things decide who reaches a VNC server: the address its listener binds to and whatever sits in front of it, a firewall rule, a NAT forward or a published container port. The listening port defaults to 5900 plus the display number, so display :1 answers on 5901.

What the audit covers, and where exposure comes from

An analyst at a monitor reviewing a VNC exposure ledger that lists reachability, port, authentication, and connected system type.

You're answering four questions for every public address you own: does anything answer as VNC, on which port, does it want a password, and who owns the machine behind it. Stay on ranges you own or have written permission to test, and stop at what the server tells an unauthenticated client. Logging in, brute-forcing or exploiting is a different job.

Exposure almost always comes from one of three places. A server binds to 0.0.0.0 instead of loopback and the host firewall allows the port, a router or firewalld forward sends a public port to an internal desktop, or a container publishes its VNC port on every host address. A server bound only to 127.0.0.1 can't be reached directly from another machine, whatever the firewall allows, which is why the fixes below start on the host.

Find VNC on your public addresses, including odd ports

A four-step audit process listing owned addresses, fingerprinting, extending the port range, and recording findings, with step three highlighted.

Start with what the internet already knows. The Shodan CLI's shodan host <public-ip> lists the services Shodan has seen on one address, and anything VNC-shaped there that isn't in your inventory is a machine somebody forgot.

Then scan from a host outside your network, such as a small cloud VM, so you see what the internet sees rather than what your LAN sees. Save the output; it's your before record:

find vnc on your public addresses, including odd ports · bash
nmap -Pn -sV --script vnc-info -p 5500,5800-5999 -oA vnc-before <your-public-range>

-Pn scans hosts that drop ping, -oA writes vnc-before.nmap, .xml and .gnmap, and the vnc-info script reports each server's protocol version and security types without logging in. Keep -sV on the line: vnc-info only runs on 5900 to 5902 or on a port that version detection has named vnc. Without it, a VNC server on 7001 shows up as afs3-callback and never gets queried. Prefer --script vnc-info over -sC, which runs the whole default set, including scripts nmap itself flags as intrusive.

The 5900 range is only the baseline. Rapid7's 2020 internet scan counted just 5900 and 5901 and estimated that about 60% of VNC users stay on those ports, so plan a full sweep of each range as well:

find vnc on your public addresses, including odd ports · bash
nmap -Pn -sV --script vnc-info -p- -oA vnc-full <your-public-range>

-p- covers all 65535 ports and takes far longer. The extra ports in the first scan come from the protocol itself: some servers serve an HTTP viewer on 5800, and a viewer waiting for a server to call in listens on 5500. nmap 7.94 never labels a TigerVNC viewer in listen mode as vnc: a scan run as root shows hotline?, an unprivileged one tcpwrapped. Treat an open 5500 as a VNC finding either way.

Read what each server answers with

Every open vnc port normally gets a vnc-info block. One with no block usually means TigerVNC has started refusing your scanner, so treat it like the Locked out row. Here's how the lines translate:

What vnc-info prints What it means
None (1) and WARNING: Server does not require authentication Anyone who reaches the port gets the desktop.
VeNCrypt (19) with a subtype starting None, such as None, Anonymous TLS (257) or None, Server-authenticated TLS (260) Encrypted, but no password. nmap 7.94 prints no WARNING for the 260 subtype, so read the subtypes yourself.
VNC Authentication (2) only A VNC password, and the session after it travels unencrypted.
VeNCrypt (19) and VNC Authentication (2) both listed The viewer picks, so any viewer can skip TLS. Treat it like the bare password row. Upstream Xvnc’s default TLSVnc,VncAuth looks like this.
VeNCrypt (19) with VNC auth, Anonymous TLS (258) and no VNC Authentication (2) TLS plus a VNC password.
VNC (protocol 3.3; Locked out) in the version column TigerVNC has blacklisted your scanner after 5 unauthenticated connections. The port is still open and still a finding.

Fix them in that order. Anything that hands out the desktop without a password goes first, then a bare VNC Authentication (2) on a public address. For each finding, write down the address, port, security types, the program you find on the host in the next step, and a named owner. A server nobody claims is a candidate for removal, not hardening.

Trace each finding to its listener and firewall rule

On a Linux host, find the process and the address it binds to:

trace each finding to its listener and firewall rule · bash
sudo ss -tlnp

A line like 0.0.0.0:5901 ... users:(("Xtigervnc",pid=2985,fd=7)) (plus a matching [::]:5901) means the server listens on every address and only the firewall stands between it and the internet. 127.0.0.1:5901 and [::1]:5901 mean loopback only, so whatever answered the scan is another listener: a container, a proxy, or a forward to a different machine.

On Windows, Get-NetTCPConnection -State Listen lists every listening port with its owning process ID. Run Get-Process -Id <pid> on the one that answered the scan to name the server, then list the Windows Firewall rules that open that port:

trace each finding to its listener and firewall rule · powershell
Get-NetFirewallPortFilter | Where-Object -Property LocalPort -EQ 5900 | Get-NetFirewallRule

Each rule that comes back shows whether it's enabled and whether it allows inbound traffic. The filter only catches rules that name port 5900 itself in the persistent store; a rule for a range such as 5900-5903, or for the server program, won't show up here.

Then read every layer that can publish the port:

trace each finding to its listener and firewall rule · bash
sudo ufw status verbose
sudo firewall-cmd --list-all-zones
docker ps
  • Status: inactive means ufw isn't filtering anything; only another nftables or iptables ruleset, or a firewall in front of the host (router, appliance or cloud), could be. ufw starts disabled on Ubuntu, and rules you add do nothing until it's enabled.
  • A ufw rule for the port from Anywhere lets every source in.
  • In firewalld, look in each zone for the vnc-server service (it opens 5900-5903/tcp), a VNC port under ports:, or an entry under forward-ports:. --list-forward-ports alone shows only the default zone and only IPv4; IPv6 forwards live in rich rules, so check --list-rich-rules too.
  • A PORTS column showing 0.0.0.0:5901->5901/tcp means a container publishes VNC on every host address, and ufw never sees that traffic: Docker routes it in the nat table before ufw's chains.

Save this output beside vnc-before.*; you'll compare against it at the end.

Close the exposure

Put administrator access on loopback and reach it through an SSH tunnel. Keep a direct port open only where the viewer genuinely can't tunnel, and then only to an allowlisted source.

Firewall, forwards and containers

ufw applies the first rule that matches, so an allowlist rule added below an Anywhere rule changes nothing. Delete the broad rule, then add the narrow one if you need direct access at all:

firewall, forwards and containers · bash
sudo ufw status numbered
sudo ufw delete allow 5901/tcp
sudo ufw allow proto tcp from <admin-network> to any port 5901

sudo ufw status verbose now shows 5901/tcp ALLOW IN <admin-network> and no Anywhere line for 5901; the delete removes the IPv6 copy of the rule too. Delete with the same words the rule was added with: a rule listed as plain 5901 needs sudo ufw delete allow 5901, and allow 5901/tcp answers Could not delete non-existent rule. Deleting by the number from status numbered removes only that line, so its (v6) twin stays behind. If ufw was inactive, allow your own SSH source the same way before you run sudo ufw enable, or you'll lock yourself out.

For firewalld, paste each VNC forward exactly as --list-all-zones printed it, drop the service, and reload so the permanent configuration becomes the running one:

firewall, forwards and containers · bash
sudo firewall-cmd --permanent --zone=<zone> --remove-forward-port=port=5900:proto=tcp:toport=5901:toaddr=<internal-host>
sudo firewall-cmd --permanent --zone=<zone> --remove-service=vnc-server
sudo firewall-cmd --reload

Recreate a VNC container with the port published on loopback, -p 127.0.0.1:5901:5901, and docker ps shows 127.0.0.1:5901->5901/tcp. Forwards on an edge router or a cloud security group have no host command; delete them in the device's own console and let the re-scan prove it. RealVNC Server and macOS Screen Sharing also use UDP 5900, so remove a UDP forward for that port along with the TCP one.

Windows Firewall

On a Windows VNC host, narrow the rule that opens the port to your admin network, or switch it off if nobody needs a direct connection. Set-NetFirewallRule takes the rule's display name from the listing above:

windows firewall · powershell
Set-NetFirewallRule -DisplayName "<rule-name>" -RemoteAddress <admin-network>

To close it instead, pipe the same listing into Disable-NetFirewallRule:

windows firewall · powershell
Get-NetFirewallPortFilter | Where-Object -Property LocalPort -EQ 5900 | Get-NetFirewallRule | Disable-NetFirewallRule

TigerVNC on Ubuntu and Debian

The tigervncserver wrapper already listens on loopback unless someone passed -localhost no or configured TLS or X509 security types with no None type in the list. Make that stick with /etc/tigervnc/vncserver-config-mandatory, which overrides the defaults file, each user's ~/.vnc/tigervnc.conf (~/.config/tigervnc/config.pl on Debian 13) and the command line, and also covers tigervncserver@ units because they start through the same wrapper. Force only the listener; the session keeps the security types and password it already has:

tigervnc on ubuntu and debian · bash
printf '$localhost = "yes";\n' | sudo tee -a /etc/tigervnc/vncserver-config-mandatory
sudo systemctl restart tigervncserver@:1
sudo ss -tlnp | grep -E 'Xtigervnc|Xvnc'

A session you started by hand needs tigervncserver -kill :1 and a fresh start instead of the systemctl line. The listener comes back on 127.0.0.1:5901 and [::1]:5901, even for a session started with -localhost no -SecurityTypes TLSVnc,VncAuth, and that session still offers TLS. Viewers now come in through the SSH tunnel. The file can't stop a user who runs Xtigervnc directly, and the bare binary listens on every interface, so check ss for any Xtigervnc or Xvnc on 0.0.0.0 or [::]. ss shows the name the server was started as, and Ubuntu's Xvnc is a symlink to Xtigervnc.

x11vnc

x11vnc started without a password file (often with -nopw to silence its warning) shows up in the scan as None (1). Create a password, then start it with -localhost, which works like -allow 127.0.0.1 and binds the listener to loopback:

x11vnc · bash
x11vnc -storepasswd

That prompts for the password and writes ~/.vnc/passwd. Add -localhost -rfbauth ~/.vnc/passwd to the x11vnc command line you already use and drop -nopw; ss then shows x11vnc on 127.0.0.1 and [::1] only.

RealVNC Server

Direct connections are controlled by Enterprise parameters: AllowIpListenRfb=FALSE stops them, localhost=TRUE accepts them only from the same machine, and IpClientAddresses allowlists viewer addresses. On Linux, put the line in /etc/vnc/policy.d/common: every RealVNC Server mode reads it after the user config files and the command line, so it overrides both. /etc/vnc/config.d/vncserver-x11 is one of the lowest-precedence files and doesn't reach Virtual Mode. vnclicense -reload with sudo re-applies the configuration to every running server:

realvnc server · bash
echo 'AllowIpListenRfb=FALSE' | sudo tee -a /etc/vnc/policy.d/common
sudo vnclicense -reload

The Windows policy key is HKLMSoftwarePoliciesRealVNC ncserver for Service Mode and HKCUSoftwarePoliciesRealVNC ncserver for User Mode. Sessions already connected stay up, so end them. None of these parameters touches cloud connections; set AllowCloudRfb=FALSE as well if the machine shouldn't be reachable through RealVNC's cloud either.

Your own Xvnc scripts

A script that starts the server binary directly skips the wrapper and its mandatory file, and the binary listens on every interface by default. Give it -localhost and a password file made with tigervncpasswd, which writes ~/.vnc/passwd on Ubuntu 24.04 and ~/.config/tigervnc/passwd on Debian 13; point -PasswordFile at whichever it wrote. The binary is Xtigervnc on Ubuntu and Debian and Xvnc in an upstream build, with the same options. The Ubuntu 24.04 line:

your own xvnc scripts · bash
Xtigervnc :1 -localhost -SecurityTypes VncAuth -PasswordFile ~/.vnc/passwd

It stays in the foreground, so check it from a second terminal:

your own xvnc scripts · bash
sudo ss -tlnp | grep -E 'Xtigervnc|Xvnc'

The listener shows 127.0.0.1:5901 and [::1]:5901 and nothing on 0.0.0.0 or [::]. VncAuth alone is fine here because the SSH tunnel carries the encryption. Keep None, TLSNone and X509None out of -SecurityTypes, and use -rfbport -1 for a session nobody connects to over TCP.

Owners and credentials

Every server that keeps a VNC listener needs a named owner and a reason. For those, Rapid7's advice holds: a VPN or SSH tunnel in front, a patched server, a unique strong password per machine, and multifactor authentication where the product supports it. Keep root and other privileged accounts out of routine remote desktop sessions, and watch the server logs. Ubuntu 24.04's TigerVNC writes Connections: blacklisted: <address> when a source keeps failing.

Re-scan and prove it

Run the same scan from the same outside host, which must not sit on any allowlist, and ask the grepable file for anything still answering:

re-scan and prove it · bash
nmap -Pn -sV --script vnc-info -p 5500,5800-5999 -oA vnc-after <your-public-range>
grep -E '/open/tcp//vnc|5500/open' vnc-after.gnmap

No output is a pass. Each line that comes back names a host where a forward, an allow rule or an alternate-port listener survived. A port reported as Locked out still counts: TigerVNC blacklisted your scanner, and the block starts at 10 seconds by default, so wait and scan that port on its own. Re-run the full -p- sweep after the quick scan comes back clean. For 5500, trust ss on the host over the re-scan: a TigerVNC viewer in listen mode can exit after the first probe, so a clean port may only mean it already quit.

On the hosts, sudo ss -tlnp shows the VNC process on 127.0.0.1 and [::1] or not at all, Get-NetTCPConnection -State Listen no longer shows it on 0.0.0.0 or ::, and the ufw and firewalld output has no Anywhere rule, VNC service or VNC forward left.

What a port scan still can't see

A clean re-scan proves there's no direct TCP path from that outside host. It doesn't cover:

  • RealVNC cloud connections, which need no inbound port at all; AllowCloudRfb is the only switch for them.
  • IPv6 forwards in firewalld rich rules, and IPv6 addresses your range list left out.
  • UDP 5900, which a TCP scan never touches.
  • Listeners outside the ports you scanned, until the next -p- sweep.
  • Sources on your allowlist, which still reach the port by design.

Between scans, Shodan Monitor can watch your ranges in CIDR notation and tell you when something new shows up.

Any server you couldn't move to loopback, and couldn't name an owner for, is the one to switch off this week. Re-run vnc-after against the same range after every firewall, NAT or VNC change, so the next audit starts from a known-clean baseline.

FAQs

Is the Nmap vnc-title script appropriate for routine exposure scans?

No. Nmap files vnc-title under intrusive because it logs into the server to read the desktop name, using None authentication, credentials found by vnc-brute, or a RealVNC authentication bypass. Run it only in a test you're explicitly authorized to log in during.

Can devices other than desktop computers appear in a VNC exposure scan?

Yes. In Rapid7's 2020 scan, 19% of the servers found were Macs, and a few dozen multifunction printers exposed their admin interface over VNC. Macs answer on TCP 5900 because Screen Sharing and Apple Remote Desktop use it. Give each one an owner like any other host.

Should VNC client machines be included in the audit?

Yes. Most VNC viewers store saved passwords in a config file or the registry, encrypted with DES and a static key. Treat any password saved that way as readable by anyone who can read the file or registry key, and change it on the server if the client machine is shared or compromised.

community thread

Discuss this in the community

Questions about this, or a setup it does not cover? Ask in Security and Remote Access.

Security and Remote Access group

last active 2 Sep 2026, 11:07