<gh_stars>0
import argparse

import scapy.all

from helpers import xor_data

parser = argparse.ArgumentParser()
parser.add_argument("input", help="The source capture file to solve.")
args = parser.parse_args()

packets = scapy.all.rdpcap(args.input)
for packet in packets:
    ip_packet = packet.getlayer('IP')
    if ip_packet and ip_packet.dport == 433:
        raw_payload = ip_packet.getlayer('TCP').payload
        if not raw_payload:
            continue

        tcp_payload = bytes(raw_payload)
        key = tcp_payload[:4]
        print("Key", key.hex())

        raw_length = xor_data(tcp_payload[len(key): len(key) + 4], key)
        length = int.from_bytes(raw_length, 'big')
        print("Length", length)

        base_length = len(key) + len(raw_length)
        data = xor_data(tcp_payload[base_length: base_length + length], key)
        print("Data", data.decode('utf-8'))

import argparse

import scapy.all

from helpers import xor_data

parser = argparse.ArgumentParser()
parser.add_argument("input", help="The source capture file to solve.")
args = parser.parse_args()

packets = scapy.all.rdpcap(args.input)
for packet in packets:
    ip_packet = packet.getlayer('IP')
    if ip_packet and ip_packet.dport == 433:
        raw_payload = ip_packet.getlayer('TCP').payload
        if not raw_payload:
            continue

        tcp_payload = bytes(raw_payload)
        key = tcp_payload[:4]
        print("Key", key.hex())

        raw_length = xor_data(tcp_payload[len(key): len(key) + 4], key)
        length = int.from_bytes(raw_length, 'big')
        print("Length", length)

        base_length = len(key) + len(raw_length)
        data = xor_data(tcp_payload[base_length: base_length + length], key)
        print("Data", data.decode('utf-8'))