コード例 #1
0
    def get_raw_packet(self, ip_pseudo_header):
        """ Get packet in raw format ready to be processed by lower level protocol """

        self.tcp_cksum = inet_cksum.compute_cksum(ip_pseudo_header +
                                                  self.raw_packet)

        return self.raw_packet
コード例 #2
0
    def get_raw_packet(self):
        """ Get packet in raw format ready to be processed by lower level protocol """

        self.ipv4_cksum = inet_cksum.compute_cksum(self.raw_header +
                                                   self.raw_options)

        return self.raw_packet
コード例 #3
0
    def validate_cksum(self, ip_pseudo_header):
        """ Validate packet checksum """

        # from binascii import hexlify
        # print(hexlify(self.raw_packet))

        return not bool(
            inet_cksum.compute_cksum(ip_pseudo_header + self.raw_packet))
コード例 #4
0
ファイル: ps_udp.py プロジェクト: dmohnani/PyTCP
    def validate_cksum(self, ip_pseudo_header):
        """ Validate packet checksum """

        # Return valid checksum if checksum is not used
        if not self.udp_cksum:
            return True

        return not bool(
            inet_cksum.compute_cksum(ip_pseudo_header + self.raw_packet))
コード例 #5
0
ファイル: phrx_ip4.py プロジェクト: Saber-Bjeoui/PyTCP
def handle_ip4_fragmentation(ip4_packet_rx):
    """ Check if packet is fragmented """

    # Check if IP packet is a first fragment
    if ip4_packet_rx.ip4_frag_offset == 0 and ip4_packet_rx.ip4_frag_mf:
        ip4_fragments[ip4_packet_rx.ip4_packet_id] = {}
        ip4_fragments[ip4_packet_rx.ip4_packet_id][ip4_packet_rx.ip4_frag_offset] = ip4_packet_rx.raw_data
        return None

    # Check if IP packet is one of middle fragments
    if ip4_packet_rx.ip4_frag_offset != 0 and ip4_packet_rx.ip4_frag_mf:
        # Check if packet is part of existing fagment flow
        if ip4_fragments.get(ip4_packet_rx.ip4_packet_id, None):
            ip4_fragments[ip4_packet_rx.ip4_packet_id][ip4_packet_rx.ip4_frag_offset] = ip4_packet_rx.raw_data
        return None

    # Check if IP packet is last fragment
    if ip4_packet_rx.ip4_frag_offset != 0 and not ip4_packet_rx.ip4_frag_mf:

        # Check if packet is part of existing fagment flow
        if ip4_fragments.get(ip4_packet_rx.ip4_packet_id, None):
            ip4_fragments[ip4_packet_rx.ip4_packet_id][ip4_packet_rx.ip4_frag_offset] = ip4_packet_rx.raw_data

            raw_data = b""
            for offset in sorted(ip4_fragments[ip4_packet_rx.ip4_packet_id]):
                raw_data += ip4_fragments[ip4_packet_rx.ip4_packet_id][offset]

            # Craft complete IP packet based on last fragment for further processing
            ip4_packet_rx.ip4_frag_mf = False
            ip4_packet_rx.ip4_frag_offset = 0
            ip4_packet_rx.ip4_plen = ip4_packet_rx.ip4_hlen + len(raw_data)
            ip4_packet_rx.ip4_cksum = 0
            ip4_packet_rx.ip4_cksum = inet_cksum.compute_cksum(ip4_packet_rx.raw_header)
            ip4_packet_rx.raw_data = raw_data

    return ip4_packet_rx
コード例 #6
0
ファイル: ps_icmpv4.py プロジェクト: dmohnani/PyTCP
    def validate_cksum(self):
        """ Validate packet checksum """

        return not bool(inet_cksum.compute_cksum(self.raw_packet))
コード例 #7
0
    def validate_cksum(self, ip_pseudo_header):
        """ Validate packet checksum """

        return not bool(
            inet_cksum.compute_cksum(ip_pseudo_header + self.raw_packet))
コード例 #8
0
    def validate_cksum(self):
        """ Validate packet checksum """

        return not bool(inet_cksum.compute_cksum(self.raw_header + self.raw_options))