From c066832f52b8a9d2ab03270349377b1170b67ec5 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Thu, 19 Oct 2023 09:22:23 +0200 Subject: [PATCH] add pcap_fix_udp_len.py and remove turn example --- sipp/README.md | 10 +++++++--- sipp/pcap_fix_udp_len.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100755 sipp/pcap_fix_udp_len.py diff --git a/sipp/README.md b/sipp/README.md index e24e180..18cc731 100644 --- a/sipp/README.md +++ b/sipp/README.md @@ -19,7 +19,7 @@ sudo build/sipp -sf scenarios/uac_pcap.xml 127.0.0.1 -m 1 ### Manipulating -Reorder +#### Reorder ```bash editcap -r g711a.pcap tmp1 2-3 # dump packets 2-3 @@ -27,9 +27,13 @@ editcap -r -t 0.07 g711a.pcap tmp2 1 # dump packet 1 and manipulate timestamp editcap g711a.pcap tmp3 1-3 # exclude packets 1-3 mergecap -w out.pcap -a tmp1 tmp2 tmp3 ``` - -Drop +#### Drop ```bash editcap g711a.pcap out.pcap 2-3 # drop packets 2-3 ``` + +#### Remove TURN (4 Bytes, Offset 42 Bytes) encapsulation + +editcap -L -C42:4 in.pcap tmp.pcap +./pcap_fix_udp_len.py tmp.pcap out.pcap 4 diff --git a/sipp/pcap_fix_udp_len.py b/sipp/pcap_fix_udp_len.py new file mode 100755 index 0000000..e4eab18 --- /dev/null +++ b/sipp/pcap_fix_udp_len.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import argparse +from scapy.all import * + +def update_bytes_from_packet(packet, rbytes): + if UDP in packet: + # Check if the packet contains a UDP layer + packet[UDP].len = packet[UDP].len - int(rbytes) + packet[IP].len = packet[IP].len - int(rbytes) + packet[UDP].chksum = None # Recalculate UDP checksum + packet[IP].chksum = None # Recalculate IP checksum + +def main(): + parser = argparse.ArgumentParser(description="Update IP/UDP length.") + parser.add_argument("input_file", help="Input PCAP file") + parser.add_argument("output_file", help="Output PCAP file") + parser.add_argument("rbytes", help="bytes to remove") + + args = parser.parse_args() + + # Load the PCAP file + packets = rdpcap(args.input_file) + + for packet in packets: + update_bytes_from_packet(packet, args.rbytes) + + # Save the modified PCAP file + wrpcap(args.output_file, packets) + + print("PCAP file successfully modified and saved as", args.output_file) + +if __name__ == "__main__": + main()