Attack Vectors and the Attack Surface
An attacker needs only one way in; a defender has to know all of them. Most organisations that are breached through a forgotten system didn't lose a battle against a clever exploit: they lost track of a test server, an old FTP service or an API version that should have been switched off years ago. This lesson is about seeing every way in, measuring it and making it smaller.
Intuition: doors and windows
Count the doors and windows of a building, note which face the street and which have locks, and you have its attack surface. A building with one guarded entrance is easier to protect than one with twenty unlocked side doors, even if each door is ordinary. Software is the same: every open port, login page, API endpoint, file upload, email inbox and remote-support tool is a door.
Definitions
| Term | Meaning |
|---|---|
| Attack vector | the route or method used to reach a vulnerability: email, an exposed service, a web form, stolen credentials, a software update, a USB stick, a phone call |
| Entry point | one concrete place where input from outside enters a system: a listening port, a URL path, a mailbox, an upload form |
| Attack surface | the sum of all entry points (and the code and data behind them) that an attacker could reach |
| Digital surface | network services, applications, APIs, cloud resources, exposed credentials |
| Physical surface | offices, devices, ports on devices, removable media |
| Human surface | people who can be persuaded or tricked: staff, contractors, help desks (social engineering) |
| External / internal surface | reachable from the internet / only from inside the network |
The on-ramp lists the common vectors with their defences. Here we measure the surface.
Measuring a surface from an inventory
You can't count what you haven't listed. The starting point is an inventory of entry points with, for each, how exposed it is and what protects it. The program gives every entry point a rough weight (internet-facing counts three times an internal one, no authentication three times MFA), then applies three common reductions:
# A synthetic inventory of entry points for one small company (lab names only).
entry_points = [
# name, exposure, authentication, still needed
("www.lab.test :443 shop", "internet", "none", True),
("www.lab.test /admin", "internet", "password", True),
("vpn.lab.test :443", "internet", "mfa", True),
("old-ftp.lab.test :21", "internet", "password", False),
("api.lab.test /v1 (legacy)", "internet", "api-key", False),
("staff email", "internet", "mfa", True),
("file share :445", "internal", "password", True),
("printer web UI :80", "internal", "none", True),
("db01 :5432", "internal", "password", True),
]
WEIGHT = {"internet": 3, "internal": 1}
AUTH = {"none": 3, "password": 2, "api-key": 2, "mfa": 1}
def score(points):
return sum(WEIGHT[e] * AUTH[a] for _, e, a, _ in points)
def show(title, points):
internet = sum(1 for p in points if p[1] == "internet")
unauth = sum(1 for p in points if p[2] == "none")
print(f"{title:<7} entry points {len(points)} internet-facing {internet} unauthenticated {unauth} weighted score {score(points)}")
show("before", entry_points)
after = [p for p in entry_points if p[3]] # 1. remove what is not needed
after = [(n, e, "mfa" if n.endswith("/admin") else a, k) for n, e, a, k in after] # 2. MFA on the admin page
after = [(n, e, "password" if n.startswith("printer") else a, k) for n, e, a, k in after] # 3. printer password
show("after", after)
print("removed:", ", ".join(p[0].split()[0] for p in entry_points if not p[3]))before entry points 9 internet-facing 6 unauthenticated 2 weighted score 40
after entry points 7 internet-facing 4 unauthenticated 1 weighted score 24
removed: old-ftp.lab.test, api.lab.test
The weights are invented for the example; the habit is not. The biggest drop came from deleting two services nobody needed, which costs nothing and removes every vulnerability they would ever have. The one unauthenticated entry point left is the public shop, which is meant to be public: attack-surface work is about making exposure deliberate, not zero.
Seeing the network surface of one machine
On a single host, the network surface is the set of listening sockets and the addresses they are bound to. A service bound to 127.0.0.1 is reachable only from the machine itself; one bound to 0.0.0.0 (all IPv4 interfaces) is reachable from every network the machine is on. The session below runs in your sandbox, which has no network at all: it starts three listeners itself, lists them with ss, and checks them from the outside with an Nmap connect scan of 127.0.0.1 only. Scanning machines you don't own or have permission to test can be an offence in many countries, and it is never part of this track (Authorization and Scope).
python3 -m http.server 8000 --bind 127.0.0.1 >web.log 2>&1 &
python3 -m http.server 8080 --bind 0.0.0.0 >web2.log 2>&1 &
ncat -lk 127.0.0.1 9000 >/dev/null 2>&1 &
for i in $(seq 50); do curl -s -o /dev/null http://127.0.0.1:8080/ && curl -s -o /dev/null http://127.0.0.1:8000/ && break; sleep 0.1; done
ss -tln | head -1
ss -tln | tail -n +2 | sort -k4
nmap -sT -p 8000,8080,9000,9001 127.0.0.1
kill %1 %2 %3State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 5 0.0.0.0:8080 0.0.0.0:*
LISTEN 0 5 127.0.0.1:8000 0.0.0.0:*
LISTEN 0 10 127.0.0.1:9000 0.0.0.0:*
Starting Nmap 7.94SVN ( https://nmap.org ) at 2026-11-22 09:47 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000071s latency).
PORT STATE SERVICE
8000/tcp open http-alt
8080/tcp open http-proxy
9000/tcp open cslistener
9001/tcp closed tor-orport
Nmap done: 1 IP address (1 host up) scanned in 0.02 seconds
Read the ss lines by their Local Address column: 127.0.0.1:8000 and 127.0.0.1:9000 are local-only, 0.0.0.0:8080 would accept connections from any network the host is attached to. That one line is the difference between a developer's private test server and an exposed service. Nmap confirms the view from a client: three ports open, 9001 closed (the host answered, nothing listens there). The same scan from another machine would see only 8080. ss -tlnp would add the owning process for each socket; on a real server you run it with sudo to see every process. The commands are covered in depth in ss and ports.
How surface growth is detected
- Inventory drift: compare today's list of hosts, ports and URLs with yesterday's. A new open port or a new subdomain is an event worth a ticket.
- External view: scan your own public address ranges from outside on a schedule (with written approval, even for your own organisation's ranges), and watch Certificate Transparency logs and DNS for names you didn't know about.
- Host view: alert when a process starts listening on
0.0.0.0that is not on the approved list. - Cloud and SaaS: list public storage buckets, public IP addresses and third-party apps with access to company data; most surprises today live there.
How it is reduced
- Remove what isn't needed: services, accounts, old API versions, test systems, unused software and features.
- Restrict reachability: bind to
127.0.0.1or an internal interface, put admin interfaces behind a VPN or an identity-aware proxy, filter with a firewall. - Require strong authentication on what must stay reachable (MFA, keys instead of passwords).
- Harden what remains: patches, secure defaults, minimal privileges for each service.
- Own it: every entry point has an owner who can say why it exists.
Pitfalls
- Only counting ports. Email, help-desk phones, OAuth apps, CI pipelines and laptops are surface too.
- Forgetting IPv6. A service can be filtered on IPv4 and wide open on
[::]. - "It's internal, so it's safe." Internal entry points are reachable by anyone who gets in through phishing; the printer with no password is a foothold.
- Treating the inventory as a one-off. Surfaces grow every week; an inventory from last year is a historical document.
Practice
- In the session, which listener would another computer on the same network be able to reach, and how would you change the command so it can't?
- In the inventory example, MFA is added to the VPN that already has it, and
db01moves to a network only the web server can reach (count it as authenticationmfafor the weights). What is the new weighted score, starting from 24? - List three entry points of your own home network that are not listening ports.
Answers
- Only port 8080, bound to
0.0.0.0. Start it with--bind 127.0.0.1(or don't start it at all). - The VPN is unchanged (3).
db01goes from to , so the score is 23. The weight only drops by one, which says the score is crude; restrictingdb01's reachability is still worth more than the number suggests. - For example: the router's admin page and its Wi-Fi itself, email accounts of the family, smart-TV and phone apps, cloud photo storage, a USB port on a shared computer.
Test yourself
ss -tln shows a listener on 0.0.0.0:8080. What does that mean?
- It is reachable only from the same machine
- It accepts connections on every IPv4 interface of the machine
- It is closed
- It listens only on IPv6
Which change reduced the weighted score the most in the inventory example?
- MFA on the admin page
- Removing the two unneeded services
- A password on the printer
- None: all three were equal
Nmap reports a port as closed. What does that tell you?
- A firewall dropped the probe
- The host answered, but no service listens on that port
- The service needs a password
- The port is open on IPv6
Which of these is part of the human attack surface?
- An open SSH port
- A help desk that resets passwords over the phone
- A public storage bucket
- An old API version