From c77414b056e7c9bcc91c9256b463c75e4992e076 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 17 Sep 2016 16:04:33 +0200 Subject: make-tcp.py: create a crafted packet with TCP issues Prompted by https://code.wireshark.org/review/17749 --- crafted-pkt/make-tcp.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 crafted-pkt/make-tcp.py (limited to 'crafted-pkt') diff --git a/crafted-pkt/make-tcp.py b/crafted-pkt/make-tcp.py new file mode 100755 index 0000000..8f6bb00 --- /dev/null +++ b/crafted-pkt/make-tcp.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python2 +# Create a crafted TCP stream with errors +# Usage: make-tcp.py [output.pcap] + +import sys +from scapy.all import * + +pkts = [] +def send(data, flags='A'): + if pkts: + last = pkts[-1][TCP] + seqno = last.seq + len(last.payload) + else: + seqno = 100 + tcp = TCP(sport=32323, dport=9, flags=flags, seq=seqno)/data + pkt = IP(dst='10.0.0.2',src='10.0.0.1') / tcp + pkts.append(pkt) + return pkt + +# data for one side +lines = [ + 'First\n', + 'Second\n', + 'Third\n', + 'Fourth\n', + 'Fifth\n', + 'Sixth\n', + 'Last\n' +] +for line in lines: + send(line) +send('', flags='F') # FIN + +# Errorneous packets +numbers = [ + 1, + 1, # duplicate packet + 2, + 4, # out-of-order (2) + 3, # out-of-order (1) + 5, + #6, # missing packet + 7, + 0, # FIN (last packet) +] + +# normal packets +#numbers = range(1, len(pkts)+1) + +pkts2 = [pkts[i-1] for i in numbers] + +# Show packets and write to file +for pkt in pkts2: + print(pkt.summary()) +if len(sys.argv) > 1: + wrpcap(sys.argv[1], pkts2) -- cgit v1.2.1