Skip to content

Commit 1ac2eab

Browse files
committed
πŸ“… Commit Fri, 25 Jun 2021 23:05:30
πŸ”οΈ set scapy logging level to error to avoid annoying warning messages
1 parent d03b976 commit 1ac2eab

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

β€Žchepy_pcaps.py

+36-34
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import chepy.core
1818

19+
logging.getLogger("scapy").setLevel(logging.ERROR)
20+
1921

2022
def _full_duplex(p): # pragma: no cover
2123
"""Create a full duplex stream from packets
@@ -295,8 +297,8 @@ class PcapUSB:
295297

296298

297299
class Pcap(chepy.core.ChepyCore):
298-
"""This plugin allows handling of various pcap
299-
related operations.
300+
"""This plugin allows handling of various pcap
301+
related operations.
300302
301303
scapy is a requirement for this plugin.
302304
"""
@@ -316,9 +318,9 @@ def _pcap_reader_instance(self, bpf_filter):
316318
@chepy.core.ChepyDecorators.call_stack
317319
def read_pcap(self):
318320
"""Load a pcap. The state is set to scapy
319-
321+
320322
Returns:
321-
ChepyPlugin: The Chepy object.
323+
ChepyPlugin: The Chepy object.
322324
"""
323325
self._pcap_filepath = str(self._abs_path(self.state))
324326
self.state = "Pcap loaded"
@@ -327,9 +329,9 @@ def read_pcap(self):
327329
@chepy.core.ChepyDecorators.call_stack
328330
def pcap_dns_queries(self):
329331
"""Get DNS queries and their frame numbers
330-
332+
331333
Returns:
332-
ChepyPlugin: The Chepy object.
334+
ChepyPlugin: The Chepy object.
333335
334336
Examples:
335337
>>> Chepy("tests/files/test.pcapng").read_pcap().pcap_dns_queries().o
@@ -354,13 +356,13 @@ def pcap_dns_queries(self):
354356

355357
@chepy.core.ChepyDecorators.call_stack
356358
def pcap_http_streams(self):
357-
"""Get a dict of HTTP req/res
359+
"""Get a dict of HTTP req/res
360+
361+
This method does full fully assemble when data exceeds a
362+
certain threshold.
358363
359-
This method does full fully assemble when data exceeds a
360-
certain threshold.
361-
362364
Returns:
363-
ChepyPlugin: The Chepy object.
365+
ChepyPlugin: The Chepy object.
364366
"""
365367
import scapy.layers.http as scapy_http
366368

@@ -398,13 +400,13 @@ def pcap_http_streams(self):
398400
@chepy.core.ChepyDecorators.call_stack
399401
def pcap_payload(self, layer: str, bpf_filter: str = ""):
400402
"""Get an array of payloads based on provided layer
401-
403+
402404
Args:
403405
layer (str): Required. A valid Scapy layer.
404-
bpf_filter (str, optional): Apply a BPF filter to the packets
405-
406+
bpf_filter (str, optional): Apply a BPF filter to the packets
407+
406408
Returns:
407-
ChepyPlugin: The Chepy object.
409+
ChepyPlugin: The Chepy object.
408410
"""
409411
hold = []
410412
for packet in self._pcap_reader_instance(bpf_filter):
@@ -420,22 +422,22 @@ def pcap_payload(self, layer: str, bpf_filter: str = ""):
420422
def pcap_payload_offset(
421423
self, layer: str, start: int, end: int = None, bpf_filter: str = ""
422424
):
423-
"""Dump the raw payload by offset.
424-
425+
"""Dump the raw payload by offset.
426+
425427
Args:
426-
layer (str): The layer to get the data from.
427-
start (int): The starting offset of the data to be extracted.
428+
layer (str): The layer to get the data from.
429+
start (int): The starting offset of the data to be extracted.
428430
This could be a negative index number.
429431
end (int, optional): The end index of the offset.
430432
bpf_filter (str, optional): Apply a BPF filter to the packets
431-
433+
432434
Returns:
433-
ChepyPlugin: The Chepy object.
435+
ChepyPlugin: The Chepy object.
434436
435437
Examples:
436-
In this example, we are extracting all the payloads from the last 20 bytes on
437-
on the ICMP layer.
438-
438+
In this example, we are extracting all the payloads from the last 20 bytes on
439+
on the ICMP layer.
440+
439441
>>> Chepy('tests/files/test.pcapng').read_pcap().pcap_payload_offset('ICMP', -20)
440442
[b'secret', b'message']
441443
"""
@@ -457,9 +459,9 @@ def pcap_to_dict(self, bpf_filter: str = ""):
457459
458460
Args:
459461
bpf_filter (str, optional): Apply a BPF filter to the packets
460-
462+
461463
Returns:
462-
ChepyPlugin: The Chepy object.
464+
ChepyPlugin: The Chepy object.
463465
"""
464466
hold = []
465467
for packet in self._pcap_reader_instance(bpf_filter):
@@ -473,9 +475,9 @@ def pcap_layer_stats(self, bpf_filter: str = ""):
473475
474476
Args:
475477
bpf_filter (str, optional): Apply a BPF filter to the packets
476-
478+
477479
Returns:
478-
ChepyPlugin: The Chepy object.
480+
ChepyPlugin: The Chepy object.
479481
"""
480482

481483
def get_layers(pkt):
@@ -500,9 +502,9 @@ def pcap_convos(self, bpf_filter: str = ""):
500502
501503
Args:
502504
bpf_filter (str, optional): Apply a BPF filter to the packets
503-
505+
504506
Returns:
505-
ChepyPlugin: The Chepy object.
507+
ChepyPlugin: The Chepy object.
506508
"""
507509
convo = collections.OrderedDict()
508510

@@ -526,15 +528,15 @@ def pcap_convos(self, bpf_filter: str = ""):
526528
@chepy.core.ChepyDecorators.call_stack
527529
def pcap_usb_keyboard(self, layout: str = "qwerty"):
528530
"""Decode usb keyboard pcap
529-
531+
530532
Args:
531533
layout (str, optional): Layout of the keyboard. Defaults to "qwerty".
532-
534+
533535
Raises:
534536
TypeError: If layout is not qwerty or dvorak
535-
537+
536538
Returns:
537-
ChepyPlugin: The Chepy object.
539+
ChepyPlugin: The Chepy object.
538540
"""
539541
if layout == "qwerty":
540542
key_map = PcapUSB.qwerty_map

0 commit comments

Comments
Β (0)