| import os | |
| import time | |
| import json | |
| from run_servers import start_all_servers, load_config | |
| from scanner import discovery_probe, loop_probe | |
| from clustering import ( | |
| cluster_discovery_responses, | |
| representative_payloads, | |
| cluster_loop_probe_results | |
| ) | |
| from graph_builder import build_graph, find_cycles, extract_candidates, draw_graph | |
| from verifier import verify_pair | |
| def main(): | |
| os.makedirs("outputs", exist_ok=True) | |
| config = load_config("configs/servers_vulnerable.json") | |
| server_configs = config["servers"] | |
| start_all_servers("configs/servers_vulnerable.json") | |
| time.sleep(1) | |
| print("\n=== Step 1: Discovery Probe ===") | |
| discovery_results = discovery_probe(server_configs) | |
| for row in discovery_results: | |
| print( | |
| row["server"], | |
| "input:", | |
| row["input_packet"].summary(), | |
| "response:", | |
| row["response_packet"].summary() if row["response_packet"] else "NO_RESPONSE" | |
| ) | |
| print("\n=== Step 2: Clustering ===") | |
| clusters = cluster_discovery_responses(discovery_results) | |
| for cluster, packets in clusters.items(): | |
| print(cluster, "count:", len(packets)) | |
| print("\n=== Step 3: Loop Probe ===") | |
| payloads = representative_payloads(clusters) | |
| loop_results = loop_probe(server_configs, payloads) | |
| print("\n=== Step 4: Transitions ===") | |
| transitions = cluster_loop_probe_results(loop_results) | |
| for t in transitions: | |
| print(t["server"], ":", t["from"], "->", t["to"]) | |
| print("\n=== Step 5: Loop Graph ===") | |
| graph, edge_servers = build_graph(transitions) | |
| for edge, servers in edge_servers.items(): | |
| print(edge, "by", servers) | |
| cycles = find_cycles(graph, max_len=5) | |
| print("\n=== Cycles Found ===") | |
| for c in cycles: | |
| print(c) | |
| draw_graph(graph, edge_servers) | |
| print("\n=== Loop Candidates ===") | |
| candidates = extract_candidates(cycles, edge_servers) | |
| for c in candidates: | |
| print(c) | |
| print("\n=== Step 6: Controlled Attack Test ===") | |
| verification_results = [] | |
| if candidates: | |
| from clustering import classify | |
| for idx, (cycle, server_a, server_b) in enumerate(candidates, start=1): | |
| print("\n" + "=" * 70) | |
| print(f"Candidate {idx}: {server_a} <-> {server_b}") | |
| print("Cycle:") | |
| for node in cycle: | |
| print(" ", node) | |
| initial_cluster = cycle[0] | |
| initial_packet = None | |
| for packet in payloads: | |
| if classify(packet) == initial_cluster: | |
| initial_packet = packet | |
| break | |
| if initial_packet is None: | |
| print("[!] Could not find representative payload for initial cluster.") | |
| verification_results.append({ | |
| "candidate_id": idx, | |
| "server_a": server_a, | |
| "server_b": server_b, | |
| "cycle": [str(node) for node in cycle], | |
| "confirmed": False, | |
| "reason": "No representative payload found for initial cluster.", | |
| "trace": [] | |
| }) | |
| continue | |
| confirmed, trace = verify_pair( | |
| server_a, | |
| server_b, | |
| initial_packet, | |
| server_configs, | |
| max_steps=12 | |
| ) | |
| print(f"\nTesting pair: {server_a} <-> {server_b}") | |
| for row in trace: | |
| print( | |
| f"Step {row['step']}: " | |
| f"{row['server']} received {row['input']} -> sent {row['output']}" | |
| ) | |
| if confirmed: | |
| print("\n[!] Loop confirmed.") | |
| else: | |
| print("\n[-] Loop stopped.") | |
| verification_results.append({ | |
| "candidate_id": idx, | |
| "server_a": server_a, | |
| "server_b": server_b, | |
| "cycle": [str(node) for node in cycle], | |
| "initial_cluster": str(initial_cluster), | |
| "initial_packet": initial_packet.summary(), | |
| "confirmed": confirmed, | |
| "steps_observed": len(trace), | |
| "trace": trace | |
| }) | |
| print("\n=== Verification Summary ===") | |
| for result in verification_results: | |
| status = "CONFIRMED" if result["confirmed"] else "STOPPED" | |
| print( | |
| f"Candidate {result['candidate_id']}: " | |
| f"{result['server_a']} <-> {result['server_b']} : {status}" | |
| ) | |
| verification_output_path = "outputs/verification_results.json" | |
| with open(verification_output_path, "w", encoding="utf-8") as f: | |
| json.dump(verification_results, f, indent=2, ensure_ascii=False) | |
| print(f"\n[+] Verification results saved to {verification_output_path}") | |
| else: | |
| print("No candidate found.") | |
| if __name__ == "__main__": | |
| main() |
Xet Storage Details
- Size:
- 5.16 kB
- Xet hash:
- fa9def318b68753fae2063b068d79f64467d4a8a7b51926cbfbebb0000004c6b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.