Beispiel #1
0
    def testDadFailure(self):
        # [3]  Get an IPv6 address back, in optimistic DAD start-up.
        self.SetDAD(self.test_ifname, 1)  # Enable DAD
        self.SetOptimisticDAD(self.test_ifname, 1)
        self.SetUseOptimistic(self.test_ifname, 1)
        # Send a RA to start SLAAC and subsequent DAD.
        self.SendRA(self.test_netid, 0)
        # Prove optimism and usability.
        self.assertAddressHasExpectedAttributes(self.test_ip,
                                                self.test_ifindex,
                                                iproute.IFA_F_OPTIMISTIC)
        self.assertAddressUsable(self.test_ip, self.test_netid)
        self.assertAddressSelected(self.test_ip, self.test_netid)

        # Send a NA for the optimistic address, indicating address conflict
        # ("DAD defense").
        conflict_macaddr = "02:00:0b:ad:d0:0d"
        dad_defense = (
            scapy.Ether(src=conflict_macaddr, dst="33:33:33:00:00:01") /
            scapy.IPv6(src=self.test_ip, dst="ff02::1") /
            scapy.ICMPv6ND_NA(tgt=self.test_ip, R=0, S=0, O=1) /
            scapy.ICMPv6NDOptDstLLAddr(lladdr=conflict_macaddr))
        self.ReceiveEtherPacketOn(self.test_netid, dad_defense)

        # The address should have failed DAD, and therefore no longer be usable.
        self.assertAddressNotUsable(self.test_ip, self.test_netid)
        self.assertAddressNotSelected(self.test_ip, self.test_netid)
Beispiel #2
0
def create_na(src_ip, dst_ip, src_mac, dst_mac, r=0, s=0):
    # Advertisement
    ether_head = scapy.Ether(dst=dst_mac, src=src_mac)
    ipv6_head = scapy.IPv6(src=src_ip, dst=dst_ip)
    icmpv6_ns = scapy.ICMPv6ND_NA(tgt=src_ip, R=r, S=s)
    ll_dst_add = scapy.ICMPv6NDOptDstLLAddr(lladdr=src_mac)
    adv = (ether_head / ipv6_head / icmpv6_ns / ll_dst_add)

    return adv
 def ReceiveUnicastAdvertisement(self, addr, mac):
     version = 6 if ":" in addr else 4
     if version == 6:
         packet = (
             scapy.Ether(src=mac, dst=self.MyMacAddress(self.netid)) /
             scapy.IPv6(src=addr, dst=self.MyLinkLocalAddress(self.netid)) /
             scapy.ICMPv6ND_NA(tgt=addr, S=1, O=0) /
             scapy.ICMPv6NDOptDstLLAddr(lladdr=mac))
         self.ReceiveEtherPacketOn(self.netid, packet)
     else:
         raise NotImplementedError
Beispiel #4
0
def neighbour_advertisement(addr, iface):
    try:
        lla = get_ipv6_link_local(iface)
        adv = sca.IPv6(src=lla, dst="ff02::1") / sca.ICMPv6ND_NA(
            R=0, S=0, O=1, tgt=addr)
        opt = sca.ICMPv6NDOptDstLLAddr(lladdr=sca.get_if_hwaddr(iface))
        adv.add_payload(opt)
        logger.warning("neighbour_advertisement packet {}".format(adv.show()))
        sca.send(adv, iface=iface)
        logger.warning("neighbour_advertisement packet send {}".format(
            adv.show()))
    except Exception as e:
        logger.error(e)
 def ReceiveUnicastAdvertisement(self,
                                 addr,
                                 mac,
                                 srcaddr=None,
                                 dstaddr=None,
                                 S=1,
                                 O=0,
                                 R=1):
     version = csocket.AddressVersion(addr)
     if srcaddr is None:
         srcaddr = addr
     if dstaddr is None:
         dstaddr = self.MyLinkLocalAddress(self.netid)
     if version == 6:
         packet = (scapy.Ether(src=mac, dst=self.MyMacAddress(self.netid)) /
                   scapy.IPv6(src=srcaddr, dst=dstaddr) /
                   scapy.ICMPv6ND_NA(tgt=addr, S=S, O=O, R=R) /
                   scapy.ICMPv6NDOptDstLLAddr(lladdr=mac))
         self.ReceiveEtherPacketOn(self.netid, packet)
     else:
         raise NotImplementedError
def NA(srcaddr, dstaddr, srcmac):
    packet = (scapy.IPv6(src=srcaddr, dst=dstaddr) /
              scapy.ICMPv6ND_NA(tgt=srcaddr, R=0, S=1, O=1) /
              scapy.ICMPv6NDOptDstLLAddr(lladdr=srcmac))
    return ("ICMPv6 NA", packet)