Coverage for /private/tmp/im/impacket/impacket/ICMP6.py : 55%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved. # # This software is provided under under a slightly modified version # of the Apache Software License. See the accompanying LICENSE file # for more information. #
#IP Protocol number for ICMP6
#Size of ICMP6 header (excluding payload)
#ICMP6 Message Type numbers
#Destination Unreachable codes
#Time Exceeded codes
#Parameter problem codes
#Node Information codes
#Node Information qtypes
#ICMP Message semantic types (error or informational)
#ICMP message dictionary - specifying text descriptions and valid message codes #Key: ICMP message number #Data: Tuple ( Message Type (error/informational), Text description, Codes dictionary (can be None) ) #Codes dictionary #Key: Code number #Data: Text description
#ICMP message dictionary tuple indexes
DESTINATION_UNREACHABLE : (ERROR_MESSAGE, "Destination unreachable", { NO_ROUTE_TO_DESTINATION : "No route to destination", ADMINISTRATIVELY_PROHIBITED : "Administratively prohibited", BEYOND_SCOPE_OF_SOURCE_ADDRESS : "Beyond scope of source address", ADDRESS_UNREACHABLE : "Address unreachable", PORT_UNREACHABLE : "Port unreachable", SOURCE_ADDRESS_FAILED_INGRESS_EGRESS_POLICY : "Source address failed ingress/egress policy", REJECT_ROUTE_TO_DESTINATION : "Reject route to destination" }), PACKET_TOO_BIG : (ERROR_MESSAGE, "Packet too big", None), TIME_EXCEEDED : (ERROR_MESSAGE, "Time exceeded", {HOP_LIMIT_EXCEEDED_IN_TRANSIT : "Hop limit exceeded in transit", FRAGMENT_REASSEMBLY_TIME_EXCEEDED : "Fragment reassembly time exceeded" }), PARAMETER_PROBLEM : (ERROR_MESSAGE, "Parameter problem", { ERRONEOUS_HEADER_FIELD_ENCOUNTERED : "Erroneous header field encountered", UNRECOGNIZED_NEXT_HEADER_TYPE_ENCOUNTERED : "Unrecognized Next Header type encountered", UNRECOGNIZED_IPV6_OPTION_ENCOUNTERED : "Unrecognized IPv6 Option Encountered" }), ECHO_REQUEST : (INFORMATIONAL_MESSAGE, "Echo request", None), ECHO_REPLY : (INFORMATIONAL_MESSAGE, "Echo reply", None), ROUTER_SOLICITATION : (INFORMATIONAL_MESSAGE, "Router Solicitation", None), ROUTER_ADVERTISEMENT : (INFORMATIONAL_MESSAGE, "Router Advertisement", None), NEIGHBOR_SOLICITATION : (INFORMATIONAL_MESSAGE, "Neighbor Solicitation", None), NEIGHBOR_ADVERTISEMENT : (INFORMATIONAL_MESSAGE, "Neighbor Advertisement", None), REDIRECT_MESSAGE : (INFORMATIONAL_MESSAGE, "Redirect Message", None), NODE_INFORMATION_QUERY: (INFORMATIONAL_MESSAGE, "Node Information Query", None), NODE_INFORMATION_REPLY: (INFORMATIONAL_MESSAGE, "Node Information Reply", None), }
############################################################################
type = self.get_type() code = self.get_code() checksum = self.get_checksum()
s = "ICMP6 - Type: " + str(type) + " - " + self.__get_message_description() + "\n" s += "Code: " + str(code) if (self.__get_code_description() != ""): s += " - " + self.__get_code_description() s += "\n" s += "Checksum: " + str(checksum) + "\n" return s
return self.icmp_messages[self.get_type()][self.DESCRIPTION_INDEX]
code_dictionary = self.icmp_messages[self.get_type()][self.CODES_INDEX] if (code_dictionary is None): return "" else: return code_dictionary[self.get_code()]
############################################################################
return (self.get_word(2))
############################################################################
############################################################################ #Initialize the checksum value to 0 to yield a correct calculation #Fetch the pseudo header from the IP6 parent packet #Fetch the ICMP data #Build an array of bytes concatenating the pseudo_header, the ICMP header and the ICMP data (if present)
#Compute the checksum over that array
return self.icmp_messages[self.get_type()][self.MSG_TYPE_INDEX] == self.INFORMATIONAL_MESSAGE
return self.icmp_messages[self.get_type()][self.MSG_TYPE_INDEX] == self.ERROR_MESSAGE
well_formed = True
#Check that the message type is known well_formed &= self.get_type() in self.icmp_messages.keys()
#Check that the code is known (zero, if there are no codes defined) code_dictionary = self.icmp_messages[self.get_type()][self.CODES_INDEX] if (code_dictionary is None): well_formed &= self.get_code() == 0 else: well_formed &= self.get_code() in code_dictionary.keys()
return well_formed
############################################################################
def __build_echo_message(class_object, type, id, sequence_number, arbitrary_data): #Build ICMP6 header
#Pack ICMP payload
#Link payload to header
############################################################################
def __build_error_message(class_object, type, code, data, originating_packet_data): #Build ICMP6 header
#Pack ICMP payload
#Link payload to header
############################################################################
def Neighbor_Solicitation(class_object, target_address): return class_object.__build_neighbor_message(ICMP6.NEIGHBOR_SOLICITATION, target_address)
def Neighbor_Advertisement(class_object, target_address): return class_object.__build_neighbor_message(ICMP6.NEIGHBOR_ADVERTISEMENT, target_address)
def __build_neighbor_message(class_object, msg_type, target_address): #Build ICMP6 header icmp_packet = ICMP6() icmp_packet.set_type(msg_type) icmp_packet.set_code(0)
# Flags + Reserved icmp_bytes = array.array('B', [0x00] * 4).tostring()
# Target Address: The IP address of the target of the solicitation. # It MUST NOT be a multicast address. icmp_bytes += array.array('B', IP6_Address(target_address).as_bytes()).tostring()
icmp_payload = Data() icmp_payload.set_data(icmp_bytes)
#Link payload to header icmp_packet.contains(icmp_payload)
return icmp_packet
############################################################################
return IP6_Address(self.child().get_bytes()[4:20])
address = IP6_Address(target_address) payload_bytes = self.child().get_bytes() payload_bytes[4:20] = address.get_bytes() self.child().set_bytes(payload_bytes)
# 0 1 2 3 4 5 6 7 # +-+-+-+-+-+-+-+-+ # |R|S|O|reserved | # +-+-+-+-+-+-+-+-+
return self.child().get_byte(0)
self.child().set_byte(0, flags)
return (self.get_neighbor_advertisement_flags() & 0x80) != 0
curr_flags = self.get_neighbor_advertisement_flags() if flag_value: curr_flags |= 0x80 else: curr_flags &= ~0x80 self.set_neighbor_advertisement_flags(curr_flags)
return (self.get_neighbor_advertisement_flags() & 0x40) != 0
curr_flags = self.get_neighbor_advertisement_flags() if flag_value: curr_flags |= 0x40 else: curr_flags &= ~0x40 self.set_neighbor_advertisement_flags(curr_flags)
return (self.get_neighbor_advertisement_flags() & 0x20) != 0
curr_flags = self.get_neighbor_advertisement_flags() if flag_value: curr_flags |= 0x20 else: curr_flags &= ~0x20 self.set_neighbor_advertisement_flags(curr_flags)
############################################################################ return class_object.__build_node_information_message(ICMP6.NODE_INFORMATION_QUERY, code, payload)
return class_object.__build_node_information_message(ICMP6.NODE_INFORMATION_REPLY, code, payload)
#Build ICMP6 header icmp_packet = ICMP6() icmp_packet.set_type(type) icmp_packet.set_code(code)
#Pack ICMP payload qtype = 0 flags = 0 nonce = [0x00] * 8
icmp_bytes = struct.pack('>H', qtype) icmp_bytes += struct.pack('>H', flags) icmp_bytes += array.array('B', nonce).tostring()
if payload is not None: icmp_bytes += array.array('B', payload).tostring()
icmp_payload = Data() icmp_payload.set_data(icmp_bytes)
#Link payload to header icmp_packet.contains(icmp_payload)
return icmp_packet
return self.child().get_word(0)
self.child().set_word(0, qtype)
return self.child().get_bytes()[4:12]
payload_bytes = self.child().get_bytes() payload_bytes[4:12] = array.array('B', nonce) self.child().set_bytes(payload_bytes)
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # | unused |G|S|L|C|A|T| # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
return self.child().get_word(2)
self.child().set_word(2, flags)
return (self.get_flags() & 0x0001) != 0
curr_flags = self.get_flags() if flag_value: curr_flags |= 0x0001 else: curr_flags &= ~0x0001 self.set_flags(curr_flags)
return (self.get_flags() & 0x0002) != 0
curr_flags = self.get_flags() if flag_value: curr_flags |= 0x0002 else: curr_flags &= ~0x0002 self.set_flags(curr_flags)
return (self.get_flags() & 0x0004) != 0
curr_flags = self.get_flags() if flag_value: curr_flags |= 0x0004 else: curr_flags &= ~0x0004 self.set_flags(curr_flags)
return (self.get_flags() & 0x0008) != 0
curr_flags = self.get_flags() if flag_value: curr_flags |= 0x0008 else: curr_flags &= ~0x0008 self.set_flags(curr_flags)
return (self.get_flags() & 0x0010) != 0
curr_flags = self.get_flags() if flag_value: curr_flags |= 0x0010 else: curr_flags &= ~0x0010 self.set_flags(curr_flags)
return (self.get_flags() & 0x0020) != 0
curr_flags = self.get_flags() if flag_value: curr_flags |= 0x0020 else: curr_flags &= ~0x0020 self.set_flags(curr_flags)
payload_bytes = self.child().get_bytes() payload_bytes[12:] = array.array('B', data) self.child().set_bytes(payload_bytes)
return self.child().get_bytes()[12:]
############################################################################
|