Cleaning code
This commit is contained in:
parent
0f513c0403
commit
a5f0a9d65c
|
@ -5,22 +5,27 @@ from __future__ import print_function
|
|||
# LoRa PHYdecoder - parse LoRa PHY decoded by gr-lora
|
||||
# Copyright (C) 2020 Sebastien Dudek (@FlUxIuS) at @PentHertz
|
||||
|
||||
import binascii
|
||||
from layers.loraphy2wan import *
|
||||
from layers import LoRa
|
||||
from scapy.layers.inet import UDP
|
||||
from scapy.sendrecv import sniff
|
||||
import argparse
|
||||
|
||||
|
||||
def decodePHY(pkt):
|
||||
decoded = LoRa(pkt[UDP].load)
|
||||
print (repr(decoded))
|
||||
|
||||
|
||||
def filterpkt(pkt, port):
|
||||
if pkt.haslayer(UDP):
|
||||
if pkt[UDP].dport == port:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='Monitor and decode MAC PHY packets.')
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Monitor and decode MAC PHY packets.')
|
||||
parser.add_argument('-p', '--port', dest='port', default=40868,
|
||||
help='TAP PORT to listen on (default: UDP 40868)')
|
||||
parser.add_argument('-i', '--iface', dest='iface', default='lo',
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
from layers.loraphy2wan import *
|
|
@ -5,6 +5,7 @@ from Crypto.Cipher import AES
|
|||
from Crypto.Hash import CMAC
|
||||
import binascii
|
||||
|
||||
|
||||
def JoinAcceptPayload_decrypt(key, hexpkt):
|
||||
"""
|
||||
Decrypt Join Accept payloads
|
||||
|
@ -16,6 +17,7 @@ def JoinAcceptPayload_decrypt(key, hexpkt):
|
|||
cipher = AES.new(key, AES.MODE_ECB)
|
||||
return cipher.encrypt(payload) # logic right? :D
|
||||
|
||||
|
||||
def JoinAcceptPayload_encrypt(key, hexpkt):
|
||||
"""
|
||||
Encrypts Join Accept Payload
|
||||
|
@ -27,6 +29,7 @@ def JoinAcceptPayload_encrypt(key, hexpkt):
|
|||
cipher = AES.new(key, AES.MODE_ECB)
|
||||
return cipher.decrypt(payload)
|
||||
|
||||
|
||||
def getPHY_CMAC(key, hexpkt, direction=1):
|
||||
"""
|
||||
Compute MIC with AES CMAC
|
||||
|
@ -43,6 +46,7 @@ def getPHY_CMAC(key, hexpkt, direction=1):
|
|||
toret = cobj.update(payload).hexdigest()
|
||||
return toret[:8]
|
||||
|
||||
|
||||
def checkMIC(key, hexpkt, direction=1):
|
||||
"""
|
||||
Check MIC in the packet
|
||||
|
@ -56,7 +60,7 @@ def checkMIC(key, hexpkt, direction=1):
|
|||
mic = hexpkt[-6:-2] # skip the CRC
|
||||
try:
|
||||
binascii.unhexlify(mic)
|
||||
except:
|
||||
except Exception:
|
||||
mic = binascii.hexlify(mic)
|
||||
cmic = getPHY_CMAC(key, hexpkt)
|
||||
return (mic == cmic)
|
||||
|
|
Loading…
Reference in New Issue