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

Replaced 'tweak' -> 'fuzz'. Removed unused imports.

parent aaee38da
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -4,8 +4,8 @@ EXITCODE=0
for pcap in $GITHUB_WORKSPACE/traces/*.pcap
do
# Run pcap_tweaker script on pcap file
python3 $GITHUB_WORKSPACE/src/pcap_tweaker.py $pcap
# Run pcap_fuzzer script on pcap file
python3 $GITHUB_WORKSPACE/src/pcap_fuzzer.py $pcap
# If the exit code is not 0, set EXITCODE to 1
if [[ $? -ne 0 ]]
then
......
# pcap-tweaker
# pcap-fuzzer
This program randomly edits packets from a PCAP file,
one field per edited packet.
......@@ -22,7 +22,7 @@ pip install -r requirements.txt
## Usage
```bash
python3 pcap_tweaker.py [-h] [-o OUTPUT] [-r RANDOM_RANGE] [-n PACKET_NUMBER] [-d] pcap [pcap ...]
python3 pcap_fuzzer.py [-h] [-o OUTPUT] [-r RANDOM_RANGE] [-n PACKET_NUMBER] [-d] pcap [pcap ...]
```
The program produces new PCAP file with the same name as the input files,
......
import scapy.all as scapy
from packet.Packet import Packet
class ARP(Packet):
......
import logging
from typing import Tuple
import random
import scapy.all as scapy
from scapy.layers import dhcp
from packet.Packet import Packet
class BOOTP(Packet):
......@@ -61,13 +59,13 @@ class BOOTP(Packet):
self.dhcp_options.setfieldval("options", dhcp_options)
def tweak(self) -> dict:
def fuzz(self) -> dict:
"""
Randomly edit a BOOTP/DHCP field, among the following:
- chaddr (client hardware address)
- message-type (DHCP message type)
:return: Dictionary containing tweak information.
:return: Dictionary containing fuzz information.
"""
# Store old hash value
old_hash = self.get_hash()
......@@ -95,5 +93,5 @@ class BOOTP(Packet):
# Update checksums
self.update_fields()
# Return value: dictionary containing tweak information
# Return value: dictionary containing fuzz information
return self.get_dict_log(field, old_value, new_value, old_hash)
import logging
import random
import scapy.all as scapy
from scapy.contrib import coap
from packet.Packet import Packet
class CoAP(Packet):
......@@ -68,14 +65,14 @@ class CoAP(Packet):
return result
def tweak(self) -> dict:
def fuzz(self) -> dict:
"""
Randomly edit one field of the CoAP packet, among the following:
- type
- code
- uri
:return: Dictionary containing tweak information.
:return: Dictionary containing fuzz information.
"""
# Store old hash value
old_hash = self.get_hash()
......@@ -105,5 +102,5 @@ class CoAP(Packet):
# Update checksums
self.update_fields()
# Return value: dictionary containing tweak information
# Return value: dictionary containing fuzz information
return self.get_dict_log(field, old_value, new_value, old_hash)
import random
import scapy.all as scapy
from scapy.layers import dns
from packet.Packet import Packet
......@@ -62,14 +61,14 @@ class DNS(Packet):
return random.choice(self.fields)
def tweak(self) -> dict:
def fuzz(self) -> dict:
"""
Randomly edit one DNS field, among the following:
- QR flag
- Query type
- Query name
:return: Dictionary containing tweak information.
:return: Dictionary containing fuzz information.
"""
# Store old hash value
old_hash = self.get_hash()
......@@ -124,5 +123,5 @@ class DNS(Packet):
# Update checksums
self.update_fields()
# Return value: dictionary containing tweak information
# Return value: dictionary containing fuzz information
return self.get_dict_log(field, old_value, new_value, old_hash)
import scapy.all as scapy
from scapy.layers import http
from packet.Packet import Packet
class HTTP_Request(Packet):
......
import scapy.all as scapy
from packet.Packet import Packet
class ICMP(Packet):
......
import scapy.all as scapy
from scapy.contrib import igmp
from packet.Packet import Packet
class IGMP(Packet):
......
import logging
import scapy.all as scapy
from scapy.contrib import igmpv3
from packet.Packet import Packet
......@@ -12,12 +10,12 @@ class IGMPv3mr(Packet):
name = "IGMPv3mr"
def tweak(self) -> dict:
def fuzz(self) -> dict:
"""
Tweak the IGMPv3 Membership Report packet,
fuzz the IGMPv3 Membership Report packet,
by randomizing all group addresses.
:return: Dictionary containing tweak information.
:return: Dictionary containing fuzz information.
"""
# Store old hash value
old_hash = self.get_hash()
......@@ -39,5 +37,5 @@ class IGMPv3mr(Packet):
# Update checksums
self.update_fields()
# Return value: dictionary containing tweak information
# Return value: dictionary containing fuzz information
return self.get_dict_log("maddr", old_value, new_value, old_hash)
import scapy.all as scapy
from packet.Packet import Packet
class IPv4(Packet):
......
import scapy.all as scapy
from packet.Packet import Packet
class IPv6(Packet):
......
......@@ -269,13 +269,13 @@ class Packet:
def get_dict_log(self, field: str, old_value: str, new_value: str, old_hash: str) -> dict:
"""
Log packet field modification,
and return a dictionary containing tweak information.
and return a dictionary containing fuzz information.
:param field: Field name.
:param old_value: Old field value.
:param new_value: New field value.
:param old_hash: Old packet hash (before tweak).
:return: Dictionary containing tweak information.
:param old_hash: Old packet hash (before fuzz).
:return: Dictionary containing fuzz information.
"""
timestamp = self.packet.time
logging.info(f"Packet {self.id}, timestamp {timestamp}: {self.name}.{field} = {old_value} -> {new_value}")
......@@ -292,12 +292,12 @@ class Packet:
return d
def tweak(self) -> dict:
def fuzz(self) -> dict:
"""
Randomly edit one packet field.
:return: Dictionary containing tweak information,
or None if no tweak was performed.
:return: Dictionary containing fuzz information,
or None if no fuzz was performed.
"""
# Store old hash value
old_hash = self.get_hash()
......@@ -368,5 +368,5 @@ class Packet:
# Update checksums
self.update_fields()
# Return value: dictionary containing tweak information
# Return value: dictionary containing fuzz information
return self.get_dict_log(field, old_value, new_value, old_hash)
import scapy.all as scapy
from packet.Transport import Transport
class TCP(Transport):
......
import random
import scapy.all as scapy
from scapy.layers import http
from packet.Packet import Packet
class Transport(Packet):
......@@ -18,14 +16,14 @@ class Transport(Packet):
ports = []
def tweak(self) -> dict:
def fuzz(self) -> dict:
"""
If one of the ports is a well-known port,
randomly edit destination or source port,
in this respective order of priority.
:return: Dictionary containing tweak information,
or None if no tweak was performed.
:return: Dictionary containing fuzz information,
or None if no fuzz was performed.
"""
# Store old hash value
old_hash = self.get_hash()
......@@ -36,7 +34,7 @@ class Transport(Packet):
elif self.layer.getfieldval("sport") in self.ports:
field = "sport"
else:
# No well-known port, do not tweak
# No well-known port, do not fuzz
return None
# Store old value of field
......@@ -54,5 +52,5 @@ class Transport(Packet):
# Update checksums, if needed
self.update_fields()
# Return value: dictionary containing tweak information
# Return value: dictionary containing fuzz information
return self.get_dict_log(field, old_value, new_value, old_hash)
import scapy.all as scapy
from packet.Transport import Transport
class UDP(Transport):
......
import random
import scapy.all as scapy
from scapy.layers import dns
from packet.DNS import DNS
class mDNS(DNS):
......
......@@ -45,7 +45,7 @@ def must_edit_packet(i: int, packet_numbers: list, random_range: int) -> bool:
return is_specified or is_random
def tweak_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers: list = None, dry_run: bool = False) -> None:
def fuzz_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers: list = None, dry_run: bool = False) -> None:
"""
Main functionality of the program:
(Randomly) edit packet fields in a (list of) PCAP file(s).
......@@ -95,7 +95,7 @@ def tweak_pcaps(pcaps: list, output: str, random_range: int = 1, packet_numbers:
new_packets.append(Packet.rebuild_packet(packet))
break
else:
d = my_packet.tweak()
d = my_packet.fuzz()
if d is None:
# Packet was not edited, try editing one layer lower
last_layer_index = my_packet.get_layer_index() - 1
......@@ -162,7 +162,7 @@ if __name__ == "__main__":
### MAIN PROGRAM ###
tweak_pcaps(
fuzz_pcaps(
pcaps=args.input_pcaps,
output=args.output,
random_range=args.random_range,
......
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