Topology Mapping and Reachability
A list of hosts and ports says what exists. A topology says how it connects: which routers and firewalls sit between two machines, which networks each device touches, and therefore who can reach what. Most serious network findings are topology findings: "the database is reachable from the guest Wi-Fi", "the VPN lands users directly in the server network", "this dual-homed machine bridges two zones the firewall is supposed to separate". This lesson builds a topology from the data an assessor collects and asks it reachability questions with a graph library.
Where topology data comes from
| Source | Gives | Notes |
|---|---|---|
| Network diagrams and IPAM | the intended design | often outdated; treat as a claim to verify |
| Router and firewall configs (interfaces, routes, ACLs) | the real layer-3 design and the policy between networks | the most reliable source; requested as exports in scope |
traceroute / tracepath from several vantage points |
the routers on a path | ICMP may be filtered; load balancers and MPLS hide hops (ICMP, Ping and Traceroute) |
| LLDP / CDP neighbour tables, switch MAC tables | physical links, which device on which switch port | layer 2, inside one site |
Host data (ip addr, ip route on servers) |
multi-homed hosts with interfaces in several networks | the classic hidden bridge |
| Scans from different zones | what each zone can actually reach | the ground truth for policy |
A topology as a graph
The lab company has grown: the flat network of the intro is being split into zones. Here is the data an assessor collected (synthetic): networks, the devices that connect them, and the firewall's policy between zones. NetworkX turns it into a graph where nodes are networks and hosts, and edges are "can send packets to".
import networkx as nx
G = nx.DiGraph()
# Layer-3 links: which network each interface sits in (both directions).
links = [
("internet", "fw"), ("fw", "dmz 10.10.1.0/24"), ("fw", "servers 10.10.2.0/24"),
("fw", "staff 10.10.3.0/24"), ("fw", "guest 10.10.9.0/24"),
("dmz 10.10.1.0/24", "www"), ("servers 10.10.2.0/24", "db"), ("servers 10.10.2.0/24", "files"),
("staff 10.10.3.0/24", "ws05"), ("staff 10.10.3.0/24", "admin01"),
("guest 10.10.9.0/24", "guest-laptop"),
# The finding to be: a backup server with one interface in the DMZ and one in the servers network.
("dmz 10.10.1.0/24", "backup"), ("servers 10.10.2.0/24", "backup"),
]
for a, b in links:
G.add_edge(a, b); G.add_edge(b, a)
# The firewall only forwards what the policy allows: zone -> zone.
policy = {("internet", "dmz 10.10.1.0/24"), ("staff 10.10.3.0/24", "dmz 10.10.1.0/24"),
("staff 10.10.3.0/24", "servers 10.10.2.0/24"), ("dmz 10.10.1.0/24", "servers 10.10.2.0/24"),
("guest 10.10.9.0/24", "internet")}
zones = ["internet", "dmz 10.10.1.0/24", "servers 10.10.2.0/24", "staff 10.10.3.0/24", "guest 10.10.9.0/24"]
R = nx.DiGraph() # the graph of allowed forwarding
for a, b in G.edges:
if a == "fw" or b == "fw":
continue # replaced by the policy edges below
R.add_edge(a, b)
for src, dst in policy:
R.add_edge(src, dst)
def reach(src, dst):
return nx.has_path(R, src, dst)
print("internet -> db: ", reach("internet", "db"))
print("guest-laptop -> db: ", reach("guest-laptop", "db"))
print("internet -> www: ", reach("internet", "www"))
path = nx.shortest_path(R, "internet", "files")
print("internet -> files: ", " -> ".join(path))internet -> db: True
guest-laptop -> db: True
internet -> www: True
internet -> files: internet -> dmz 10.10.1.0/24 -> servers 10.10.2.0/24 -> files
The policy has no rule from the Internet to the server network, yet the graph answers True for internet -> db. Reachability here is in hops: each edge is "packets can flow", so a path means "an attacker who compromises each host on the way can continue". The shortest path uses the dmz → servers rule: break into a DMZ host and the database is one step further. The guest laptop is just as exposed, because guests reach the Internet and the Internet reaches the DMZ. Neither path appears in a port scan of a single zone, and there is a third one, through the dual-homed backup server with one interface in the DMZ and one in the server network, that the next program finds.
Questions the graph answers
import networkx as nx
R = nx.DiGraph()
edges = [("internet", "dmz"), ("staff", "dmz"), ("staff", "servers"), ("dmz", "servers"),
("guest", "internet"), ("dmz", "backup"), ("backup", "dmz"), ("servers", "backup"), ("backup", "servers")]
R.add_edges_from(edges)
print("reachable from internet:", sorted(nx.descendants(R, "internet")))
print("can reach servers: ", sorted(nx.ancestors(R, "servers")))
# Which single node, if removed, cuts the internet off from the servers zone?
cuts = [n for n in R.nodes if n not in ("internet", "servers")
and not nx.has_path(R.subgraph(set(R.nodes) - {n}), "internet", "servers")]
print("choke points internet -> servers:", cuts)
# Remove the dmz -> servers rule: is there still a path?
R2 = R.copy(); R2.remove_edge("dmz", "servers")
print("without the dmz->servers rule:", " -> ".join(nx.shortest_path(R2, "internet", "servers")))
R2.remove_node("backup")
print("and without the dual-homed backup:", nx.has_path(R2, "internet", "servers"))reachable from internet: ['backup', 'dmz', 'servers']
can reach servers: ['backup', 'dmz', 'guest', 'internet', 'staff']
choke points internet -> servers: ['dmz']
without the dmz->servers rule: internet -> dmz -> backup -> servers
and without the dual-homed backup: False
- Descendants of the Internet node are its exposure: everything an outside attacker can eventually reach by hopping.
- Ancestors of the server zone are everything that can touch it, which is the list of places you must monitor and harden.
- Choke points are where controls belong. Here the DMZ is one: every path from the Internet to the servers passes through it, so the DMZ hosts deserve the strictest controls.
- What-if edits show the effect of a fix before anyone changes a firewall: only removing both the policy rule and the bridge cuts the path.
The same idea at scale, with hosts, services and credentials as edges, is attack-path analysis, used for Active Directory in the planned Windows & Active Directory Security course.
How hidden paths are detected
- Compare
ip -br addron servers with the IPAM: any host with addresses in two zones is a bridge until proven otherwise; checknet.ipv4.ip_forward. - Scan from each zone into every other zone (within scope) and compare with the policy matrix; any unexpected reachability is a finding.
- Look for tunnels and VPN clients on servers, and for management interfaces (iDRAC, iLO, IPMI) connected to a different network than the host.
How they are fixed
- Remove dual homing where it isn't needed; where it is (backup networks, storage), make the second interface a dedicated, non-routed network with its own host firewall, and disable IP forwarding.
- Express the zone policy once, as a matrix, and generate firewall rules from it (Zones, DMZs and Trust Boundaries).
- Keep the topology as data (configs and inventory), not only as a drawing, so it can be queried like this.
Pitfalls
- Mapping only layer 3: a misconfigured switch trunk joins two VLANs below the firewall (VLAN Hopping).
- Trusting traceroute: firewalls often drop its probes and hide hops, and a missing hop is not a missing router.
- Forgetting management and out-of-band networks, which often reach everything.
- Treating "reachable" as "exploitable". Reachability is the precondition; the service on the far side decides the risk.
Practice
1. In the first program, remove ("dmz 10.10.1.0/24", "servers 10.10.2.0/24") from the policy. Does internet -> db become False?
No. The path now runs internet → DMZ → backup → servers → db, through the dual-homed backup server. Only removing the bridge as well cuts it, as the second program shows.
2. Why is a dual-homed host dangerous even when IP forwarding is off?
An attacker who compromises it can run their own tools on it and connect to the second network from there (pivoting). Forwarding off only stops it from routing other people's packets.
3. Which data would you request in scope to map the lab company's topology reliably?
Firewall and router configuration exports (interfaces, routes, rules, NAT), switch configs or LLDP neighbour tables, IPAM/DHCP data, and ip addr/ip route from servers; then verify with scans from each zone.
Test yourself
In the lab graph, which host bridges the DMZ and the server network?
- www
- db
- backup
- fw
What do nx.descendants(R, 'internet') represent?
- Everything that can reach the Internet
- Everything reachable from the Internet by following allowed edges
- The firewall rules
- The shortest path
Removing only the dmz->servers rule left a path. What else had to go?
- The guest network
- The dual-homed backup host (or its bridging)
- The Internet edge
- Nothing
Which source is most reliable for the real layer-3 policy between networks?
- The network diagram
- Traceroute from one laptop
- Router and firewall configuration exports
- DNS names