Scapy: GetMulticastMAC() License: GPL Download (trac.secdev.org/scapy) Tags: scapy, MAC, multicast, addon

Proporciona una MAC del listado creado por IANA de las MAC reservadas a multicast. Con un total de 66111 MACs posibles, la función genera una MAC aleatoria si el parametro que se le introduce es 0 o se omite. También se puede obtener una MAC introduciendo como parámetro un índice dentro del rango 1-66111. Utilizado satisfactoriamente sobre scapy-2.1.0.

[email protected]: # cd scapy-x.x.x
 [email protected]: # wget <a href="http://urlpatch/volatile.patch" target="_blank">http://URLPatch/volatile.patch</a>
 [email protected]: /scapy-x.x.x/ # ls
 bin  doc  MANIFEST.in  PKG-INFO  run_scapy  scapy  setup.py  test volatile.patch
 [email protected]: /scapy-x.x.x/ # patch -p0 < volatile.patch
 [email protected]: /scapy-x.x.x/ # ./run_scapy
 Welcome to Scapy (2.1.0)
 >>> print GetMulticastMAC(0)
 ab:00:04:01:5e:43
 >>> help(GetMulticastMAC)

Help on class GetMulticastMAC in module scapy.volatile:

class GetMulticastMAC(RandMAC)
 |      ------------------------
 |      GetMulticastMAC(Index) - For use in fuzzing probes.
 |      --------------------------------------------------
 |      Get a multicast MAC from the list generated by IANA (<a href="http://www.iana.org/assignments/ethernet-numbers" target="_blank">www.iana.org/assignments/ethernet-numbers</a>)
 |          ''' An Ethernet multicast address consists of the multicast bit, the
 |          23-bit vendor component, and the 24-bit group identifier assigned by
 |          the vendor.  For example, DEC is assigned the vendor component
 |          08-00-2B, so multicast addresses assigned by DEC have the first
 |          24-bits 09-00-2B (since the multicast bit is the low-order bit of the
 |          first byte, which is "the first bit on the wire").'''

|      Index can be zero or another number.
 |          - If valor is zero script will generate a random number (default Index = 0).
 |          - Use index to generate a secuecial list.
 |      Example:
 |          ...
 |          >>> for i in range(66111): print GetMulticastMAC(i)
 |          ...
 |          >>> GetMulticastMAC()
 |          ...
 |
 |  +info:
 |          <a href="../labs" target="_blank">www.iniqua.com/labs</a>
 |
 |  Method resolution order:
 |      GetMulticastMAC
 |      RandMAC
 |      RandString
 |      RandField
 |      VolatileValue
 |
 |  Methods defined here:
 |
 |  __init__(self, Index=0)

Código:

multicastList = ["01:00:5E:00:00:00","01:00:5E:7F:FF:FF","01:00:5E:80:00:00",
"01:00:5E:8F:FF:FF","01:00:5E:90:00:00","01:00:5E:FF:FF:FF","01:80:C2:00:00:00",
"09:00:02:04:00:01","09:00:02:04:00:02","09:00:09:00:00:01","09:00:09:00:00:01",
"09:00:09:00:00:04","09:00:1E:00:00:00","09:00:2B:00:00:00","09:00:2B:00:00:01",
"09:00:2B:00:00:02","09:00:2B:00:00:03","09:00:2B:00:00:04","09:00:2B:00:00:05",
"09:00:2B:00:00:06","09:00:2B:00:00:07","09:00:2B:00:00:0F","09:00:2B:00:00:10",
"09:00:2B:00:00:11","09:00:2B:00:00:12","09:00:2B:00:00:13","09:00:2B:00:00:14",
"09:00:2B:00:00:15","09:00:2B:00:00:16","09:00:2B:00:00:17","09:00:2B:00:00:18",
"09:00:2B:00:00:19","09:00:2B:00:00:1A","09:00:2B:00:00:1B","09:00:2B:00:00:1C",
"09:00:2B:00:00:1D","09:00:2B:00:00:1E","09:00:2B:00:00:1F","09:00:2B:01:00:00",
"09:00:2B:01:00:01","09:00:2B:02:00:00","09:00:2B:02:01:00","09:00:2B:02:01:01",
"09:00:2B:02:01:02","09:00:2B:04:00:00","09:00:2B:23:00:00","09:00:4E:00:00:02",
"09:00:56:00:00:00","09:00:56:FE:FF:FF","09:00:56:FF:00:00","09:00:56:FF:FF:FF",
"09:00:77:00:00:01","09:00:7C:02:00:05","09:00:7C:05:00:01","0D:1E:15:BA:DD:06",
"AB:00:00:01:00:00","AB:00:00:02:00:00","AB:00:00:03:00:00","AB:00:00:04:00:00",
"AB:00:00:05:00:00","AB:00:03:FF:FF:FF","AB:00:03:00:00:00","CF:00:00:00:00:00",
"09:00:2B:03:xx:xx","AB:00:04:00:xx:xx","AB:00:04:01:xx:yy"]

class GetMulticastMAC(RandMAC):
 """
 ------------------------
 GetMulticastMAC(Index) - For use in fuzzing probes.
 --------------------------------------------------
 Get a multicast MAC from the list generated by IANA (http://www.iana.org/assignments/ethernet-numbers)
 """
 def __init__(self, Index=0):
    self.randMac = None
    self.indexMac = None
    self.mac = ()
    template = "ff:ff:ff:ff:ff:ff"
    if Index == 0:
       rn = RandNum(0,66111)
    if 0        self.randMac = multicastList[rn]
    elif 63        template = multicastList[63]
    elif 319        template = multicastList[64]
    elif 575        template = multicastList[65]
       template = template.split(":")
    for i in range(6):
       if template[i] == "xx" and template[i-1] != "xx":
          v = RandByte()
       elif template[i] == "xx" and template[i-1] == "xx":
          v = v
       elif template [i] == "yy":
          v = RandByte()
       else:
          v = int(template[i],16)
       self.mac += (v,)

    else:
       if 0           self.indexMac = multicastList[Index]
       if 63           template = multicastList[63]
          template = template.split(":")
          relativeIndex = Index - 63
          for i in range(6):
             if template[i] == "xx":
                v = int(hex(relativeIndex).split('x')[1],16)
             else:
                v = int(template[i],16)
          self.mac += (v,)
       if 319           template = multicastList[64]
          template = template.split(":")
          relativeIndex = Index - 319
          for i in range(6):
             if template[i] == "xx":
                v = int(hex(relativeIndex).split('x')[1],16)
             else:
                v = int(template[i],16)
          self.mac += (v,)
       if 575           template = multicastList[65]
          relativeIndex = Index - 575
          template = template.split(":")
          macof = str("%04X" % relativeIndex)
          for i in range(6):
             if template[i] == "xx":
                v = int(macof[0] + macof[1],16)
             elif template[i] == "yy":
                v = int(macof[2] + macof[3],16)
             else:
                v = int(template[i],16)
             self.mac += (v,)

 def _fix(self):
    if self.randMac:
       return self.randMac
    elif self.indexMac:
       return self.indexMac
    else:
       return "%02x:%02x:%02x:%02x:%02x:%02x" % self.mac