What it is
Exposed ports are TCP or UDP services reachable from the public internet that should only be available to specific clients or internal networks. Common offenders are databases, admin panels, cache servers, and debug endpoints left bound to 0.0.0.0.
Why it matters
Every open port is an attack surface that gets brute forced, fingerprinted, and probed continuously. Closing or restricting ports removes whole classes of credential stuffing and exploit attempts before they reach the application.
How it is exploited
Unintended open ports expose admin panels, debug endpoints, legacy services with default credentials, and unauthenticated database listeners directly to the internet. Attackers fingerprint the service and version, then brute force credentials, replay known exploits, or connect straight into the data layer with no auth at all. A single compromised service often becomes a pivot point for deeper movement into the internal network.
How to fix it
- Inventory what is listening. Run a port scan from outside your network and compare it to ss -tlnp or netstat on each host. The diff between expected and actual is your remediation list.
- Lock down with a host firewall. Use ufw, iptables, or nftables to default-deny inbound traffic and allow only the ports your service truly needs. Bind services to a private interface or localhost when an external client never needs to reach them.
- Narrow cloud security groups. In AWS, GCP, or Azure, tighten security groups and firewall rules to specific source CIDRs and ports. Avoid 0.0.0.0/0 on management ports like SSH, RDP, and database listeners.
- Verify from the outside. Re-scan from an unauthenticated network to confirm the closed ports no longer respond. Schedule recurring scans so a future deploy or security-group edit does not silently re-expose the service.
Examples by platform
ufw
sudo ufw default deny incoming; sudo ufw allow 443/tcpiptables
sudo iptables -P INPUT DROP
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPTAWS security group
aws ec2 revoke-security-group-ingress --group-id sg-0123456789abcdef0 --protocol tcp --port 22 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 --protocol tcp --port 22 --cidr 10.0.0.0/16