def input_ip6(self, eth, ip6, timestamp): if eth.src == self.mac: return if ip6.nxt == dpkt.ip.IP_PROTO_ICMP6: icmp6 = dpkt.icmp6.ICMP6(str(ip6.data)) mac = dnet.eth_ntoa(str(eth.src)) if self.mac: if icmp6.type == dpkt.icmp6.ND_NEIGHBOR_SOLICIT: ip6_dst = dnet.ip6_ntoa(str(icmp6.data)[4:20]) for h in self.hosts: if mac == h: (ip6_src, rand_mac_src, iter_src, reply_src) = self.hosts[mac] for i in self.hosts: (ip6, rand_mac_dst, iter_dst, reply_dst) = self.hosts[i] if ip6_dst == ip6: break if reply_src and reply_dst: _icmp6 = dpkt.icmp6.ICMP6( type=dpkt.icmp6.ND_NEIGHBOR_SOLICIT, code=0, data=struct.pack("!L16sBB6s", 0x60000000, dnet.ip6_aton(ip6_dst), 1, 1, rand_mac_dst) ) _eth = dpkt.ethernet.Ethernet( dst=eth.src, src=dnet.eth_aton(rand_mac_dst), type=dpkt.ip.IP_PROTO_IP6, data=str(_icmp6) ) self.dnet.send(str(_eth)) break if icmp6.type == dpkt.icmp6.ND_ROUTER_ADVERT: if mac in self.hosts: (ip, random_mac, iter, reply) = self.hosts[mac] if self.ui == 'gtk': self.hosts_liststore.set(iter, 2, "R") for h in self.hosts: if mac == h: return (ip, random_mac, iter, reply) = self.hosts[h] if mac == random_mac: return ip = dnet.ip6_ntoa(ip6.src) if ip == "::": return rand_mac = [ 0x00, random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff) ] rand_mac = ':'.join(map(lambda x: "%02x" % x, rand_mac)) if self.ui == 'gtk': iter = self.hosts_liststore.append([mac, ip, "", self.mac_to_vendor(mac)]) elif self.ui == 'urw': self.hostlist.append(self.parent.menu_button("%s(%s) - %s" % (mac, self.mac_to_vendor(mac), ip), self.urw_hostlist_activated, mac)) iter = None self.hosts[mac] = (dnet.ip6_ntoa(ip6.src), rand_mac, iter, False) if self.ui == 'gtk': self.mappings_liststore.append([mac, rand_mac])
def input_udp(self, eth, ip, udp, timestamp): if ip.src != self.ip and ip.src != self.ip6_ll: if ip.src not in self.peers: pkg = {} ip_addr = "" prio = 0 auth = "" tlv = hsrp2_tlv() left = str(udp.data) while len(left) > 0: left = tlv.parse(left) if tlv.type == hsrp2_tlv.TYPE_GROUP_STATE: hsrp2_group_state = hsrp2_group_state_tlv() left = hsrp2_group_state.parse(left) pkg["hsrp2_group_state_tlv"] = hsrp2_group_state ip_addr = hsrp2_group_state.ip prio = hsrp2_group_state.prio elif tlv.type == hsrp2_tlv.TYPE_TEXT_AUTH: hsrp2_text_auth = hsrp2_text_auth_tlv() left = hsrp2_text_auth.parse(left) pkg["hsrp2_text_auth_tlv"] = hsrp2_text_auth auth = hsrp2_text_auth.auth_data elif tlv.type == hsrp2_tlv.TYPE_MD5_AUTH: hsrp2_md5_auth = hsrp2_md5_auth_tlv() left = hsrp2_md5_auth.parse(left) pkg["hsrp2_md5_auth_tlv"] = hsrp2_md5_auth auth = "MD5: %s key#%d" % (hsrp2_md5_auth.csum.encode( "hex"), hsrp2_md5_auth.keyid) else: return if type(ip) == dpkt.ip6.IP6: src = dnet.ip6_ntoa(ip.src) ip_addr = dnet.ip6_ntoa(ip_addr) else: src = dnet.ip_ntoa(ip.src) ip_addr = dnet.ip_ntoa(ip_addr) if self.ui == 'gtk': iter = self.liststore.append( [src, ip_addr, prio, "Seen", auth]) elif self.ui == 'urw': label = "%s - %s PRIO(%d) AUTH(%s)" % (src, ip_addr, prio, auth) self.hostlist.append( self.parent.menu_button(label + " - Seen", self.urw_hostlist_activated, (ip.src, label))) iter = None self.peers[ip.src] = (iter, pkg, False, False) self.log("HSRP2: Got new peer %s" % (src))
def input_udp(self, eth, ip, udp, timestamp): if ip.src != self.ip and ip.src != self.ip6_ll: if ip.src not in self.peers: pkg = {} ip_addr = "" prio = 0 auth = "" tlv = hsrp2_tlv() left = str(udp.data) while len(left) > 0: left = tlv.parse(left) if tlv.type == hsrp2_tlv.TYPE_GROUP_STATE: hsrp2_group_state = hsrp2_group_state_tlv() left = hsrp2_group_state.parse(left) pkg["hsrp2_group_state_tlv"] = hsrp2_group_state ip_addr = hsrp2_group_state.ip prio = hsrp2_group_state.prio elif tlv.type == hsrp2_tlv.TYPE_TEXT_AUTH: hsrp2_text_auth = hsrp2_text_auth_tlv() left = hsrp2_text_auth.parse(left) pkg["hsrp2_text_auth_tlv"] = hsrp2_text_auth auth = hsrp2_text_auth.auth_data elif tlv.type == hsrp2_tlv.TYPE_MD5_AUTH: hsrp2_md5_auth = hsrp2_md5_auth_tlv() left = hsrp2_md5_auth.parse(left) pkg["hsrp2_md5_auth_tlv"] = hsrp2_md5_auth auth = "MD5: %s key#%d" % (hsrp2_md5_auth.csum.encode("hex"), hsrp2_md5_auth.keyid) else: return if type(ip) == dpkt.ip6.IP6: src = dnet.ip6_ntoa(ip.src) ip_addr = dnet.ip6_ntoa(ip_addr) else: src = dnet.ip_ntoa(ip.src) ip_addr = dnet.ip_ntoa(ip_addr) if self.ui == 'gtk': iter = self.liststore.append([src, ip_addr, prio, "Seen", auth]) elif self.ui == 'urw': label = "%s - %s PRIO(%d) AUTH(%s)" % (src, ip_addr, prio, auth) self.hostlist.append(self.parent.menu_button(label + " - Seen", self.urw_hostlist_activated, (ip.src, label))) iter = None self.peers[ip.src] = (iter, pkg, False, False) self.log("HSRP2: Got new peer %s" % (src))
def add_spoof(self): data = [] org_data = [] hosts = [] for host_upper in self.upper_add: (ip_upper, rand_mac_upper, iter_upper) = self.upper_add[host_upper] for host_lower in self.lower_add: (ip_lower, rand_mac_lower, iter_lower) = self.lower_add[host_lower] advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_upper), 2, 1, dnet.eth_aton(rand_mac_upper)) icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ND_NEIGHBOR_ADVERT, code=0, data=advert) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_upper), dst=dnet.ip6_aton(ip_lower), nxt=dpkt.ip.IP_PROTO_ICMP6, hlim=255, data=icmp6, plen=len(icmp6_str)) ip6.extension_hdrs = {} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i] = None ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton(host_lower), src=dnet.eth_aton(rand_mac_upper), data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6) data.append(str(eth)) advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(host_upper)) icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ND_NEIGHBOR_ADVERT, code=0, data=advert) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_upper), dst=dnet.ip6_aton(ip_lower), nxt=dpkt.ip.IP_PROTO_ICMP6, hlim=255, data=icmp6, plen=len(icmp6_str)) ip6.extension_hdrs = {} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i] = None ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton(host_lower), src=dnet.eth_aton(host_upper), data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6) org_data.append(str(eth)) advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(rand_mac_lower)) icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ND_NEIGHBOR_ADVERT, code=0, data=advert) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_lower), dst=dnet.ip6_aton(ip_upper), nxt=dpkt.ip.IP_PROTO_ICMP6, hlim=255, data=icmp6, plen=len(icmp6_str)) ip6.extension_hdrs = {} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i] = None ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton(host_upper), src=dnet.eth_aton(rand_mac_lower), data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6) data.append(str(eth)) advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(host_lower)) icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ND_NEIGHBOR_ADVERT, code=0, data=advert) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_lower), dst=dnet.ip6_aton(ip_upper), nxt=dpkt.ip.IP_PROTO_ICMP6, hlim=255, data=icmp6, plen=len(icmp6_str)) ip6.extension_hdrs = {} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i] = None ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton(host_upper), src=dnet.eth_aton(host_lower), data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6) org_data.append(str(eth)) hosts.append(host_upper) mld = struct.pack( "!xxHBBH16s", 1, 4, 0, 0, dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_upper)[13:]) icmp6 = dpkt.icmp6.ICMP6(type=143, code=0, data=mld) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_upper), dst=dnet.ip6_aton("ff02::16"), nxt=dpkt.ip.IP_PROTO_HOPOPTS, hlim=1, data=icmp6, plen=len(icmp6_str) + 8) ip6.extension_hdrs = {} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i] = None ip6.extension_hdrs[ dpkt.ip.IP_PROTO_HOPOPTS] = dpkt.ip6.IP6HopOptsHeader( nxt=dpkt.ip.IP_PROTO_ICMP6, data=struct.pack("!BBHBB", 5, 2, 0, 1, 0)) ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet( dst=dnet.eth_aton("33:33:00:00:00:16"), src=self.mac, data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6) self.dnet.send(str(eth)) self.log("ICMP6: Joined multicast group " + dnet.ip6_ntoa( dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_upper)[13:])) for host_lower in self.lower_add: hosts.append(host_lower) (ip_lower, rand_mac_lower, iter_lower) = self.lower_add[host_lower] mld = struct.pack( "!xxHBBH16s", 1, 4, 0, 0, dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_lower)[13:]) icmp6 = dpkt.icmp6.ICMP6(type=143, code=0, data=mld) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_lower), dst=dnet.ip6_aton("ff02::16"), nxt=dpkt.ip.IP_PROTO_HOPOPTS, hlim=1, data=icmp6, plen=len(icmp6_str) + 8) ip6.extension_hdrs = {} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i] = None ip6.extension_hdrs[ dpkt.ip.IP_PROTO_HOPOPTS] = dpkt.ip6.IP6HopOptsHeader( nxt=dpkt.ip.IP_PROTO_ICMP6, data=struct.pack("!BBHBB", 5, 2, 0, 1, 0)) ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet( dst=dnet.eth_aton("33:33:00:00:00:16"), src=self.mac, data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6) self.dnet.send(str(eth)) self.log("ICMP6: Joined multicast group " + dnet.ip6_ntoa( dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_lower)[13:])) self.upper_add = {} self.lower_add = {} return (data, org_data, hosts)
def input_ip6(self, eth, ip6, timestamp): if eth.src == self.mac: return if ip6.nxt == dpkt.ip.IP_PROTO_ICMP6: icmp6 = dpkt.icmp6.ICMP6(str(ip6.data)) mac = dnet.eth_ntoa(str(eth.src)) if self.mac: if icmp6.type == dpkt.icmp6.ND_NEIGHBOR_SOLICIT: ip6_dst = dnet.ip6_ntoa(str(icmp6.data)[4:20]) for h in self.hosts: if mac == h: (ip6_src, rand_mac_src, iter_src, reply_src) = self.hosts[mac] for i in self.hosts: (ip6, rand_mac_dst, iter_dst, reply_dst) = self.hosts[i] if ip6_dst == ip6: break if reply_src and reply_dst: _icmp6 = dpkt.icmp6.ICMP6( type=dpkt.icmp6.ND_NEIGHBOR_SOLICIT, code=0, data=struct.pack("!L16sBB6s", 0x60000000, dnet.ip6_aton(ip6_dst), 1, 1, rand_mac_dst)) _eth = dpkt.ethernet.Ethernet( dst=eth.src, src=dnet.eth_aton(rand_mac_dst), type=dpkt.ip.IP_PROTO_IP6, data=str(_icmp6)) self.dnet.send(str(_eth)) break if icmp6.type == dpkt.icmp6.ND_ROUTER_ADVERT: if mac in self.hosts: (ip, random_mac, iter, reply) = self.hosts[mac] if self.ui == 'gtk': self.hosts_liststore.set(iter, 2, "R") for h in self.hosts: if mac == h: return (ip, random_mac, iter, reply) = self.hosts[h] if mac == random_mac: return ip = dnet.ip6_ntoa(ip6.src) if ip == "::": return rand_mac = [ 0x00, random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff) ] rand_mac = ':'.join(map(lambda x: "%02x" % x, rand_mac)) if self.ui == 'gtk': iter = self.hosts_liststore.append( [mac, ip, "", self.mac_to_vendor(mac)]) elif self.ui == 'urw': self.hostlist.append( self.parent.menu_button( "%s(%s) - %s" % (mac, self.mac_to_vendor(mac), ip), self.urw_hostlist_activated, mac)) iter = None self.hosts[mac] = (dnet.ip6_ntoa(ip6.src), rand_mac, iter, False) if self.ui == 'gtk': self.mappings_liststore.append([mac, rand_mac])
def check_ip6(self, ip6): if dnet.ip6_ntoa(ip6.src) == "::": return (False, False) return (True, False)
def add_spoof(self): data = [] org_data = [] hosts = [] for host_upper in self.upper_add: (ip_upper, rand_mac_upper, iter_upper) = self.upper_add[host_upper] for host_lower in self.lower_add: (ip_lower, rand_mac_lower, iter_lower) = self.lower_add[host_lower] advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_upper), 2, 1, dnet.eth_aton(rand_mac_upper)) icmp6 = dpkt.icmp6.ICMP6( type=dpkt.icmp6.ND_NEIGHBOR_ADVERT, code=0, data=advert ) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_upper), dst=dnet.ip6_aton(ip_lower), nxt=dpkt.ip.IP_PROTO_ICMP6, hlim=255, data=icmp6, plen=len(icmp6_str) ) ip6.extension_hdrs={} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i]=None ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet( dst=dnet.eth_aton(host_lower), src=dnet.eth_aton(rand_mac_upper), data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6 ) data.append(str(eth)) advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(host_upper)) icmp6 = dpkt.icmp6.ICMP6( type=dpkt.icmp6.ND_NEIGHBOR_ADVERT, code=0, data=advert ) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_upper), dst=dnet.ip6_aton(ip_lower), nxt=dpkt.ip.IP_PROTO_ICMP6, hlim=255, data=icmp6, plen=len(icmp6_str) ) ip6.extension_hdrs={} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i]=None ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet( dst=dnet.eth_aton(host_lower), src=dnet.eth_aton(host_upper), data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6 ) org_data.append(str(eth)) advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(rand_mac_lower)) icmp6 = dpkt.icmp6.ICMP6( type=dpkt.icmp6.ND_NEIGHBOR_ADVERT, code=0, data=advert ) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_lower), dst=dnet.ip6_aton(ip_upper), nxt=dpkt.ip.IP_PROTO_ICMP6, hlim=255, data=icmp6, plen=len(icmp6_str) ) ip6.extension_hdrs={} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i]=None ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet( dst=dnet.eth_aton(host_upper), src=dnet.eth_aton(rand_mac_lower), data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6 ) data.append(str(eth)) advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(host_lower)) icmp6 = dpkt.icmp6.ICMP6( type=dpkt.icmp6.ND_NEIGHBOR_ADVERT, code=0, data=advert ) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_lower), dst=dnet.ip6_aton(ip_upper), nxt=dpkt.ip.IP_PROTO_ICMP6, hlim=255, data=icmp6, plen=len(icmp6_str) ) ip6.extension_hdrs={} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i]=None ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet( dst=dnet.eth_aton(host_upper), src=dnet.eth_aton(host_lower), data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6 ) org_data.append(str(eth)) hosts.append(host_upper) mld = struct.pack("!xxHBBH16s", 1, 4, 0, 0, dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_upper)[13:]) icmp6 = dpkt.icmp6.ICMP6( type=143, code=0, data=mld ) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_upper), dst=dnet.ip6_aton("ff02::16"), nxt=dpkt.ip.IP_PROTO_HOPOPTS, hlim=1, data=icmp6, plen=len(icmp6_str) + 8 ) ip6.extension_hdrs={} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i]=None ip6.extension_hdrs[dpkt.ip.IP_PROTO_HOPOPTS] = dpkt.ip6.IP6HopOptsHeader(nxt=dpkt.ip.IP_PROTO_ICMP6, data=struct.pack("!BBHBB", 5, 2, 0, 1, 0)) ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet( dst=dnet.eth_aton("33:33:00:00:00:16"), src=self.mac, data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6 ) self.dnet.send(str(eth)) self.log("ICMP6: Joined multicast group " + dnet.ip6_ntoa(dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_upper)[13:])) for host_lower in self.lower_add: hosts.append(host_lower) (ip_lower, rand_mac_lower, iter_lower) = self.lower_add[host_lower] mld = struct.pack("!xxHBBH16s", 1, 4, 0, 0, dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_lower)[13:]) icmp6 = dpkt.icmp6.ICMP6( type=143, code=0, data=mld ) icmp6_str = str(icmp6) ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_lower), dst=dnet.ip6_aton("ff02::16"), nxt=dpkt.ip.IP_PROTO_HOPOPTS, hlim=1, data=icmp6, plen=len(icmp6_str) + 8 ) ip6.extension_hdrs={} for i in dpkt.ip6.ext_hdrs: ip6.extension_hdrs[i]=None ip6.extension_hdrs[dpkt.ip.IP_PROTO_HOPOPTS] = dpkt.ip6.IP6HopOptsHeader(nxt=dpkt.ip.IP_PROTO_ICMP6, data=struct.pack("!BBHBB", 5, 2, 0, 1, 0)) ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6) icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str) eth = dpkt.ethernet.Ethernet( dst=dnet.eth_aton("33:33:00:00:00:16"), src=self.mac, data=str(ip6), type=dpkt.ethernet.ETH_TYPE_IP6 ) self.dnet.send(str(eth)) self.log("ICMP6: Joined multicast group " + dnet.ip6_ntoa(dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_lower)[13:])) self.upper_add = {} self.lower_add = {} return (data, org_data, hosts)