This lab demonstrates a full 5-phase flow:
- Negotiation
- Attack path / downgrade
- Interception + packet dump
- Quantum break (Shor demo)
- Decryption summary
- Orchestration:
lab/scripts/09_quantum_mitm_flow.py - Logging + file output:
lab/lib/logging.py - Network namespace / tcpdump / packet send:
lab/lib/network.py - Weak crypto registry + Shor simulator path:
lab/lib/crypto.py - Runtime artifact collection and parsing:
lab/lib/evidence.py - MITM strategy transforms:
lab/lib/mitm.py
Design intent:
- Keep policy + sequencing in one script (
09_*). - Keep mechanisms in small focused modules (
lab/lib/*). - Keep evidence parsing independent from crypto simulation.
Follow these steps in order.
docker build -f docker/Dockerfile --build-arg LIBRESWAN_VERSION=5.3 -t pqc-lab-min .Quick verify after container starts:
docker exec pqc-lab bash -lc 'ipsec --version'docker rm -f pqc-lab 2>$null
docker run -d --privileged --name pqc-lab pqc-lab-min tail -f /dev/nulldocker exec -it pqc-lab bashdocker exec -it pqc-lab bashAll commands below are intended to run inside the container.
Creates alice <-> eve <-> bob namespaces and links.
TOPOLOGY_MODE=mitm bash lab/scripts/start_topology.shThis attempts real IKEv2 bring-up and writes immediate status/log snapshots.
bash lab/scripts/07_start_libreswan_ns.shRuns negotiation, downgrade, interception view, quantum break, and summary.
The script now prefers runtime evidence (status/log/tcpdump artifacts) for protocol selection, and only falls back to config/strategy parsing when no runtime evidence is found.
python3 lab/scripts/09_quantum_mitm_flow.py \
--mode mitm \
--strategy packet-drop \
--weak-algo xor-phi21 \
--message 'hello' \
--config lab/configs/ipsec.conf \
--no-live-captureCustomize packet count, interval, and payload content:
python3 lab/scripts/09_quantum_mitm_flow.py \
--mode mitm \
--strategy packet-drop \
--weak-algo xor-phi21 \
--message 'network-level' \
--packet-count 6 \
--packet-interval 0.1 \
--payload-override 'CUSTOM-DEMO-PAYLOAD' \
--config lab/configs/ipsec.conf \
--live-captureEnables real tcpdump parsing and prints packet metadata + payload extraction.
python3 lab/scripts/09_quantum_mitm_flow.py \
--mode mitm \
--strategy strip-pqc \
--weak-algo auto \
--message 'capture-me' \
--config lab/configs/ipsec.conf \
--live-captureShows raw packet bytes directly from Eve namespace.
First ensure namespaces exist in the current container session:
TOPOLOGY_MODE=mitm bash lab/scripts/start_topology.sh
ip netns listip netns exec eve tcpdump -X -A -n -v -i veth-eve-a udp port 500Open a second container terminal and run:
ip netns exec eve tcpdump -n -vv -X -A -l -i veth-eve-a udp port 500Then run Phase 6/6b/7 in terminal A and watch packets in real time in terminal B.
Open another terminal and run:
watch -n 1 "ip netns exec eve iptables -S FORWARD; echo; ip netns exec eve sysctl net.ipv4.ip_forward"This shows Eve's forwarding/drop rules live while the attack is running.
Reads the dump saved by the flow script.
cat /lab/lab/data/tcpdump_raw.txttail -n 200 /lab/lab/data/events.logLive view:
tail -f /lab/lab/data/events.logEach run creates a bundle under /lab/lab/data/runs/<timestamp>/, including:
ipsec_status_<ns>.txtpluto_log_<ns>.txtike_tcpdump_eve.txtprotocol_selection.txtprotocol_selection_source.txtkex_tokens.txt
ls -1 /lab/lab/data/runs
latest=$(ls -1 /lab/lab/data/runs | tail -n 1)
ls -1 "/lab/lab/data/runs/${latest}"
cat "/lab/lab/data/runs/${latest}/protocol_selection.txt"
cat "/lab/lab/data/runs/${latest}/protocol_selection_source.txt"Notes:
--no-live-captureprints a synthetic payload dump (CT:...+ hex + ASCII).--live-captureprints real capture details when namespaces are available.--packet-count,--packet-interval, and--payload-overridecontrol custom traffic from Alice to Bob.
python3 lab/scripts/09_quantum_mitm_flow.py \
--mode mitm \
--strategy packet-drop \
--weak-algo xor-phi21 \
--message 'network-level' \
--config lab/configs/ipsec.conf \
--no-live-capture 2>&1 | grep -E '^\[(VIEW|NEGOTIATION|FLOW|INTERCEPT|QUANTUM|SUMMARY)\]'... | grep '^\[NEGOTIATION\]'... | grep '^\[INTERCEPT\]'... | grep '^\[QUANTUM\]'... | grep '^\[VIEW\]'Current registered weak models:
xor-phi15(N=15, phi=8)shift-phi15(N=15, phi=8)xor-phi21(N=21, phi=12)xor-phi35(N=35, phi=24)
CLI:
python3 lab/scripts/09_quantum_mitm_flow.py --weak-algo auto
python3 lab/scripts/09_quantum_mitm_flow.py --weak-algo xor-phi21python -m unittest discover -s tests -vShell tests (also under tests/):
bash tests/test_all_algorithms.sh
bash tests/test_capture.sh
bash tests/test_tcpdump.shUse this script to produce a review-grade verdict:
python3 lab/scripts/10_prove_pqc_then_downgrade.pyBehavior:
- Exit
0: baseline shows runtime PQ negotiation evidence and downgrade run changes outcome to non-PQ. - Exit
2: UNPROVEN (no runtime PQ negotiation evidence in baseline). - Other non-zero: orchestration failure.
Artifacts are written under:
/lab/lab/data/proof-runs/<timestamp>/baseline/<run-id>//lab/lab/data/proof-runs/<timestamp>/downgrade/<run-id>/
This gate is intended for review and prevents claiming downgrade success without runtime PQ evidence.
- This is an educational toy model.
- Event logs are appended to
/lab/lab/data/events.loginside the running container. - For packet-drop strategy, container must include
iptablesand run with--privileged. - This workshop simulates downgrade pathways and observability around hybrid IKE/IPsec negotiation; it does not claim practical cryptanalysis of production PQC