summaryrefslogtreecommitdiff
path: root/crafted-pkt
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-09-17 16:04:33 +0200
committerPeter Wu <peter@lekensteyn.nl>2016-09-17 16:04:33 +0200
commitc77414b056e7c9bcc91c9256b463c75e4992e076 (patch)
treee23d42c40a783875154991f022ea479c05f8cb66 /crafted-pkt
parent38366ff8bd0c0d6e5e48acdfe2b8ca8cebe390d8 (diff)
downloadwireshark-notes-c77414b056e7c9bcc91c9256b463c75e4992e076.tar.gz
make-tcp.py: create a crafted packet with TCP issues
Prompted by https://code.wireshark.org/review/17749
Diffstat (limited to 'crafted-pkt')
-rwxr-xr-xcrafted-pkt/make-tcp.py56
1 files changed, 56 insertions, 0 deletions
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)