Skip to content
Extraits de code Groupes Projets
Valider fcface94 rédigé par François De Keersmaeker's avatar François De Keersmaeker
Parcourir les fichiers

Funtion fuzz_pcaps can now take a single file as parameter

parent 732a9c64
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -10,3 +10,6 @@ dist ...@@ -10,3 +10,6 @@ dist
# Temp files # Temp files
*.log *.log
csv csv
# Package build script
build_and_publish.sh
...@@ -2,14 +2,18 @@ ...@@ -2,14 +2,18 @@
Randomly edit packet fields in a PCAP file. Randomly edit packet fields in a PCAP file.
""" """
## Import libraries
import os import os
import argparse import argparse
from typing import Union
import random import random
import logging import logging
import csv import csv
# Scapy libraries
import scapy.all as scapy import scapy.all as scapy
from scapy.layers import dhcp, dns, http from scapy.layers import dhcp, dns, http
from scapy.contrib import coap, igmp, igmpv3 from scapy.contrib import coap, igmp, igmpv3
# Custom Packet utilities
from packet.Packet import Packet from packet.Packet import Packet
...@@ -45,7 +49,7 @@ def must_edit_packet(i: int, packet_numbers: list, random_range: int) -> bool: ...@@ -45,7 +49,7 @@ def must_edit_packet(i: int, packet_numbers: list, random_range: int) -> bool:
return is_specified or is_random return is_specified or is_random
def fuzz_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers: list = None, dry_run: bool = False) -> None: def fuzz_pcaps(pcaps: Union[str, list], output: str, random_range: int = 1, packet_numbers: list = None, dry_run: bool = False) -> None:
""" """
Main functionality of the program: Main functionality of the program:
(Randomly) edit packet fields in a (list of) PCAP file(s). (Randomly) edit packet fields in a (list of) PCAP file(s).
...@@ -56,6 +60,8 @@ def fuzz_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers: ...@@ -56,6 +60,8 @@ def fuzz_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers:
:param packet_numbers: list of packet numbers to edit (starting from 1) :param packet_numbers: list of packet numbers to edit (starting from 1)
:param dry_run: if True, do not write output PCAP file :param dry_run: if True, do not write output PCAP file
""" """
# If input PCAP is a single file, convert to list of one element
pcaps = [pcaps] if isinstance(pcaps) != list else pcaps
# Loop on given input PCAP files # Loop on given input PCAP files
for input_pcap in pcaps: for input_pcap in pcaps:
...@@ -160,6 +166,9 @@ if __name__ == "__main__": ...@@ -160,6 +166,9 @@ if __name__ == "__main__":
if args.output is not None and len(args.input_pcaps) > 1: if args.output is not None and len(args.input_pcaps) > 1:
logging.warning("Multiple input PCAP files specified, ignoring output PCAP file name.") logging.warning("Multiple input PCAP files specified, ignoring output PCAP file name.")
print(args.input_pcaps)
exit()
### MAIN PROGRAM ### ### MAIN PROGRAM ###
fuzz_pcaps( fuzz_pcaps(
......
...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages ...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name='pcap_fuzzer', name='pcap_fuzzer',
version='0.1.0', version='0.2.0',
author='François De Keersmaeker', author='François De Keersmaeker',
author_email='francois.dekeersmaeker@uclouvain.be', author_email='francois.dekeersmaeker@uclouvain.be',
description='Randomly edit packet fields in a PCAP file.', description='Randomly edit packet fields in a PCAP file.',
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter