Unnecessary Exposed Services
Every listening service is code that strangers can send input to. A service nobody needs still has bugs, still needs patching, and is usually the one nobody patches, because nobody remembers it is there. "Unnecessary exposed services" heads most lists of network weaknesses for that reason: the cheapest vulnerability to fix is the one you remove. The usual suspects are database ports reachable from every desk, management interfaces (printer web pages, iLO/iDRAC, router admin pages) on user networks, development servers left running, and services bound to all interfaces when they only serve the local machine.
This lesson is the first of seven on the common weaknesses of a network. Each one goes: what it is, how to find it, how to fix it.
The mechanism
A service is exposed when three things line up: it listens on an address, the host firewall lets packets through, and the network routes and permits packets from the client to it. Remove any one and the exposure is gone. The most common root cause is the first: a server that binds to 0.0.0.0 (all IPv4 interfaces) or [::] (all IPv6 interfaces) when 127.0.0.1 would do.
Finding it on the host
On a host in scope, ss -tulnp lists the listeners (ss, ip and nftables). The session starts two web servers, one bound to loopback and one to all interfaces, plus a "debug" listener, and then runs a small checker that flags every listener on a wildcard address that isn't on the approved list.
python3 -m http.server 8000 --bind 127.0.0.1 >a.log 2>&1 &
python3 -m http.server 8080 --bind 0.0.0.0 >b.log 2>&1 &
ncat -lk 9229 >/dev/null 2>&1 &
for i in $(seq 50); do [ "$(ss -Htln | wc -l)" -ge 4 ] && break; sleep 0.1; done
echo "== listeners:"
ss -Htln | awk '{print $4}' | sort -t: -k2 -n
echo "== check:"
ss -Htln | awk '{print $4}' | python3 -c '
import sys
approved = {"8080"} # the one service this host is meant to offer to the network
for local in sorted(set(sys.stdin.read().split())):
addr, port = local.rsplit(":", 1)
wildcard = addr in ("0.0.0.0", "*", "[::]")
if not wildcard:
verdict = "local only"
elif port in approved:
verdict = "exposed, approved"
else:
verdict = "EXPOSED, NOT APPROVED"
print(f"{local:16} {verdict}")'
kill %1 %2 %3== listeners:
[::]:9229
127.0.0.1:8000
0.0.0.0:8080
0.0.0.0:9229
== check:
0.0.0.0:8080 exposed, approved
0.0.0.0:9229 EXPOSED, NOT APPROVED
127.0.0.1:8000 local only
[::]:9229 EXPOSED, NOT APPROVED
ncat -lk 9229 without an address listens on every IPv4 and IPv6 interface. Port 9229 is the Node.js inspector's default, a classic accidental exposure: a debugger port lets anyone who reaches it run code in the process.
Finding it from the network
From the network side the question is "what can each zone reach?", answered with the inventory scans of Nmap Inventories. The program compares the lab scan of the earlier lesson with the approved service matrix, the document that says which service is offered to whom.
scan = { # host -> open TCP ports seen from the staff network (lab scan 2026-02-03)
"fw.lab.test": {22, 53}, "www.lab.test": {22, 80, 443},
"mail.lab.test": {25, 143, 587}, "db.lab.test": {22, 5432},
"files.lab.test": {21, 445}, "10.10.0.77": {22, 80},
}
approved = { # host -> {port: who may use it}
"fw.lab.test": {22: "admins"}, "www.lab.test": {80: "everyone", 443: "everyone", 22: "admins"},
"mail.lab.test": {25: "everyone", 587: "staff", 143: "staff"},
"db.lab.test": {5432: "www only"}, "files.lab.test": {445: "staff"},
}
NOTES = {21: "FTP: cleartext, replace with SFTP", 53: "DNS on the firewall: resolver open to all?",
5432: "database reachable from staff desks", 22: "SSH reachable from staff, not only admins"}
for host in scan:
allowed = approved.get(host)
if allowed is None:
print(f"{host:15} UNKNOWN HOST, ports {sorted(scan[host])}: identify the owner")
continue
for port in sorted(scan[host]):
who = allowed.get(port)
if who is None:
print(f"{host:15} {port:>5} not approved {NOTES.get(port, '')}")
elif who not in ("everyone", "staff"):
print(f"{host:15} {port:>5} approved for {who:9} but reachable from staff: {NOTES.get(port, '')}")fw.lab.test 22 approved for admins but reachable from staff: SSH reachable from staff, not only admins
fw.lab.test 53 not approved DNS on the firewall: resolver open to all?
www.lab.test 22 approved for admins but reachable from staff: SSH reachable from staff, not only admins
db.lab.test 22 not approved SSH reachable from staff, not only admins
db.lab.test 5432 approved for www only but reachable from staff: database reachable from staff desks
files.lab.test 21 not approved FTP: cleartext, replace with SFTP
10.10.0.77 UNKNOWN HOST, ports [22, 80]: identify the owner
Each line is a draft finding. Note the difference between "not approved" (the service should not exist or should not listen here) and "approved for X but reachable from Y" (the service is legitimate, the reachability is too broad, which is a firewall or segmentation fix, not a service fix).
How it is detected over time
- Nightly scans from each zone diffed against the approved matrix; a new listener on a server is a ticket within a day.
- Host agents or configuration management reporting
ss -tulnoutput; alerts on new listening ports, especially on high ports. - Firewall logs: denied connection attempts to a port that suddenly start succeeding mean something changed.
How it is fixed
In order of preference:
- Remove the service: uninstall or
systemctl disable --nowit (Services). - Bind it narrowly:
listen_addresses = 'localhost'in PostgreSQL,bind 127.0.0.1in Redis,--bind 127.0.0.1in development servers, a dedicated management interface for admin pages. - Filter it: host firewall default deny with explicit allows, then network rules from the zones that need it (Firewalls).
- Require authentication for what remains, and keep the approved matrix up to date with an owner per line.
Pitfalls
- Fixing only the network firewall: the next network change re-exposes a service that listens on everything. Do both binding and filtering.
- Forgetting IPv6: a service bound to
[::]is reachable over IPv6 even when the IPv4 firewall is tight. - Containers:
docker run -p 5432:5432publishes on all host interfaces and Docker inserts its own firewall rules ahead of yours; publish as-p 127.0.0.1:5432:5432. - "It has a password" is not a reason to expose an admin interface to every network.
Practice
1. In the session, which listener would you fix by binding and which by removing?
8000 is already local. 8080 is approved and exposed on purpose. 9229 is a debugger port: remove it from production entirely (don't start Node with --inspect), or bind it to 127.0.0.1 and reach it through an SSH tunnel when debugging.
2. Add the host prn40.lab.test with ports 23, 80 and 9100 to scan and an approved entry {9100: "staff"}. What does the checker report?
23 (Telnet) and 80 (web admin page) as not approved. Fix: disable Telnet and the web interface on user networks, or move the printer's management to a management network.
3. Why is "approved for www only but reachable from staff" a different fix from "not approved"?
The service is needed, so it stays; the fix is to restrict who can reach it (firewall rule allowing only the web server's address to 5432, and segmentation), not to remove it.
Test yourself
Which three conditions together make a service exposed?
- It is old, slow and big
- It listens on an address, the host firewall allows it, and the network routes and permits traffic to it
- It has a banner, a version and a port
- It uses TCP
What does a listener on 0.0.0.0:8080 mean?
- It listens only on loopback
- It listens on all IPv4 interfaces
- It is closed
- It listens on IPv6 only
What is the preferred fix for an unneeded service?
- A firewall rule
- Removing or disabling the service
- Changing its port
- Hiding its banner
Why can docker run -p 5432:5432 surprise you?
- It doesn't publish the port
- It publishes on all host interfaces and Docker adds its own firewall rules
- It only works on IPv6
- It disables PostgreSQL authentication