]> git.somenet.org - pub/jan/netsec2.git/blob - exercise2/task2/decode_ipid.py
add decoder
[pub/jan/netsec2.git] / exercise2 / task2 / decode_ipid.py
1 #!/usr/bin/env python
2
3 # disable IPv6 error message
4 import logging
5 logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
6 from scapy.all import *
7 logging.getLogger("scapy.runtime").setLevel(logging.WARN)
8 from pprint import pprint
9
10 # disable payload parsing (saves two seconds runtime^^)
11 IP.payload_guess = []
12
13 bytes = bytearray()
14
15 for p in PcapReader('large_flow.pcap'):
16     if IP in p:
17         src = p[IP].src
18         dst = p[IP].dst
19         id = p[IP].id
20
21         bin = "{0:016b}".format(id)
22         upper = int(bin[0:8], 2)
23         lower = int(bin[8:16], 2)
24         print ("Upper: %s, Lower: %s" % (bin[0:8], bin[8:16]))
25         print ("Full: %s" % (bin))
26         bytes.append(upper)
27         bytes.append(lower)
28
29 with open('stream_encrypted', 'a+') as encfile:
30     encfile.write(bytes)
31