def ICMPPortUnreachable(version, srcaddr, dstaddr, packet):
    if version == 4:
        # Linux hardcodes the ToS on ICMP errors to 0xc0 or greater because of
        # RFC 1812 4.3.2.5 (!).
        return ("ICMPv4 port unreachable",
                scapy.IP(src=srcaddr, dst=dstaddr, proto=1, tos=0xc0) /
                scapy.ICMPerror(type=3, code=3) / packet)
    else:
        return ("ICMPv6 port unreachable",
                scapy.IPv6(src=srcaddr, dst=dstaddr) /
                scapy.ICMPv6DestUnreach(code=4) / packet)
示例#2
0
def ICMPPacketTooBig(version, srcaddr, dstaddr, packet):
  if version == 4:
    return ("ICMPv4 fragmentation needed",
            scapy.IP(src=srcaddr, dst=dstaddr, proto=1) /
            scapy.ICMPerror(type=3, code=4, unused=1280) / str(packet)[:64])
  else:
    udp = packet.getlayer("UDP")
    udp.payload = str(udp.payload)[:1280-40-8]
    return ("ICMPv6 Packet Too Big",
            scapy.IPv6(src=srcaddr, dst=dstaddr) /
            scapy.ICMPv6PacketTooBig() / str(packet)[:1232])
def ICMPPacketTooBig(version, srcaddr, dstaddr, packet):
    if version == 4:
        desc = "ICMPv4 fragmentation needed"
        pkt = (scapy.IP(src=srcaddr, dst=dstaddr, proto=1) /
               scapy.ICMPerror(type=3, code=4) / str(packet)[:64])
        # Only newer versions of scapy understand that since RFC 1191, the last two
        # bytes of a fragmentation needed ICMP error contain the MTU.
        if hasattr(scapy.ICMP, "nexthopmtu"):
            pkt[scapy.ICMPerror].nexthopmtu = PTB_MTU
        else:
            pkt[scapy.ICMPerror].unused = PTB_MTU
        return desc, pkt
    else:
        return ("ICMPv6 Packet Too Big", scapy.IPv6(src=srcaddr, dst=dstaddr) /
                scapy.ICMPv6PacketTooBig(mtu=PTB_MTU) / str(packet)[:1232])