def ICMPExtension_post_dissection(self, pkt): # RFC4884 section 5.2 says if the ICMP packet length # is >144 then ICMP extensions start at byte 137. lastlayer = pkt.lastlayer() if not isinstance(lastlayer, conf.padding_layer): return if IP in pkt: if (ICMP in pkt and pkt[ICMP].type in [3, 11, 12] and pkt.len > 144): bytes = pkt[ICMP].build()[136:] else: return elif scapy.layers.inet6.IPv6 in pkt: if ((scapy.layers.inet6.ICMPv6TimeExceeded in pkt or scapy.layers.inet6.ICMPv6DestUnreach in pkt) and pkt.plen > 144): bytes = pkt[scapy.layers.inet6.ICMPv6TimeExceeded].build()[136:] else: return else: return # validate checksum ieh = ICMPExtensionHeader(bytes) if checksum(ieh.build()): return # failed lastlayer.load = lastlayer.load[:-len(ieh)] lastlayer.add_payload(ieh)
def post_build(self, p, pay): p += pay if self.Length is None: tmp_len = len(p) tmp_p = p[:6] + chb((tmp_len >> 8) & 0xff) + chb(tmp_len & 0xff) p = tmp_p + p[8:] if self.chksum is None: ck = checksum(p) p = p[:2] + chb(ck >> 8) + chb(ck & 0xff) + p[4:] return p
def post_build(self, p, pay): p += pay if self.Length is None: tmp_len = len(p) tmp_p = p[:6] + chb((tmp_len >> 8) & 0xff) + chb(tmp_len & 0xff) p = tmp_p + p[8:] if self.chksum is None: ck = checksum(p) p = p[:2] + chb(ck >> 8) + chb(ck & 0xff) + p[4:] return p
def post_build(self, pkt, pay): p = pkt + pay if self.cksum is None: cksum = checksum(self._check_len(p)) p = p[:2] + struct.pack("!H", cksum) + p[4:] return p
def post_build(self, p, pay): p += pay if self.chksum is None: c = checksum(p) p = p[:2] + chb((c >> 8) & 0xff) + chb(c & 0xff) + p[4:] return p
def post_build(self, p, pay): if self.chksum is None: ck = checksum(p) p = p[:6] + chb(ck >> 8) + chb(ck & 0xff) + p[8:] return p
def post_build(self, p, pay): p += pay if self.chksum is None: c = checksum(p) p = p[:2] + chb((c >> 8) & 0xff) + chb(c & 0xff) + p[4:] return p
def post_build(self, pkt, pay): p = pkt + pay if self.cksum is None: cksum = checksum(self._check_len(p)) p = p[:2] + struct.pack("!H", cksum) + p[4:] return p
def post_build(self, p, pay): if self.chksum is None: ck = checksum(p) p = p[:6] + chb(ck >> 8) + chb(ck & 0xff) + p[8:] return p