コード例 #1
0
ファイル: UDP6.py プロジェクト: umitproject/umpa
    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits):
        """
        """

        cksum_rev_offset = 0
        # checking if user not defined his own value of checksum
        if _bits.get_bits(raw_value, self.get_field('_checksum').bits,
                                    cksum_rev_offset, rev_offset=True) == 0:
            # Payload
            if self.payload:
                cksum = self.payload.__dict__['__raw_value']
            else:
                cksum = 0
            offset = protocol_bits

            # UDP Header
            cksum |= raw_value << offset
            offset += bit

            # Pseudo Header
            #
            # create pseudo header object
            pheader = _layer4_ipv6.PseudoHeader(self.protocol_id,
                                        self.get_field('_length').fillout())
            # generate raw value of it
            pheader_raw = pheader.get_raw(protocol_container, protocol_bits)[0]
            # added pseudo header bits to cksum value
            cksum |= pheader_raw << offset

            # finally, calcute and apply checksum
            raw_cksum = _net.in_cksum(cksum)
            cksum_cal = ((raw_cksum << 8) | (raw_cksum >> 8)) & 0xFFFF
            raw_value |= cksum_cal << cksum_rev_offset

        return raw_value, bit
コード例 #2
0
ファイル: IP.py プロジェクト: umitproject/umpa
    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits):
        """
        Handle with fields after calling fillout() for them.

        Calculate header checksum.

        @type raw_value: C{int}
        @param raw_value: currently raw value for the packet.

        @type bit: C{int}
        @param bit: currently length of the protocol.

        @type protocol_container: C{tuple}
        @param protocol_container: tuple of protocols included in the packet.

        @type protocol_bits: C{int}
        @param protocol_bits: currently length of the packet.

        @return: C{raw_value, bit}
        """

        # Header Checksum
        # a checksum on the header only.
        cksum_offset = bit - self.get_offset('_checksum') - \
                                    self.get_field('_checksum').bits
        # check if user doesn't provide own values of bits
        if _bits.get_bits(raw_value,
                        self.get_field('_checksum').bits,
                        cksum_offset,
                        rev_offset=True) == 0:
            # calculate and add checksum to the raw_value
            cksum = _net.in_cksum(raw_value)
            raw_value |= cksum << cksum_offset

        return raw_value, bit
コード例 #3
0
    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits):
        """
        Handle with fields after calling fillout() for them.

        Calculate header checksum.

        @type raw_value: C{int}
        @param raw_value: currently raw value for the packet.

        @type bit: C{int}
        @param bit: currently length of the protocol.

        @type protocol_container: C{tuple}
        @param protocol_container: tuple of protocols included in the packet.

        @type protocol_bits: C{int}
        @param protocol_bits: currently length of the packet.

        @return: C{raw_value, bit}
        """

        # Header Checksum
        # a checksum on the header only.
        cksum_offset = bit - self.get_offset('_checksum') - \
                                    self.get_field('_checksum').bits
        # check if user doesn't provide own values of bits
        if _bits.get_bits(raw_value,
                          self.get_field('_checksum').bits,
                          cksum_offset,
                          rev_offset=True) == 0:
            # calculate and add checksum to the raw_value
            cksum = _net.in_cksum(raw_value)
            raw_value |= cksum << cksum_offset

        return raw_value, bit
コード例 #4
0
    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits):
        """
        """
        print "proto bit "
        print protocol_bits

        # Fill checksum only if it's zero (not supplied by user)
        cksum_offset = bit - self.get_offset('_checksum') - \
                       self.get_field('_checksum').bits

        if _bits.get_bits(raw_value,self.get_field('_checksum').bits,cksum_offset,rev_offset=True) == 0:

            # calculate checksum and place it at the correct offset in raw_value
            cksum = _net.in_cksum(raw_value)
            raw_value |= cksum << cksum_offset

        return raw_value, bit
コード例 #5
0
ファイル: ICMPV6.py プロジェクト: umitproject/umpa
    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits):
        """
        """
        
        # Fill checksum only if it's zero (not supplied by user)
        cksum_offset = bit - self.get_offset('_checksum') - \
                       self.get_field('_checksum').bits

        #self.get_field('_checksum')._tmp_value  = 32699
        if _bits.get_bits(raw_value,self.get_field('_checksum').bits,cksum_offset,rev_offset=True) == 0:

            # Payload
            if self.payload:
                cksum = self.payload.__dict__['__raw_value']
            else:
                cksum = 0
            offset = protocol_bits

            # TCP Header
            cksum |= raw_value << offset
            offset += bit
            
            # calculate checksum and place it at the correct offset in raw_value
            total_length = offset
            total_length /= 8
            pheader = _layer4_ipv6.PseudoHeader6(self.protocol_id, total_length)
            pheader_raw = pheader.get_raw(protocol_container, protocol_bits)[0]
            cksum |= pheader_raw << offset
            raw_cksum = _net.in_cksum(cksum)
            cksum_cal = ((raw_cksum << 8) | (raw_cksum >> 8)) & 0xFFFF
            raw_value |= cksum_cal << cksum_offset
            #cksum = _net.in_cksum(raw_value)
            #raw_value |= cksum << cksum_offset
            #self.get_field('_checksum')._tmp_value  = 32699

        return raw_value, bit
コード例 #6
0
ファイル: TCP6.py プロジェクト: umitproject/umpa
    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits):
        """
        Handle with fields after calling fillout() for them.

        Calculate header checksum with new instance of PseudoHeader object.

        @type raw_value: C{int}
        @param raw_value: currently raw value for the packet.

        @type bit: C{int}
        @param bit: currently length of the protocol.

        @type protocol_container: C{tuple}
        @param protocol_container: tuple of protocols included in the packet.

        @type protocol_bits: C{int}
        @param protocol_bits: currently length of the packet.

        @return: C{raw_value, bit}
        """

        # rev_offset it the offset from the right side
        cksum_rev_offset = bit - self.get_offset('_checksum') - \
                                            self.get_field('_checksum').bits

        # checking if user not defined his own value of checksum
        if _bits.get_bits(raw_value,
                          self.get_field('_checksum').bits,
                          cksum_rev_offset,
                          rev_offset=True) == 0:
            # Payload
            if self.payload:
                cksum = self.payload.__dict__['__raw_value']
            else:
                cksum = 0

            offset = protocol_bits

            # TCP Header
            cksum |= raw_value << offset

            offset += bit

            # Pseudo Header
            #
            # TCP header length...converted to bits unit
            total_length = self.get_field('_hdr_len').fillout() * 32
            # add payload
            total_length += protocol_bits
            # conversion to bytes unit
            total_length /= 8

            # create pseudo header object
            #in _layer4_ipv6 also need to add ipv6 notation
            #
            pheader = _layer4_ipv6.PseudoHeader6(self.protocol_id,
                                                 total_length)
            # generate raw value of it
            pheader_raw = pheader.get_raw(protocol_container, protocol_bits)[0]

            # added pseudo header bits to cksum value

            cksum |= pheader_raw << offset

            # finally, calcute and apply checksum
            raw_cksum = _net.in_cksum(cksum)
            # To swap last two byte of tcp checksum
            cksum_cal = ((raw_cksum << 8) | (raw_cksum >> 8)) & 0xFFFF

            raw_value |= cksum_cal << cksum_rev_offset

        return raw_value, bit
コード例 #7
0
ファイル: TCP6.py プロジェクト: umitproject/umpa
    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits):
        """
        Handle with fields after calling fillout() for them.

        Calculate header checksum with new instance of PseudoHeader object.

        @type raw_value: C{int}
        @param raw_value: currently raw value for the packet.

        @type bit: C{int}
        @param bit: currently length of the protocol.

        @type protocol_container: C{tuple}
        @param protocol_container: tuple of protocols included in the packet.

        @type protocol_bits: C{int}
        @param protocol_bits: currently length of the packet.

        @return: C{raw_value, bit}
        """

        # rev_offset it the offset from the right side
        cksum_rev_offset = bit - self.get_offset('_checksum') - \
                                            self.get_field('_checksum').bits

        
        
        # checking if user not defined his own value of checksum
        if _bits.get_bits(raw_value, self.get_field('_checksum').bits,
                                    cksum_rev_offset, rev_offset=True) == 0:
            # Payload
            if self.payload:
                cksum = self.payload.__dict__['__raw_value']
            else:
                cksum = 0
                
            offset = protocol_bits

            # TCP Header
            cksum |= raw_value << offset

            offset += bit

            # Pseudo Header
            #
            # TCP header length...converted to bits unit
            total_length = self.get_field('_hdr_len').fillout()*32
            # add payload
            total_length += protocol_bits
            # conversion to bytes unit
            total_length /= 8

            # create pseudo header object
            #in _layer4_ipv6 also need to add ipv6 notation
            #
            pheader = _layer4_ipv6.PseudoHeader6(self.protocol_id, total_length)
            # generate raw value of it
            pheader_raw = pheader.get_raw(protocol_container, protocol_bits)[0]

            # added pseudo header bits to cksum value

            cksum |= pheader_raw << offset

            # finally, calcute and apply checksum
            raw_cksum = _net.in_cksum(cksum)
            # To swap last two byte of tcp checksum
            cksum_cal = ((raw_cksum << 8) | (raw_cksum >> 8)) & 0xFFFF

            
            raw_value |= cksum_cal << cksum_rev_offset
            

        return raw_value, bit
コード例 #8
0
ファイル: UDP.py プロジェクト: umitproject/umpa
    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits):
        """
        Handle with fields after calling fillout() for them.

        Calculate header checksum with new instance of PseudoHeader object.

        @type raw_value: C{int}
        @param raw_value: currently raw value for the packet.

        @type bit: C{int}
        @param bit: currently length of the protocol.

        @type protocol_container: C{tuple}
        @param protocol_container: tuple of protocols included in the packet.

        @type protocol_bits: C{int}
        @param protocol_bits: currently length of the packet.

        @return: C{raw_value, bit}
        """

        cksum_rev_offset = 0
        # checking if user not defined his own value of checksum
        if _bits.get_bits(raw_value,
                          self.get_field('_checksum').bits,
                          cksum_rev_offset,
                          rev_offset=True) == 0:
            # Payload
            if self.payload:
                cksum = self.payload.__dict__['__raw_value']
            else:
                cksum = 0
            offset = protocol_bits

            # UDP Header
            cksum |= raw_value << offset
            offset += bit

            # Pseudo Header
            #
            # create pseudo header object
            it = iter(protocol_container)
            for proto in it:
                if isinstance(proto, IPV6):
                    pheader = _layer4_ipv6.PseudoHeader6(
                        self.protocol_id,
                        self.get_field('_length').fillout())
                    pheader_raw = pheader.get_raw(protocol_container,
                                                  protocol_bits)[0]
                    cksum |= pheader_raw << offset
                    raw_cksum = _net.in_cksum(cksum)
                    if proto.dst == '0000:0000:0000:0000:0000:0000:0000:0001' and proto.src == '0000:0000:0000:0000:0000:0000:0000:0001':
                        cksum_cal = ((raw_cksum << 8) |
                                     (raw_cksum >> 8)) & 0xFFFF
                    else:
                        cksum_cal = raw_cksum

                    #cksum_cal = ((raw_cksum << 8) | (raw_cksum >> 8)) & 0xFFFF
                    #cksum_cal = raw_cksum
                    raw_value |= cksum_cal << cksum_rev_offset
                elif isinstance(proto, IP):
                    pheader = _layer4.PseudoHeader(
                        self.protocol_id,
                        self.get_field('_length').fillout())
                    pheader_raw = pheader.get_raw(protocol_container,
                                                  protocol_bits)[0]
                    cksum |= pheader_raw << offset
                    raw_cksum = _net.in_cksum(cksum)
                    raw_value |= raw_cksum << cksum_rev_offset

            #pheader = _layer4.PseudoHeader(self.protocol_id,self.get_field('_length').fillout())

            # generate raw value of it
            #pheader_raw = pheader.get_raw(protocol_container, protocol_bits)[0]
            # added pseudo header bits to cksum value
            #cksum |= pheader_raw << offset

            # finally, calcute and apply checksum
            #raw_cksum = _net.in_cksum(cksum)
            #raw_value |= raw_cksum << cksum_rev_offset

        return raw_value, bit