diff --git a/example.py b/example.py index 50a190a..72ed9d3 100644 --- a/example.py +++ b/example.py @@ -1,52 +1,20 @@ -import matplotlib.pyplot as plt -import numpy as np -from scapy.all import (TCP, Packet, RandIP, RandIP6, RandMAC, Raw, rdpcap, - sniff, wrpcap) - from heifip.extractor import FIPExtractor -from heifip.images.flow import FlowImage -from heifip.images.flow_tiled_auto import FlowImageTiledAuto -from heifip.images.flow_tiled_fixed import FlowImageTiledFixed -from heifip.images.markovchain import (MarkovTransitionMatrixFlow, - MarkovTransitionMatrixPacket) -from heifip.images.packet import PacketImage from heifip.layers import PacketProcessorType +from heifip.images.flow import FlowImage -# extractor = FIPExtractor() -# imgs = extractor.create_image_from_file( -# "/home/smachmeier/data/better-split-binary/benign/BitTorrent-0710.pcap", -# PacketProcessorType.NONE, -# MarkovTransitionMatrixFlow, -# 0, # min_image_dim -# 0, # max_image_dim -# 3, # min_packets -# 0, # max_packets -# True, # remove_duplicates, -# 8 -# # 30, # dim -# # 0, # fill -# # True # auto_dim -# ) -# i = 0 -# for img in imgs: -# extractor.save_image(img, f"/home/smachmeier/Documents/projects/heiFIP/data/benign/{i}.png") -# i += 1 -pcap = sniff(offline="/home/smachmeier/data/test-data/") -for pkt in pcap: - # if Raw in pkt: - # pkt[TCP].remove_payload() - pkt.show() - # wrpcap("/home/smachmeier/test.pcap", pkt, append=True) - -# fig = plt.figure(figsize=(16, 16)) -# columns = 4 -# rows = 4 -# for i in range(1, columns*rows +1): -# fig.add_subplot(rows, columns, i) -# plt.ylabel("Y") -# plt.xlabel("X") -# plt.imshow(imgs[i]) -# plt.savefig('test.pdf', dpi=fig.dpi) - -# plt.imshow(imgs[0]) -# plt.savefig('test.pdf') +extractor = FIPExtractor() +imgs = extractor.create_image_from_file( + "./tests/pcaps/dns-caa.pcap", + PacketProcessorType.NONE, + FlowImage, + 0, # min_image_dim + 0, # max_image_dim + 1, # min_packets + 0, # max_packets + True, # remove_duplicates, + 8 + # 30, # dim + # 0, # fill + # True # auto_dim +) +print(imgs) diff --git a/heifip/images/flow.py b/heifip/images/flow.py index 69554a6..e795236 100644 --- a/heifip/images/flow.py +++ b/heifip/images/flow.py @@ -1,5 +1,4 @@ import binascii -import logging import numpy as np from scapy.all import Packet, raw diff --git a/heifip/images/flow_tiled_auto.py b/heifip/images/flow_tiled_auto.py index 690336d..4ce37bb 100644 --- a/heifip/images/flow_tiled_auto.py +++ b/heifip/images/flow_tiled_auto.py @@ -1,5 +1,4 @@ import binascii -import logging import numpy as np from scapy.all import Packet, raw diff --git a/heifip/images/flow_tiled_fixed.py b/heifip/images/flow_tiled_fixed.py index 431c0e3..615af56 100644 --- a/heifip/images/flow_tiled_fixed.py +++ b/heifip/images/flow_tiled_fixed.py @@ -1,5 +1,4 @@ import binascii -import logging import numpy as np from scapy.all import Packet, raw diff --git a/heifip/images/markovchain.py b/heifip/images/markovchain.py index b03def8..ee83e99 100644 --- a/heifip/images/markovchain.py +++ b/heifip/images/markovchain.py @@ -1,7 +1,5 @@ -import logging - import numpy as np -from scapy.all import Packet, chexdump, hexdump, raw +from scapy.all import Packet from heifip.images import NetworkTrafficImage diff --git a/heifip/images/packet.py b/heifip/images/packet.py index 566ca78..15e7069 100644 --- a/heifip/images/packet.py +++ b/heifip/images/packet.py @@ -1,5 +1,4 @@ import binascii -import logging import numpy as np from scapy.all import Packet, raw diff --git a/heifip/layers/__init__.py b/heifip/layers/__init__.py index fd9e926..e01507f 100644 --- a/heifip/layers/__init__.py +++ b/heifip/layers/__init__.py @@ -4,9 +4,8 @@ from enum import Enum, unique from typing import Type -import cryptography -from scapy.all import (Packet, RandIP, RandIP6, RandMAC, Raw, load_layer, - rdpcap, sniff, wrpcap) +from scapy.all import (Packet,load_layer, + sniff, wrpcap) from scapy.layers.dns import DNS from scapy.layers.http import HTTP, HTTPRequest, HTTPResponse from scapy.layers.inet import IP, TCP, UDP, Ether diff --git a/heifip/layers/dns.py b/heifip/layers/dns.py index 8fb4112..cda2421 100644 --- a/heifip/layers/dns.py +++ b/heifip/layers/dns.py @@ -1,6 +1,3 @@ -import hashlib -from typing import Type - from scapy.all import Packet from scapy.layers.dns import DNS diff --git a/heifip/layers/http.py b/heifip/layers/http.py index b5a448a..04e21cf 100644 --- a/heifip/layers/http.py +++ b/heifip/layers/http.py @@ -1,11 +1,10 @@ import hashlib -from typing import Type -from scapy.all import Packet -from scapy.layers.http import HTTP, HTTPRequest, HTTPResponse +from scapy.all import Packet, Raw +from scapy.layers.http import HTTPRequest, HTTPResponse from heifip.layers.transport import TransportPacket -from heifip.plugins.header import (CustomHTTP, CustomHTTP_Request, +from heifip.plugins.header import (CustomHTTP_Request, CustomHTTP_Response) diff --git a/heifip/layers/packet.py b/heifip/layers/packet.py index a753596..7633c8f 100644 --- a/heifip/layers/packet.py +++ b/heifip/layers/packet.py @@ -1,7 +1,6 @@ import hashlib -from typing import Type -from scapy.all import Packet, RandMAC +from scapy.all import RandMAC from scapy.layers.inet import Ether diff --git a/heifip/plugins/header.py b/heifip/plugins/header.py index b36d36e..e9c2297 100644 --- a/heifip/plugins/header.py +++ b/heifip/plugins/header.py @@ -1,9 +1,8 @@ -from scapy.all import (DNS, IP, IP_PROTOS, TCP, UDP, BitEnumField, BitField, +from scapy.all import (IP_PROTOS, BitEnumField, BitField, ByteEnumField, ByteField, DNSQRField, DNSRRField, - FlagsField, IntField, IPv6, Packet, ShortEnumField, + FlagsField, IntField, Packet, ShortEnumField, StrField, TCPOptionsField, XByteField) from scapy.layers.dns import DNSStrField, InheritOriginDNSStrPacket, dnstypes -from scapy.layers.http import HTTPRequest, HTTPResponse from scapy.layers.inet6 import ipv6nh