我在计算机上设置了一个侦听端口4433的SSL服务器,我想进行某些测试并收集流量。我正试图用scapy做到这一点,但是,我无法收集任何流量
from scapy.all import *
import time
from threading import Thread, Event
import os
class Sniffer(Thread):
def __init__(self, host, interface=None):
super().__init__()
self.daemon = True
self.socket = None
self.filters = "dst port " + str(host)
print(self.filters)
self.interface = interface
self.stop_sniffer = Event()
def run(self):
print("running")
conf.L3listen= L3RawSocket
self.socket = conf.L3listen(
filter=self.filters
)
self.capture = sniff(
filter='tcp and (port 4433 or port 4444)',
opened_socket=self.socket,
prn=self.print_packet,
stop_filter=self.should_stop_sniffer#,
#store=0
)
def join(self, timeout=None):
self.stop_sniffer.set()
super().join(timeout)
def should_stop_sniffer(self, packet):
return self.stop_sniffer.isSet()
def print_packet(self, packet):
print(packet)
def write_packet(self):
wrpcap("hi.pcap", self.capture)
sniff = Sniffer("4433")
sniff.start()
for i in range(100):
os.system("wget -qO- https://localhost:4433 --no-check-certificate /dev/null")
sniff.join(5.0)
sniff.write_packet()
输出
Traceback (most recent call last):
File "traffic_scapy.py", line 56, in <module>
sniff.write_packet()
File "traffic_scapy.py", line 48, in write_packet
wrpcap("hi.pcap", self.capture)
AttributeError: 'Sniffer' object has no attribute 'capture'