with open('secret.key', 'rb') as my_private_key: key = my_private_key.read() h = hmac.new(key, apdu, hashlib.sha256) if (h.digest() == mac): f = Fernet(key) apdu_unen = f.decrypt(apdu) i = i.load[:11] + apdu_unen packet[UDP].remove_payload() packet[UDP].add_payload(i) else: print("Compromised Data") break g = goose.GOOSE(packet.load) pl1 = packet.load[:39] # print (type(pl1)) # print (repr(g.load)) gpdu = goose.GOOSEPDU(g.load[31:]) print(gpdu.__dict__) stnum = gpdu.__dict__['stNum'].data if (stnum != prev_stnum): if (stnum < prev_stnum): print("Discard because smaller state", stnum) prevt = gpdu.__dict__['t'].data continue age = gpdu.__dict__['t'].data - prevt if (abs(age) > 640000):
prev_stnum = -1 prevt = -1 while (True): t = sniff(iface=your_iface, count=1, filter="udp and host 10.220.64.207 and port 49153") # lfilter=lambda x: x.haslayer(UDP)) # and x[IP].src == broad_ip) t[0].show() # print (len(t[0].load)) # print (len(t[0][UDP])) # print (len(t[0][IP])) # print (len(t[0][Ether])) # print (type(t)) g = goose.GOOSE(t[0].load) pl1 = t[0].load[:39] # print (type(pl1)) # print (repr(g.load)) gpdu = goose.GOOSEPDU(g.load[31:]) print("The R-GOOSE payload is decoded as- ") print(gpdu.__dict__) try: stnum = gpdu.__dict__['stNum'].data except Exception as e: print("************************************") print() print(" DECODING ERROR") print() print("Key not found : ", e) print()
from scapy.all import * import goose a = rdpcap("wireshark2.pcap") for i in a: try: if i.type == 0x88b8: g = goose.GOOSE(i.load) print repr(g.load) gpdu = goose.GOOSEPDU(g.load[4:]) print gpdu.__dict__ except AttributeError: continue