summaryrefslogtreecommitdiff
path: root/crafted-pkt/make-tcp.py
blob: 8f6bb0031f3657a608828b63071fc7a820fffed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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)