-
Notifications
You must be signed in to change notification settings - Fork 10
/
generate-sctp-segments.py
executable file
·82 lines (63 loc) · 2.59 KB
/
generate-sctp-segments.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python2.7
'''
MIT License
Copyright (c) 2019 Orange CERT-CC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'''
from scapy.all import *
def sctp_segment(pkt, fragsize=42):
'''harder: clone packets and generate segmentation at SCTP level.
As a bonus, it will evade equipements performing IP reassembly.'''
assert(IP in pkt)
assert(SCTP in pkt)
assert(SCTPChunkData in pkt)
data_chunk = pkt[SCTPChunkData]
assert(data_chunk.beginning == 1)
assert(data_chunk.ending == 1)
total_length = data_chunk.len
data = data_chunk.data
tsn = data_chunk.tsn
for o in range(0, len(data), fragsize):
new_pkt = pkt.copy()
new_pkt[IP].len = None
new_pkt[IP].chksum = None
new_pkt[SCTP].chksum = None
new_pkt[SCTPChunkData].beginning = 0
new_pkt[SCTPChunkData].ending = 0
new_pkt[SCTPChunkData].data = data[o:o+fragsize]
new_pkt[SCTPChunkData].len = None
new_pkt[SCTPChunkData].tsn = tsn + o//fragsize
if o == 0:
new_pkt[SCTPChunkData].beginning = 1
elif o + fragsize >= len(data):
new_pkt[SCTPChunkData].ending = 1
new_pkt[SCTPChunkData].data = data[o:]
yield new_pkt
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('input', help='input filename, expected to a pcap file, containing a single packet containing IP/SCTP/M3UA/SCCP layers')
parser.add_argument('output', help='output filename')
args = parser.parse_args()
pkts = rdpcap(args.input)
assert(len(pkts) == 1)
pkt = pkts[0]
assert(IP in pkt)
assert(SCTP in pkt)
assert(SCTPChunkData in pkt)
pkts = sctp_segment(pkt)
wrpcap(args.output, pkts)