Asset Inventory and Attack-Surface Mapping
At the end of reconnaissance a tester has a pile of facts: names from DNS and certificates, addresses, a few banners, technology guesses, notes from the client's documentation. Testing time is limited, so the pile has to become a map: which assets exist, which services each exposes, who can reach each service, and which paths lead to what the client cares about most. That map decides where the days go. This lesson turns an asset inventory into a small graph model in Python and asks it the questions a test plan needs answered.
Attack Vectors and the Attack Surface introduced the idea and a weighted count of entry points. Here the surface becomes a reachability graph, which can express what a flat list can't: a database that is not exposed to the Internet may still be two steps from it.
From inventory to graph
An asset inventory for a test lists, per asset: name, address, zone, role, services (port, product, version if known), authentication, data held, and the source of each fact (DNS, CT, client documentation, later the scan). The attack-surface map adds reachability: which zones can open connections to which services, from the firewall rules or the client's network diagram.
As a graph:
- nodes are network positions (the Internet, a workstation, a server) and the services on them;
- edges mean "can open a connection to" (from the firewall rules) or "a compromise of this service gives a foothold on this host";
- attributes carry what matters for prioritising: authentication, exposure, known weaknesses, data value.
The lab network as a model
The lab below is the one used in the course's mini project. Its addresses are in 10.10.0.0/24; the facts are what recon and the client's documentation gave before any scan.
import networkx as nx
G = nx.DiGraph()
hosts = { # host: (address, zone, data value 0-3)
"internet": (None, "internet", 0),
"www": ("10.10.0.10", "dmz", 1),
"mail": ("10.10.0.25", "dmz", 2),
"vpn": ("10.10.0.5", "dmz", 1),
"ws17": ("10.10.0.117", "office", 1),
"files01": ("10.10.0.21", "servers", 2),
"jenkins": ("10.10.0.62", "servers", 2),
"db01": ("10.10.0.40", "servers", 3),
}
services = [ # (service id, host, port, product, auth)
("www:443", "www", 443, "nginx + PHP shop", "none"),
("mail:25", "mail", 25, "Postfix", "none"),
("mail:443", "mail", 443, "webmail", "password"),
("vpn:443", "vpn", 443, "VPN portal", "password+mfa"),
("files01:445", "files01", 445, "SMB share", "password"),
("jenkins:8080","jenkins", 8080, "Jenkins", "none"),
("db01:5432", "db01", 5432, "PostgreSQL", "password"),
("ws17:3389", "ws17", 3389, "RDP", "password"),
]
for h, (addr, zone, value) in hosts.items():
G.add_node(h, kind="host", zone=zone, addr=addr, value=value)
for sid, h, port, product, auth in services:
G.add_node(sid, kind="service", host=h, product=product, auth=auth)
G.add_edge(sid, h, why="foothold if compromised")
# reachability from the firewall rules the client supplied
reach = {"internet": ["www:443", "mail:25", "mail:443", "vpn:443"],
"www": ["db01:5432"],
"vpn": ["ws17:3389", "files01:445", "jenkins:8080"],
"ws17": ["files01:445", "jenkins:8080", "mail:443"],
"jenkins": ["db01:5432", "files01:445"]}
for src, dsts in reach.items():
for d in dsts:
G.add_edge(src, d, why="can connect")
exposed = [s for s in G.successors("internet")]
print("Internet-facing services:", ", ".join(exposed))
print("unauthenticated anywhere:", ", ".join(s for s, a in G.nodes(data="auth") if a == "none"))
print()
for target in ["db01", "files01"]:
path = nx.shortest_path(G, "internet", target)
hops = [p for p in path if G.nodes[p]["kind"] == "service"]
print(f"shortest route to {target} (value {G.nodes[target]['value']}): {' -> '.join(path)}")
print(f" services to break on the way: {len(hops)}: {', '.join(hops)}")
print()
fanout = {s: len(nx.descendants(G, s) & {h for h, k in G.nodes(data='kind') if k == 'host'})
for s, k in G.nodes(data="kind") if k == "service"}
print("hosts reachable after compromising each service:")
for s, n in sorted(fanout.items(), key=lambda kv: (-kv[1], kv[0])):
print(f" {s:<13} {n} ({G.nodes[s]['auth']})")Internet-facing services: www:443, mail:25, mail:443, vpn:443
unauthenticated anywhere: www:443, mail:25, jenkins:8080
shortest route to db01 (value 3): internet -> www:443 -> www -> db01:5432 -> db01
services to break on the way: 2: www:443, db01:5432
shortest route to files01 (value 2): internet -> vpn:443 -> vpn -> files01:445 -> files01
services to break on the way: 2: vpn:443, files01:445
hosts reachable after compromising each service:
vpn:443 6 (password+mfa)
ws17:3389 5 (password)
jenkins:8080 3 (none)
www:443 2 (none)
db01:5432 1 (password)
files01:445 1 (password)
mail:25 1 (none)
mail:443 1 (password)
The model gives the test plan its order:
jenkins:8080stands out: no authentication, reachable from every VPN user and from the office, and a compromise of it reaches the database and the file server. Unauthenticated CI servers are a classic finding, and here the graph shows why it matters even though it is not on the Internet.- The shop on
www:443is the only unauthenticated Internet service, and the web server may connect todb01. Web testing of the shop goes first among the external tests, and the report will want to know whether the web tier's database account can read more than it needs. - The VPN is protected by MFA; its value is that everything internal sits one hop behind it, so its configuration (who gets VPN access, from where) deserves review rather than attack.
Notice what the model doesn't know yet: real versions, whether the firewall rules match reality, whether services exist that nobody documented. Scanning and enumeration (the next section) check and extend it, and the graph is updated with each finding.
How the defender uses the same map
An attack-surface graph is a defensive tool first. Security teams build it from the inventory and the firewall configuration and ask the same questions continuously:
- Exposure drift: a new edge from
internet(a new firewall rule, a new cloud security group) is an alert. - Path analysis: which single change cuts the most routes to the crown jewels? In this model, requiring authentication on Jenkins and limiting
www's database access each remove a short route. - Unknown nodes: anything the scan finds that the inventory lacks is a process failure (shadow IT, an unrecorded change).
The same reasoning at directory scale is how tools for Active Directory attack paths work; the Windows & Active Directory Security course builds one.
How surface is reduced
Remove services nobody needs; put authentication in front of every administrative interface (CI servers, dashboards, databases); restrict reachability to what each role needs (the office doesn't need Jenkins' web UI, only the developers' VPN group does); and segment so that a compromised edge service reaches as little as possible. Each reduction is an edge or node removed from the graph, which is how to show its effect in a report.
Pitfalls
- Mapping only the Internet edge. Most impact comes from the second and third hop.
- Trusting the documented firewall rules. The scan is the test of the documentation; mismatches are findings.
- Treating every path as equal. Weight edges by difficulty (authentication, MFA, known weaknesses) when there are many paths.
- Forgetting identities. Network reachability is half the map; accounts and their rights (who can log in where) are the other half, and they are usually the shorter route.
Practice
- Give Jenkins
auth="password"and rerun. Does the shortest route todb01change? What does that tell you about the model? - Which connections must the firewall block so that no route from the Internet can connect to
db01:5432? Usenx.minimum_edge_cut(G, "internet", "db01:5432").
Answers
- Authentication on Jenkins doesn't change the graph's shape, only the difficulty of a node: the shortest path is still
internet -> www:443 -> www -> db01:5432 -> db01(two services). The model would need edge weights for difficulty to show the improvement, which is the pitfall above. - Two edges: there are two edge-disjoint routes (through the web server, and through the VPN and Jenkins), so every cut needs one edge on each route. The function returns one of several minimum cuts; the most useful for a recommendation is the pair closest to the asset,
www -> db01:5432andjenkins -> db01:5432, because blocking them leaves every other service working. Two firewall changes protect the database: the kind of conclusion a report can recommend precisely.
Test yourself
Why model the attack surface as a graph rather than a list of exposed services?
- Graphs are faster
- A graph shows multi-step routes: an unexposed database can still be two hops from the Internet
- Lists can't hold ports
- Scanners output graphs
In the model, why is jenkins:8080 a top priority although it isn't Internet-facing?
- It runs on port 8080
- It is unauthenticated, reachable from VPN users and the office, and leads to db01 and files01
- Jenkins is always vulnerable
- It holds the most data
What should happen when the scan finds a service that isn't in the inventory?
- Ignore it
- Add it to the map (if in scope) and report the inventory gap
- Delete it
- Assume it is a false positive