Exemple #1
0
	def _dissect(self, buf):
		# Needed by _parse_flags()
		self.present_flags = unpack_I(buf[4:8])[0]
		#logger.debug("Flags: 0x%X" % flags)
		pos_end = len(buf)

		# Check for FSC, needs to be skipped for upper layers
		if self.present_flags & FLAGS_MASK == FLAGS_MASK:
			#logger.debug("Flags mask matched")
			flags_off = 8
			# TSFT present -> Flags values are after TSFT value
			if self.present_flags & TSFT_MASK == TSFT_MASK:
				flags_off = 8 + 8
			if buf[flags_off] & 0x10 != 0:
				#logger.debug("FCS found")
				self._fcs = buf[-4:]
				pos_end = -4

		hdr_len = unpack_H_le(buf[2:4])[0]
		#logger.debug("Bytes for flags (%d): %s" % (hdr_len, buf[8: hdr_len]))
		self._init_triggerlist("flags", buf[8: hdr_len], self._parse_flags)
		#logger.debug("rtap bytes:=%r" % buf[:hdr_len])
		# now we got the correct header length
		self._init_handler(RTAP_TYPE_80211, buf[hdr_len: pos_end])
		#logger.debug("Adding %d flags" % len(self.flags))
		return hdr_len
Exemple #2
0
    def extract_certificates(self):
        """
		Extracts certificates from a Handshake packet
		Workflow:
			find 1# cert segment(SSL.get_cert_length()) -> collect/assemble until
			cert length collected -> create SSL(tcp_bytes) -> ssl.handshake.extract_certs()
		return -- [cert1, cert2, ...]
		"""
        ret = []

        if self.type != HNDS_CERTIFICATE:
            logger.warning("not a certificate handshake: %r", self)
            return ret

        bts_body = self.body_bytes
        certs_len = self.len_i - 3
        #logger.debug("total cert length: %d", certs_len)
        # skip total cert length
        off = 3

        while off < certs_len:
            cert_len = unpack_I(b"\x00" + bts_body[off:off + 3])[0]
            #logger.debug("cert length: %d", cert_len)
            cert_bytes = bts_body[off + 3:off + 3 + cert_len]
            off += 3 + cert_len
            ret.append(cert_bytes)

        return ret
Exemple #3
0
def count_and_dissect_tlvs(buf):
    """
	Count and dissect TLVs. Return length of LLDP layer

	buf -- buffer to dissect
	return -- parsed_bytes_total, [(clz, bts), ...]
	"""
    shift = 0
    tlv_type, tlv_len = 1, 1
    clz_bts_list = []

    while (tlv_type | tlv_len) != 0:
        type_and_len = unpack_H(buf[shift:shift + TLV_HEADER_LEN])[0]
        # get tlv length and type
        tlv_type = (type_and_len & TYPE_MASK) >> LENGTH_FIELD_BITS
        tlv_len = type_and_len & LENGTH_MASK

        if tlv_type != ORG_SPEC_TYPE:
            clz = LLDP_TLV_CLS.get(tlv_type, LLDPGeneric)
        else:
            oui_subtype = unpack_I(
                buf[shift + TLV_HEADER_LEN:shift + ORG_SPEC_HEADER_LEN +
                    TLV_HEADER_LEN])[0]
            oui = (oui_subtype & OUI_MASK) >> SUBTYPE_LEN_BITS
            subtype = oui_subtype & SUBTYPE_MASK
            clz = LLDP_ORG_SPEC_TLV_CLS.get((oui, subtype), LLDPOrgSpecGeneric)
        # get body bytes
        tlv_body = buf[shift:tlv_len + shift + TLV_HEADER_LEN]
        # update shift to begin of next TLV (TLV_HEADER_LEN:2 + content:x)
        shift += TLV_HEADER_LEN + tlv_len
        clz_bts_list.append((clz, tlv_body))

    return shift, clz_bts_list
Exemple #4
0
    def _dissect(self, buf):
        # parse chunks
        chunks = []
        off = 12
        blen = len(buf)

        # logger.debug("SCTP: parsing chunks")
        chunktype = -1

        # TODO: use lazy dissect, possible?
        while off + 4 < blen:
            dlen = unpack_H(buf[off + 2:off + 4])[0]
            # check for padding (this should be a data chunk)
            if off + dlen < blen:
                self.padding = buf[off + dlen:]
                # logger.debug("found padding: %s" % self.padding)

            chunk = Chunk(buf[off:off + dlen])
            # logger.debug("SCTP: Chunk; %s " % chunk)
            chunks.append(chunk)

            # get payload chunktype from DATA chunks
            if chunk.type == 0:
                chunktype = unpack_I(buf[off + chunk.header_len + 8:off +
                                         chunk.header_len + 8 + 4])[0]
                # logger.debug("got DATA chunk, chunktype: %d" % chunktype)
                # remove data from chunk: use bytes for handler
                chunk.body_bytes = b""
                off += len(chunk)
                # assume DATA is the last chunk
                break

            off += dlen

        self.chunks.extend(chunks)

        chunktype = unpack_H(buf[2:4])[0]
        self._init_handler(chunktype, buf[off:-len(self.padding)])
        return off
Exemple #5
0
    def _dissect(self, buf):
        flags = self._present_flags = unpack_I(buf[4:8])[0]
        pos_end = len(buf)

        if flags & FLAGS_MASK == FLAGS_MASK:
            off = 0

            if flags & TSFT_MASK == TSFT_MASK:
                off = 8
            if buf[off] & 0x10 != 0:
                #logger.debug("fcs found")
                self._fcs = buf[-4:]
                pos_end = -4

        hdr_len = unpack_H_le(buf[2:4])[0]
        #logger.debug("hdr length is: %d" % hdr_len)
        self._init_triggerlist("flags", buf[8:hdr_len], self._parse_flags)
        #logger.debug("rtap bytes:=%r" % buf[:hdr_len])
        # now we got the correct header length
        self._init_handler(RTAP_TYPE_80211, buf[hdr_len:pos_end])
        #logger.debug(adding %d flags" % len(self.flags))
        return hdr_len
Exemple #6
0
 def __get_crcinit_rev_int(self):
     return unpack_I(b"\x00" + self.crcinit_rev)[0]