Coverage for /private/tmp/im/impacket/impacket/cdp.py : 47%

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. # # Description: # Cisco Discovery Protocol packet codecs. # # Author: # Martin Candurra # martincad at corest.com
Header.__init__(self, 8) if aBuffer: self.load_header(aBuffer) self._elements = self._getElements(aBuffer)
# Remove version (1 byte), TTL (1 byte), and checksum (2 bytes) buff = aBuffer[4:] l = [] while buff: elem = CDPElementFactory.create(buff) l.append( elem ) buff = buff[ elem.get_length() : ] return l
return 8
return self.get_byte(0)
return self.get_byte(1)
return self.get_word(2)
return self.get_word(4)
return self.get_word(6)
return self._elements
tmp_str = 'CDP Details:\n' for element in self._elements: tmp_str += "** Type:" + str(element.get_type()) + " " + str(element) + "\n" return tmp_str
return unpack("!B", buffer[offset:offset+1])[0]
return unpack("!h", buffer[offset:offset+2])[0]
return unpack("!I", buffer[offset:offset+4])[0]
return buffer[offset:offset + bytes]
bytes = unpack('!BBBBBB', mac_bytes) s = '' for byte in bytes: s += '%02x:' % byte return s[0:-1]
Header.__init__(self, 8) if aBuffer: self._length = CDPElement.Get_length(aBuffer) self.load_header( aBuffer[:self._length] )
def Get_length(cls, aBuffer): return unpack('!h', aBuffer[2:4])[0]
self._length
return self.get_word(2)
return self.get_bytes().tostring()[4:self.get_length()]
if not ip: ip = self.get_bytes().tostring()[offset : offset + IP_ADDRESS_LENGTH] return socket.inet_ntoa( ip )
return CDPDevice.Type
return CDPElement.get_data(self)
return "Device:" + self.get_device_id()
CDPElement.__init__(self, aBuffer) if aBuffer: data = self.get_bytes().tostring()[8:] self._generateAddressDetails(data)
self.address_details = [] while buff: address = AddressDetails.create(buff) self.address_details.append( address ) buff = buff[address.get_total_length():]
return Address.Type
return self.get_long(4)
return self.address_details
tmp_str = "Addresses:" for address_detail in self.address_details: tmp_str += "\n" + str(address_detail) return tmp_str
def create(cls, buff): a = AddressDetails(buff) return a
if aBuffer: addr_length = unpack("!h", aBuffer[3:5])[0] self.total_length = addr_length + 5 self.buffer = aBuffer[:self.total_length]
return self.total_length
return self.buffer[0:1]
return get_byte( self.buffer, 1)
return get_byte( self.buffer, 2)
return get_word( self.buffer, 3)
address = get_bytes( self.buffer, 5, self.get_address_length() ) if self.get_protocol()==AddressDetails.PROTOCOL_IP: return socket.inet_ntoa(address) else: LOG.error("Address not IP") return address
return self.get_protocol()==AddressDetails.PROTOCOL_IP
return "Protocol Type:%r Protocol:%r Address Length:%r Address:%s" % (self.get_protocol_type(), self.get_protocol(), self.get_address_length(), self.get_address())
return Port.Type
return CDPElement.get_data(self)
return "Port:" + self.get_port()
CDPElement.__init__(self, aBuffer) self._capabilities_processed = False
self._router = False self._transparent_bridge = False self._source_route_bridge = False self._switch = False self._host = False self._igmp_capable = False self._repeater = False self._init_capabilities()
return Capabilities.Type
return CDPElement.get_data(self)
if self._capabilities_processed: return
capabilities = unpack("!L", self.get_capabilities())[0] self._router = (capabilities & 0x1) > 0 self._transparent_bridge = (capabilities & 0x02) > 0 self._source_route_bridge = (capabilities & 0x04) > 0 self._switch = (capabilities & 0x08) > 0 self._host = (capabilities & 0x10) > 0 self._igmp_capable = (capabilities & 0x20) > 0 self._repeater = (capabilities & 0x40) > 0
return self._router
return self._transparent_bridge
return self._source_route_bridge
return self._switch
return self.is_host
return self._igmp_capable
return self._repeater
return "Capabilities:" + self.get_capabilities()
return SoftVersion.Type
return CDPElement.get_data(self)
return "Version:" + self.get_version()
return Platform.Type
return CDPElement.get_data(self)
return "Platform:%r" % self.get_platform()
return IpPrefix .Type
return CDPElement.get_ip_address(self, 4)
return self.get_byte(8)
return "IP Prefix/Gateway: %r/%d" % (self.get_ip_prefix(), self.get_bits())
return ProtocolHello.Type
return self.get_ip_address(9)
return self.get_byte(17)
return self.get_byte(18)
return self.get_byte(19)
return self.get_bytes().tostring()[20:20+6]
return self.get_bytes().tostring()[28:28+6]
return self.get_word(36)
return "\n\n\nProcolHello: Master IP:%s version:%r subversion:%r status:%r Switch's Mac:%r Management VLAN:%r" \ % (self.get_master_ip(), self.get_version(), self.get_sub_version(), self.get_status(), mac_to_string(self.get_switch_mac()), self.get_management_vlan())
return VTPManagementDomain.Type
return CDPElement.get_data(self)
return Duplex.Type
return CDPElement.get_data(self)
return self.get_duplex()==0x1
return VLAN.Type
return CDPElement.get_data(self)
return TrustBitmap.Type
return self.get_data()
return "TrustBitmap Trust Bitmap:%r" % self.get_trust_bitmap()
return UntrustedPortCoS.Type
return self.get_data()
return "UntrustedPortCoS port CoS %r" % self.get_port_CoS()
return ManagementAddresses.Type
return MTU.Type
return SystemName.Type
return SystemObjectId.Type
return SnmpLocation.Type
return DummyCdpElement.Type
CDPDevice.Type : CDPDevice, Port.Type : Port, Capabilities.Type : Capabilities, Address.Type : Address, SoftVersion.Type : SoftVersion, Platform.Type : Platform, IpPrefix.Type : IpPrefix, ProtocolHello.Type : ProtocolHello, VTPManagementDomain.Type : VTPManagementDomain, VLAN.Type : VLAN, Duplex.Type : Duplex, TrustBitmap.Type : TrustBitmap, UntrustedPortCoS.Type : UntrustedPortCoS, ManagementAddresses.Type : ManagementAddresses, MTU.Type : MTU, SystemName.Type : SystemName, SystemObjectId.Type : SystemObjectId, SnmpLocation.Type : SnmpLocation }
def create(cls, aBuffer): # print "CDPElementFactory.create aBuffer:", repr(aBuffer) # print "CDPElementFactory.create sub_type:", repr(aBuffer[0:2]) _type = unpack("!h", aBuffer[0:2])[0] # print "CDPElementFactory.create _type:", _type try: class_type = cls.elementTypeMap[_type] except KeyError: class_type = DummyCdpElement #raise Exception("CDP Element type %s not implemented" % _type) return class_type( aBuffer ) |