Algorithmadvanced
Hash-based IP traceback
Also called SPIE, source path isolation engine.
Routers keep Bloom filters of digests of recent packets, so a single packet can be traced back by querying routers hop by hop.
- Solves
- IP traceback problem
- Time
- O(k(V + E)) worst · averageO(k) best
- Space
- O(V) extra
- Where
- E = the number of links; V = the number of routers; k = the number of hash functions; m = the bits in one digest table
- Model
- Word RAM
- Properties
- deterministicno false negativessingle packet
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Alex C. Snoeren, Craig Partridge, Luis A. Sanchez, Christine E. Jones, Fabrice Tchakountio, Stephen T. Kent, W. Timothy Strayer, 2001
Hash-based IP traceback, built as the Source Path Isolation Engine (SPIE), solves the single-packet version of the IP traceback problem. Each router stores a Bloom filter of digests of the packets it forwarded in a recent time window. To trace one packet, the victim's side asks the nearest router whether it saw the packet, and every router that answers yes asks its own neighbors, in a breadth-first search backward along the path. The answer never misses a router that forwarded the packet, and it may contain a few extra routers because of false positives.
In plain words
Every post office keeps a small sheet of tick boxes for each hour. For each letter it handles, it ticks a few boxes chosen by a secret rule from the letter's address and first line. It never writes the letter down.
When a harmful letter arrives, an investigator goes to the last office and asks: "are all the boxes for this letter ticked?" If yes, the letter probably passed there, and the investigator asks each office that sends mail to it. Offices that say no stop the search on that branch. An office that handled the letter always says yes. An office that did not may say yes by chance when its sheet is nearly full, so the answer can include a few wrong offices but never miss a right one.
The problem
Given one packet that reached a victim , and the time it arrived, output a set of routers that contains every router that forwarded (Snoeren et al., Section 2). The network is a graph of routers and links. The attacker chooses the contents of and of any other traffic, including forged source addresses. The routers on the path are not compromised, and their hash keys are secret. A router cannot store packets: it can afford a few bits per packet for a short time.
The algorithm
Each router has a digest table : a Bloom filter of bits with hash functions chosen at random by . The hash input is the part of the packet that routers do not change. When the table holds its capacity of packets, the router saves it with a time stamp and starts an empty one.
INSERT(T, x) ▷ router r forwards x- 1
for i ← 1 to k do - 2
T[h_{r,i}(invariant(x))] ← 1 QUERY(T, x)- 3
return T[h_{r,i}(invariant(x))] = 1 for every i in 1..k TRACE(G, v, x) ▷ reverse-path flooding from the victim- 4
found ← ∅, seen ← {v}, Q ← a queue holding v - 5
while Q is not empty do - 6
u ← the first node of Q, removed - 7
for each neighbor r of u with r not in seen do add r to seen - 8
if QUERY(T_r, x) for the table of the time x passed r then - 9
add r to found and to the end of Q - 10
return found
Line L8 uses the table that covered the time when could have passed . A router that answers no is not searched further, so the search stays close to the true path.
Example
Take the graph of the IP traceback problem page with links -, -, -, -, -, - and -. Each table has bits and functions, keyed by a secret of its router. Four background packets enter, two at and two at , and then the packet , from 198.51.100.7 to 192.0.2.1, enters at and takes the path . Then traces :
| step | asked by | router | positions of | bits at those positions | answer |
|---|---|---|---|---|---|
| 1 | 25, 14, 5 | 1, 1, 1 | yes | ||
| 2 | 17, 26, 9 | 1, 1, 1 | yes | ||
| 3 | 7, 16, 18 | 1, 1, 1 | yes | ||
| 4 | 7, 23, 26 | 0, 0, 1 | no | ||
| 5 | 27, 26, 8 | 0, 0, 1 | no | ||
| 6 | 19, 18, 12 | 1, 1, 1 | yes |
The answer is , the true path. is never asked, because said no. holds 2 packets, so its false-positive rate is ; holds 5 packets and has 14 of its 32 bits set. With the same graph and 18 background packets in 16-bit tables with , the tables are nearly full, and also answer yes, and the answer grows to six routers.
Correctness
Theorem (no false negatives). Assume that the routers on the path of are not compromised, that each recorded with INSERT, that no router changed the invariant fields, and that the query reaches each table before the router discards it. Then TRACE returns a set that contains every router on the path, against an attacker who chooses all packets. With exact sets in place of Bloom filters, TRACE returns exactly the routers that forwarded .
The proof is by induction along the path from : a Bloom filter has no false negatives, so each router on the path answers yes, and each one is a neighbor of the previous one, which also answered yes. With exact sets, only forwarders answer yes. The full proof is in proofs/correctness.md.
Theorem (extra routers; Snoeren et al., Section 7.1.1). If every router has at most neighbors and every table has a false-positive rate of at most , then the expected number of extra routers in the answer for a path of routers is at most . The paper calls its analysis simplistic: it assumes that the sets of neighbors of different nodes are disjoint and that the tables are full, so it is a worst-case bound for their model. For this gives , so at most extra routers on average for a path of 32. Their simulation on the topology of a tier-one ISP with about 70 backbone routers found far fewer false positives than the bound (measurement, Section 7.1.2).
Rate of one table (theorem for ideal hash functions). After packets in a table of bits with functions, a packet that was not inserted passes the query with probability (Section 7.2). With and this is 0.092; with 8 functions and it is 0.00314. For , and the formula gives 5.3%, and the tests measure 4.8% over 10,000 queries to 25 tables (measurement).
Proof: Correctness of hash-based IP tracebackfull
Setting. is a graph whose nodes are the victim and the routers. The packet took the path of routers, where is a neighbor of and is a neighbor of for . Each router has a table , a Bloom filter with functions, or an exact set in the oracle version. The attacker chooses and all other packets.
Assumptions. (A1) Each is not compromised and ran INSERT on in the table that TRACE asks. (A2) No router changed the fields that invariant(x) reads, so every router hashed the same input. (A3) In the oracle version, is the exact set of packets that forwarded.
Lemma 1 (Bloom filters have no false negatives). If INSERT ran on a table , then QUERY returns true at any later time.
Proof. Lines L1 and L2 set the positions to 1. No line sets a bit to 0, so they stay 1. Line L3 reads the same positions, because the functions and, by (A2), the input are the same, and returns true.
Lemma 2 (the search). A router is added to found by line L9 if and only if answers yes at line L8 and there is a sequence of neighbors in which all answer yes.
Proof. Only nodes in found, and , enter the queue , and only routers that answered yes enter found. Each router enters seen once and is asked at most once (line L7), and a router's answer does not depend on who asks, so the order of the search does not matter. If is added, the chain of the nodes that added each other back to is such a sequence. Conversely, suppose such a sequence exists, and let be the first node of the sequence after that is not in found. Then is or in found, so it entered and was removed at line L6. When it was removed, was either already in seen, which happens only when some node asked it, or asks it now. In both cases was asked once and answered yes, so it is in found, a contradiction.
Theorem 1 (no false negatives). Under (A1) and (A2), TRACE returns a set that contains .
Proof. By (A1) and Lemma 1, each answers yes. The sequence is a sequence of neighbors in which every router answers yes. By Lemma 2, is in found.
Theorem 2 (exact oracle). Under (A1) to (A3), TRACE returns exactly .
Proof. By (A3), a router answers yes if and only if it forwarded , that is, if and only if it is some . So found is contained in , and Theorem 1 gives the other inclusion.
Theorem 3 (one bit of a table). Assume that the hash values of the inserted packets are independent and uniform on . After packets other than were inserted into an empty table, a fixed position is 1 with probability .
Proof. The packets make independent uniform writes. A fixed position is missed by one write with probability , so it is missed by all of them with probability .
Remark (the rate of a query). QUERY returns true when all positions of are 1. If the bits were independent, the probability would be for distinct positions. This is the formula of Snoeren et al. (Section 7.2) and of the code, and it is an approximation: the bits are not independent, and positions of may coincide. The test of the code checks the approximation by measurement, not by proof. None of Theorems 1 and 2 depends on it.
Complexity
In the word RAM model, with one hash evaluation taken as for a fixed input length:
- Per packet at a router. INSERT costs time. The table needs bits for packets, so the cost is bits per packet, a constant set by the chosen false-positive rate.
- Per trace. TRACE asks each router at most once and looks at each link at most twice, so it takes time and extra space. In practice it touches only the routers near the path and their neighbors. The best case is : the router next to says no.
- Storage. Snoeren et al. (Section 7.2) estimate the storage at about 0.5% of the total link capacity of a router per unit of time (heuristic, for their chosen rate); for an OC-3 router with 4 links, about 47 MB per minute.
Properties
- One packet suffices. Unlike probabilistic packet marking, SPIE traces a single packet, such as one that crashed a host.
- No false negatives. A router on the path always answers yes, while its table is kept.
- Privacy. Routers keep digests, not packets, so a table does not reveal the traffic it saw; it only answers membership questions.
- Limited time. The answer depends on the tables still being kept, so a trace must start before the router discards the tables for the time of the packet.
- State in routers. Every router needs memory written at line rate, which is the price of single-packet tracing.
Variants and improvements
- The digest input. SPIE hashes the first 28 invariant bytes of a packet: the IP header with the type of service, TTL, checksum and options masked, plus the first 8 bytes of the payload (Section 4). On their traces, 28 bytes gave a rate of identical digests for distinct packets of 0.00092% in a wide-area trace and 0.139% in a local trace (measurement).
- Hash families. Section 4.3 uses a universal hash family, so that two different packets collide with probability for -bit outputs, with members chosen independently at each router. The prototype of Section 6 uses MD5 with a random input vector to produce four 32-bit digests, and changes the input vectors each time a table is paged. The code here uses keyed BLAKE2b in the same role, which is a heuristic for independence.
- Transformations. Routers that change a packet, for example by fragmentation, tunneling or network address translation, store a transform lookup table entry so that the trace can continue with the original packet (Section 5.3).
- Architecture. Data generation agents in the routers compute digests, SPIE collection and reduction agents gather tables for a region, and a SPIE traceback manager runs the query (Section 5.1).
- Counting filters. A counting Bloom filter allows deletion, so a router could remove old digests one by one instead of paging whole tables, at a cost of several bits per position.
When to use it
Use hash-based traceback when one packet, or a few, must be traced, and the routers can spend memory written at line rate. Use probabilistic packet marking when routers cannot keep state and the attack is a flood. Use ingress filtering to stop forged sources at the edge, which makes many traces unnecessary.
Pitfalls
- Hashing fields that change. If lines L2 and L3 hash the whole header, the TTL and checksum that each router changes make the victim's copy hash to different positions than the copy each upstream router stored, and line L3 answers no on the true path. Hash only invariant(x), as in lines L2 and L3.
- Flooding through every router. If line L9 adds every neighbor to , not only those that answered yes, the search visits the whole network and collects every false positive in it. Add to only when line L8 says yes.
- Full tables. If a table is not paged when it reaches its capacity, its bits fill up and line L3 answers yes for almost every packet; the example with 18 background packets shows the answer growing. Page the table when it holds packets, with fixed by the target rate.
- Shared hash keys. If all routers use the same functions in line L2, a packet that collides at one router tends to collide at its neighbors that saw the same traffic, and an attacker who learns the functions can craft collisions. Choose the functions at random per router and per table.
- Asking the wrong table. If line L8 asks the current table instead of the one that covered the time of , the trace misses routers after a page change. Use the arrival time and the path delay to pick the table.
Implementations
The code is a synthetic model: packets are tuples with documentation addresses, routers are names in a graph of at most 20 nodes, and nothing is sent. The tests compare TRACE with Bloom filters against TRACE with exact sets on 500 random graphs, check that the Bloom answer always contains the true path, and measure the false-positive rate of a table.
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hash-based-ip-traceback/. The authors are listed in prov/3RR23Q.jsonl.
"""Single-packet traceback with per-router Bloom filters of packet digests.
A synthetic model of SPIE (Snoeren et al., SIGCOMM 2001). Packets are tuples of
abstract fields with documentation addresses; routers are names in a small
graph given as an adjacency dict. No packet is built and no network is touched.
"""
from collections import deque
from hashlib import blake2b
from typing import Hashable, Mapping
Node = Hashable
# (source, destination, identification, ttl, payload)
Packet = tuple[str, str, int, int, bytes]
def invariant(x: Packet) -> bytes:
"""The fields that no router changes: the TTL is left out, and only the
first 8 bytes of the payload are kept, as in Section 4 of Snoeren et al.
Cost: O(1).
"""
src, dst, ident, _ttl, payload = x
return f"{src}|{dst}|{ident}|".encode() + payload[:8]
class DigestTable:
"""A Bloom filter of m bits with k keyed hash functions (one router, one time window)."""
def __init__(self, m: int, k: int, key: bytes) -> None:
"""Precondition: m >= 1, 1 <= k <= 255, len(key) <= 64. Cost: O(m)."""
self.m = m
self.k = k
self.key = key
self.bits = bytearray(m)
def indices(self, x: Packet) -> list[int]:
"""The k bit positions of x. Cost: O(k)."""
data = invariant(x)
return [
int.from_bytes(blake2b(bytes([i]) + data, key=self.key, digest_size=8).digest(), "big") % self.m
for i in range(self.k)
]
def insert(self, x: Packet) -> None:
"""Record that this router forwarded x. Cost: O(k)."""
for j in self.indices(x): # @line L1
self.bits[j] = 1 # @line L2
def query(self, x: Packet) -> bool:
"""True if x may have been forwarded; never False for a recorded x. Cost: O(k)."""
return all(self.bits[j] for j in self.indices(x)) # @line L3
def forward(path: list[Node], x: Packet, tables: Mapping[Node, DigestTable]) -> None:
"""Every router on path records x as it forwards it. Cost: O(k len(path))."""
for r in path:
tables[r].insert(x)
def trace(graph: Mapping[Node, list[Node]], v: Node, x: Packet, tables: Mapping[Node, "DigestTable | set"]) -> set[Node]:
"""Reverse-path flooding from the victim v (Section 5.4 of Snoeren et al.).
A neighbor is asked only by a node that answered yes (or by v), and it is
asked once. tables maps each router to a DigestTable or, for the exact
oracle, to a set of packets. Returns the routers that answered yes.
Cost: O(k (V + E)) for a graph with V nodes and E edges.
"""
found: set[Node] = set() # @line L4
seen = {v}
queue = deque([v])
while queue: # @line L5
u = queue.popleft() # @line L6
for r in graph[u]: # @line L7
if r in seen or r not in tables:
continue
seen.add(r)
t = tables[r]
if (x in t) if isinstance(t, set) else t.query(x): # @line L8
found.add(r) # @line L9
queue.append(r)
return found # @line L10
def false_positive_rate(m: int, k: int, n: int) -> float:
"""(1 - (1 - 1/m)^(k n))^k: the chance that a packet not inserted passes the
query after n insertions, for independent uniform hash functions.
"""
return (1 - (1 - 1 / m) ** (k * n)) ** k
test_hash_based_ip_traceback.py 148 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/hash-based-ip-traceback/. The authors are listed in prov/3RR23Q.jsonl.
import random
from collections import deque
from hash_based_ip_traceback import DigestTable, false_positive_rate, forward, invariant, trace
G = {
"V": ["R1"],
"R1": ["V", "R2"],
"R2": ["R1", "R3", "R4"],
"R3": ["R2", "R5", "R6"],
"R4": ["R2", "R7"],
"R5": ["R3"],
"R6": ["R3"],
"R7": ["R4"],
}
ROUTES = {
"R5": ["R5", "R3", "R2", "R1"],
"R6": ["R6", "R3", "R2", "R1"],
"R7": ["R7", "R4", "R2", "R1"],
}
X = ("198.51.100.7", "192.0.2.1", 4242, 60, b"example payload")
def example_tables() -> dict:
tables = {r: DigestTable(32, 3, f"key-{r}".encode()) for r in G if r != "V"}
for i in range(4):
src = ("R5", "R7")[i % 2]
forward(ROUTES[src], (f"203.0.113.{i + 1}", "192.0.2.1", i + 1, 64, b"background"), tables)
forward(ROUTES["R6"], X, tables)
return tables
def test_example() -> None:
t = example_tables()
assert t["R4"].indices(X) == [7, 23, 26]
assert [t["R4"].bits[j] for j in (7, 23, 26)] == [0, 0, 1]
assert [t["R5"].bits[j] for j in t["R5"].indices(X)] == [0, 0, 1]
assert sum(t["R1"].bits) == 14 and sum(t["R4"].bits) == 6
assert trace(G, "V", X, t) == {"R1", "R2", "R3", "R6"}
exact = {r: set() for r in G if r != "V"}
for r in ROUTES["R6"]:
exact[r].add(X)
assert trace(G, "V", X, exact) == {"R1", "R2", "R3", "R6"}
assert abs(false_positive_rate(32, 3, 2) - 0.00522) < 1e-5
assert abs(false_positive_rate(32, 3, 5) - 0.05439) < 1e-5
def test_edges() -> None:
t = DigestTable(64, 4, b"k")
assert not t.query(X)
t.insert(X)
assert t.query(X)
# A router decrements the TTL; the digest does not change.
y = X[:3] + (17,) + X[4:]
assert invariant(y) == invariant(X) and t.query(y)
# Payload bytes after the first 8 are not part of the digest.
assert invariant(X[:4] + (b"example other",)) == invariant(X)
one = DigestTable(1, 3, b"k")
one.insert(("192.0.2.9", "192.0.2.1", 1, 64, b""))
assert one.query(X) # a full table answers yes to everything
assert trace({"V": []}, "V", X, {}) == set()
empty = {r: DigestTable(32, 3, f"key-{r}".encode()) for r in G if r != "V"}
assert trace(G, "V", X, empty) == set()
# Different keys give different positions (independence across routers).
assert example_tables()["R1"].indices(X) != example_tables()["R2"].indices(X)
def random_graph(rng: random.Random, n: int) -> dict:
names = ["V"] + [f"R{i}" for i in range(1, n)]
g = {a: set() for a in names}
for i in range(1, n):
j = rng.randrange(0, i)
g[names[i]].add(names[j])
g[names[j]].add(names[i])
for _ in range(rng.randrange(0, n)):
a, b = rng.sample(names[1:], 2) if n > 2 else (names[0], names[-1])
if a != b:
g[a].add(b)
g[b].add(a)
return {a: sorted(b) for a, b in g.items()}
def route_to(g: dict, src: str) -> list:
"""The shortest path from src to V, without V, by breadth-first search from V."""
parent = {"V": None}
q = deque(["V"])
while q:
u = q.popleft()
for r in g[u]:
if r not in parent:
parent[r] = u
q.append(r)
path = [src]
while parent[path[-1]] != "V":
path.append(parent[path[-1]])
return path
def test_random_graphs() -> None:
"""Exact sets give the path exactly; Bloom filters give a superset with no false negatives."""
rng = random.Random(2001)
supersets = 0
for trial in range(500):
n = rng.randrange(2, 21)
g = random_graph(rng, n)
routers = [r for r in g if r != "V"]
keys = {r: rng.randbytes(16) for r in routers}
m = rng.choice((16, 32, 64))
k = rng.randrange(1, 4)
bloom = {r: DigestTable(m, k, keys[r]) for r in routers}
exact = {r: set() for r in routers}
for i in range(rng.randrange(0, 8)):
y = (f"203.0.113.{rng.randrange(1, 255)}", "192.0.2.1", 10000 + i, 64, rng.randbytes(8))
p = route_to(g, rng.choice(routers))
forward(p, y, bloom)
for r in p:
exact[r].add(y)
x = (f"198.51.100.{rng.randrange(1, 255)}", "192.0.2.1", trial, 64, rng.randbytes(8))
path = route_to(g, rng.choice(routers))
forward(path, x, bloom)
for r in path:
exact[r].add(x)
assert trace(g, "V", x, exact) == set(path)
got = trace(g, "V", x, bloom)
assert set(path) <= got <= set(routers)
for r in got: # every yes is a forwarder or a false positive of its own filter
assert x in exact[r] or bloom[r].query(x)
supersets += got != set(path)
assert supersets > 0 # the oracle comparison exercised false positives
def test_false_positive_rate() -> None:
"""The measured rate matches (1 - (1 - 1/m)^(k n))^k for m = 256, k = 3, n = 40."""
rng = random.Random(7)
m, k, n = 256, 3, 40
hits = queries = 0
for t in range(25):
table = DigestTable(m, k, rng.randbytes(16))
for i in range(n):
table.insert(("203.0.113.1", "192.0.2.1", i, 64, rng.randbytes(8)))
for i in range(400):
queries += 1
hits += table.query(("198.51.100.1", "192.0.2.1", i, 64, rng.randbytes(8)))
rate = hits / queries
assert abs(rate - false_positive_rate(m, k, n)) < 0.015
History
Logging of whole packets for traceback was known to be too costly for fast routers, as Savage et al. noted in 2000. Snoeren, Partridge, Sanchez, Jones, Tchakountio, Kent and Strayer at BBN Technologies replaced logs by Bloom filters of digests and described the Source Path Isolation Engine, with a prototype, at SIGCOMM 2001. The journal version followed in 2002. Bloom described the filter in 1970.
References
- Alex C. Snoeren, Craig Partridge, Luis A. Sanchez, Christine E. Jones, Fabrice Tchakountio, Stephen T. Kent and W. Timothy Strayer, Hash-based IP traceback, ACM SIGCOMM 2001, pages 3 to 14, doi:10.1145/964723.383060, Section 2 (goals and transformations), Section 4 (digests of the invariant bytes, Bloom filters and hash families), Section 5 (the architecture and the traceback process, with reverse-path flooding in Section 5.4), Section 6 (the prototype) and Section 7 (the analysis of false positives and of storage)
- Alex C. Snoeren, Craig Partridge, Luis A. Sanchez, Christine E. Jones, Fabrice Tchakountio, Beverly Schwartz, Stephen T. Kent and W. Timothy Strayer, Single-packet IP traceback, IEEE/ACM Transactions on Networking 10(6), pages 721 to 734, December 2002, the journal version of the same system
- Burton H. Bloom, Space/time trade-offs in hash coding with allowable errors, Communications of the ACM 13(7), 1970, the Bloom filter and its error rate
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 3RR23Q Edit this page History Report an error Markdown