summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2018-11-08 20:27:25 +0900
committerjaseg <git@jaseg.net>2018-11-08 20:27:25 +0900
commit9252eac84058f48410cb38c65a6f30bee2bc2b89 (patch)
tree9ee39f3fbb9770e24b83a7edd8331845b833f508
parent21be46a0b5364c5f00f4d081ad9524ae9a36d022 (diff)
downloadsecure-hid-9252eac84058f48410cb38c65a6f30bee2bc2b89.tar.gz
secure-hid-9252eac84058f48410cb38c65a6f30bee2bc2b89.tar.bz2
secure-hid-9252eac84058f48410cb38c65a6f30bee2bc2b89.zip
Add proof-of-concept packet loss recovery through nonce search
-rwxr-xr-xhexnoise.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/hexnoise.py b/hexnoise.py
index 1b8a304..31d7695 100755
--- a/hexnoise.py
+++ b/hexnoise.py
@@ -38,8 +38,8 @@ def send_packet(ser, data, width=16):
def receive_packet(ser, width=16):
packet = ser.read_until(b'\0')
data = cobs.decode(packet[:-1])
- print(f'\033[93mReceived {len(data)} bytes\033[0m')
- hexdump(print, data, width)
+ #print(f'\033[93mReceived {len(data)} bytes\033[0m')
+ #hexdump(print, data, width)
return data
if __name__ == '__main__':
@@ -55,6 +55,7 @@ if __name__ == '__main__':
ser = serial.Serial(args.serial, args.baudrate)
from noise.connection import NoiseConnection, Keypair
+ from noise.exceptions import NoiseInvalidMessage
STATIC_LOCAL = bytes([
0xbb, 0xdb, 0x4c, 0xdb, 0xd3, 0x09, 0xf1, 0xa1,
@@ -80,8 +81,29 @@ if __name__ == '__main__':
print('Handshake finished, handshake hash:')
hexdump(print, proto.get_handshake_hash(), args.width)
- while True:
- data = proto.decrypt(receive_packet(ser, args.width))
- print('Decrypted data:')
- hexdump(print, data, args.width)
+ def noise_rx(received):
+ data = proto.decrypt(received)
+ #print('Decrypted data:')
+ #hexdump(print, data, args.width)
+ while True:
+ try:
+ received = receive_packet(ser, args.width)
+ try:
+ noise_rx(received)
+ except NoiseInvalidMessage as e:
+ orig_n = proto.noise_protocol.cipher_state_decrypt.n
+ print('Invalid noise message', e)
+ for n in [orig_n+1, orig_n+2, orig_n+3]:
+ try:
+ proto.noise_protocol.cipher_state_decrypt.n = n
+ noise_rx(received)
+ print(f' Recovered. n={n}')
+ break
+ except NoiseInvalidMessage as e:
+ pass
+ else:
+ print(' Unrecoverable.')
+ proto.noise_protocol.cipher_state_decrypt.n = orig_n
+ except Exception as e:
+ print('Invalid framing:', e)