Beispiel #1
0
    def fragment(self):
        pac = self.packet
        self.src_ip = Converter.get_decoded_ip(pac[:4])
        self.req_type = ord(pac[4])

        if self.req_type <= 0 or self.req_type > 5:
            self.isvalid = 0
            return

        if self.req_type < 4:
            #they bore a format shown above
            #get the data length
            if len(pac) < 6:
                self.isvalid = 0
                return
            len_dat = ord(pac[5]) * 256 + ord(pac[6])

            #check if length is within the bounds
            if len_dat + 7 >= len(pac):
                self.isvalid = 0
                return
            self.dat = pac[7:7 + len_dat]

            #get the key length
            key_len = ord(pac[7 + len_dat]) * 256 + ord(pac[7 + len_dat + 1])

            #check the format of the packet
            if len(self.packet) != 4 + 1 + 2 + 2 + len_dat + key_len:
                self.isvalid = 0
                return
            self.key = pac[7 + len_dat + 2:7 + len_dat + 2 + key_len]

        else:
            #this will have simple format
            self.dat = pac[5:]
Beispiel #2
0
	def fragment(self):
		pac = self.packet
		self.src_ip = Converter.get_decoded_ip(pac[:4])
		self.req_type = ord(pac[4])

		if self.req_type<=0 or self.req_type>5:
			self.isvalid = 0
			return

		if self.req_type < 4:
			#they bore a format shown above
			#get the data length
			if len(pac)<6:
				self.isvalid = 0
				return
			len_dat = ord(pac[5])*256 + ord(pac[6])
			
			#check if length is within the bounds
			if len_dat+7 >= len(pac):
				self.isvalid = 0
				return
			self.dat = pac[7:7+len_dat]

			#get the key length
			key_len = ord(pac[7+len_dat])*256 + ord(pac[7+len_dat+1])
			
			#check the format of the packet
			if len(self.packet)!= 4+1+2+2+len_dat+key_len:
				self.isvalid = 0
				return
			self.key = pac[7+len_dat+2: 7+len_dat+2+key_len]

		else:
			#this will have simple format
			self.dat = pac[5:]
Beispiel #3
0
    def makePacket(self):
        pac = ''
        #ip address
        pac += Converter.get_encoded_ip(self.src_ip)
        # print pac,'*',len(pac)
        #request-type
        pac += chr(self.req_type)
        # print pac,'*',len(pac)
        #length of payload...
        pac += chr(len(self.dat) / 256)
        pac += chr(len(self.dat) % 256)
        # print pac,'*',len(pac)
        #append the payload
        pac += self.dat

        #append key-size
        pac += chr(len(self.key) / 256)
        pac += chr(len(self.key) % 256)
        # print pac,'*',len(pac)
        #append key
        pac += self.key
        # print pac,'*',len(pac)
        self.packet = pac
Beispiel #4
0
	def makePacket(self):
		pac = ''
		#ip address
		pac += Converter.get_encoded_ip(self.src_ip)
		# print pac,'*',len(pac)
		#request-type
		pac += chr(self.req_type)
		# print pac,'*',len(pac)
		#length of payload...
		pac += chr(len(self.dat)/256) 
		pac += chr(len(self.dat)%256)
		# print pac,'*',len(pac)
		#append the payload
		pac += self.dat
		
		#append key-size
		pac += chr(len(self.key)/256)
		pac += chr(len(self.key)%256)
		# print pac,'*',len(pac)
		#append key
		pac += self.key
		# print pac,'*',len(pac)
		self.packet = pac
Beispiel #5
0
 def setPacketByFields(self, typ, src, payload):
     self.packet = Converter.get_encoded_ip(src) +\
         chr(typ) + payload
Beispiel #6
0
	def setPacketByFields(self, typ, src, payload):
		self.packet = Converter.get_encoded_ip(src) +\
						chr(typ) + payload