Consider a cloud virtual machine spun up on a Friday by a developer at an illustrative Bengaluru start-up. It runs a web application on 443, SSH on 22 for administration, a MongoDB database on 27017 because the app needs one, and an admin dashboard on 8080 that someone set up for testing. The security group allows all four from anywhere because “it was easier while we debugged”. By Monday, automated internet scanners will almost certainly have found every one of those ports. Only one of them, 443, was meant to be public.

That scenario is the whole topic in miniature. A port is just a number, but an open port is a promise: “send bytes here and a program will read them.” Every such promise is a piece of attack surface.

What a port actually is

An IP address gets a packet to a machine. A port number, a 16-bit value from 0 to 65535 carried in the TCP or UDP header, gets it to the right program on that machine. When a server application starts, it asks the operating system to “listen” on a port. From then on, the operating system hands any incoming connection for that port to that program.

TCP and UDP ports are separate. TCP 53 and UDP 53 are different doors, even though DNS uses both. IANA divides the range into three bands: well-known ports from 0 to 1023, registered ports from 1024 to 49151, and dynamic or private ports from 49152 to 65535. These are conventions, not enforcement. Nothing prevents SSH from running on port 2222 or a web server on 8443; port numbers indicate what a service probably is, never what it definitely is.

The other end: ephemeral ports

When your laptop connects to a website, it also uses a port, chosen temporarily by the operating system from an ephemeral range. Linux commonly uses 32768 to 60999 by default; modern Windows uses the IANA dynamic range. Each connection is identified by four values: source IP, source port, destination IP and destination port. This is why a firewall rule allowing “outbound to port 443” must also allow the replies coming back to a random high port, and why stateful firewalls, which track connections, made rule-writing so much simpler.

A common beginner confusion in firewall logs is seeing traffic “to port 51734” and assuming something strange is listening there. Usually it is just the client side of an ordinary connection.

Three risks behind every listening service

Each open port exposes the software behind it to anyone who can reach it. That creates three separate risks.

Vulnerabilities in the service. If the program has a flaw in how it parses input, an attacker can trigger it remotely. Several of the worst worms in history, including WannaCry in 2017, spread through an SMB flaw on port 445 on machines that should never have exposed SMB to untrusted networks.

Weak or missing authentication. Many databases and caches historically shipped with authentication off by default because they were assumed to sit on private networks. Exposed instances of Elasticsearch, MongoDB and Redis have led to large data leaks without any exploit at all; the data was simply readable.

Credential guessing. Login services such as SSH on 22 and RDP on 3389 face constant automated password attempts the moment they are internet-reachable. Exposed RDP has been a frequent entry point for ransomware groups.

Ports attackers look for first

PortUsual serviceWhy exposure worries defenders
22 / 3389SSH / RDPDirect remote control if credentials are guessed or stolen
445SMB file sharingHistory of wormable flaws, credential relay risks
1433 / 3306 / 5432SQL Server / MySQL / PostgreSQLDatabases should rarely be reachable from the internet
6379 / 27017 / 9200Redis / MongoDB / ElasticsearchOften deployed without authentication
23 / 21Telnet / FTPCredentials sent in clear text
161 (UDP)SNMPDefault community strings leak device configuration

This is not a complete list, and a service on an unusual port is not safer for it. Scanners fingerprint services by how they respond, not by port number. Moving SSH to a high port reduces log noise from lazy bots, but it is not a control.

Reducing the surface

Back to the start-up’s virtual machine. A sensible fix works at three levels.

  • Do not run what you do not need. The test dashboard on 8080 should be switched off, not just firewalled. A service that is not listening cannot be attacked.
  • Bind to the right interface. The database only needs to accept connections from the application. Configured to listen on localhost or a private interface, it is unreachable from outside regardless of firewall mistakes.
  • Filter at the network. The security group allows 443 from anywhere and nothing else. Administrative access goes through a VPN, a bastion host or the cloud provider’s session manager, with SSH restricted to those sources.

Defence in depth matters here. If someone later loosens the security group by mistake, the database still is not exposed because it is not listening publicly.

Knowing your own exposure

Attackers learn what you expose using internet-wide scanning and public search engines that index service banners. Defenders should know it first. That means an asset inventory that includes cloud accounts, regular external scans of all public IP ranges, and alerts when a new port appears. Comparing “what we think is open” with “what a scan says is open” regularly surfaces forgotten test servers, vendor-managed devices and services opened during an outage and never closed.

Internally, the same logic applies. An attacker who compromises one laptop will scan the internal network next. Workstations rarely need to accept SMB or RDP connections from other workstations, so blocking that peer-to-peer traffic removes easy paths for lateral movement at almost no cost to users.

Written by the RP Strativa Team. The start-up and its server configuration are illustrative.

Leave a Reply

Trending