Пример #1
0
    def inject(self, packet):
        '''
	   	The inject method of the sender, which is bound the the netfilter queue NETFILTERQUEUE_NUMBER.
	   	This method injects the i-th chunks of the secret message (i.e., self.chunks[self.sent_received_chunks])
	   	into the targeted field, accordingly to the sending mode used (i.e., interleaved or burst).
	   	:param Packet packet: The NetfilterQueue Packet object packet.
	   	'''
        # tocheck: maybe the sleep necessary for HL: it can't handle the big amount of packets in the queue of this cc
        # if self.sleep:
        # 	time.sleep(1)
        # 	self.sleep = False
        if self.number_of_repetitions_done < self.number_of_repetitions:
            tmp1 = time.perf_counter()
            pkt = IPv6(packet.get_payload())
            if self.sent_received_chunks < len(self.chunks):
                if self.sent_received_chunks == 0:
                    self.starttime_stegocommunication = time.perf_counter()

                if self.stegotime:
                    pkt.fl = helper.get_md5_signature_at_indices(
                        self.sent_received_chunks,
                        helper.USED_INDICES_OF_HASH_FLOW_LABEL)
                    if self.chunks[self.sent_received_chunks] == '1':
                        pkt.hlim += self.hoplimit_delta
                        self.exfiltrated_data.append('1')
                    else:
                        pkt.hlim -= self.hoplimit_delta
                        self.exfiltrated_data.append('0')

                    self.sent_received_chunks += 1

                    if self.consecutive_stego > 0:
                        self.stegotime = self.sent_received_chunks % self.consecutive_stego != 0

                else:
                    self.clean_counter += 1
                    self.stegotime = self.clean_counter % self.consecutive_nonstego == 0
            else:
                pkt.fl = Hop_Limit_CC.END_SIGNATURE
                self.endtime_stegocommunication = time.perf_counter()
                self.stegotime = True
                self.number_of_repetitions_done += 1
                self.statistical_evaluation_sent_packets()
                self.write_csv()
                self.injection_exfiltration_time_sum = 0
                self.sent_received_chunks = 0
                self.exfiltrated_data = []
                #self.sleep = True

            packet.set_payload(bytes(pkt))
            if self.sent_received_chunks != 0:
                self.injection_exfiltration_time_sum += time.perf_counter(
                ) - tmp1
        packet.accept()
Пример #2
0
    def inject(self, packet):
        '''
	   	The inject method of the sender, which is bound the the netfilter queue NETFILTERQUEUE_NUMBER.
	   	This method injects the i-th chunks of the secret message (i.e., self.chunks[self.sent_received_chunks])
	   	into the targeted field, accordingly to the sending mode used (i.e., interleaved or burst).
	   	:param Packet packet: The NetfilterQueue Packet object packet.
	   	'''
        if self.number_of_repetitions_done < self.number_of_repetitions:
            tmp1 = time.perf_counter()
            pkt = IPv6(packet.get_payload())
            if self.sent_received_chunks < len(self.int_chunks):
                if self.sent_received_chunks == 0:
                    self.starttime_stegocommunication = time.perf_counter()

                if self.stegotime:
                    pkt.tc = helper.get_md5_signature_at_indices(
                        self.sent_received_chunks,
                        helper.USED_INDICES_OF_HASH_TRAFFIC_CLASS)
                    #to check: with TC == 255, problems will occurs in the receinving side
                    if pkt.tc == 255:
                        pkt.tc = 254
                    pkt.fl = int(self.chunks[self.sent_received_chunks], 2)
                    self.exfiltrated_data.append((pkt.fl, pkt.tc))

                    self.sent_received_chunks += 1

                    if self.consecutive_stego > 0:
                        self.stegotime = self.sent_received_chunks % self.consecutive_stego != 0
                else:
                    self.clean_counter += 1
                    self.stegotime = self.clean_counter % self.consecutive_nonstego == 0
            else:
                pkt.fl = Flow_Label_CC.END_SIGNATURE
                self.endtime_stegocommunication = time.perf_counter()
                self.stegotime = True
                self.number_of_repetitions_done += 1
                self.statistical_evaluation_sent_packets()
                self.write_csv()
                self.injection_exfiltration_time_sum = 0
                self.sent_received_chunks = 0
                self.exfiltrated_data = []

            packet.set_payload(bytes(pkt))
            if self.sent_received_chunks != 0:
                self.injection_exfiltration_time_sum += time.perf_counter(
                ) - tmp1
        packet.accept()
Пример #3
0
    def exfiltrate(self, packet):
        '''
	   	The exfiltration method of the receiver, which is bound the the netfilter queue NETFILTERQUEUE_NUMBER.
	   	This method extracts the value contained into the targeted field, accordingly to the sending mode used 
	   	(i.e., interleaved or burst).
	   	:param Packet packet: The NetfilterQueue Packet object.
	   	'''
        if self.number_of_repetitions_done < self.number_of_repetitions:
            tmp1 = time.perf_counter()
            pkt = IPv6(packet.get_payload())
            if self.stegotime:
                tmp = helper.get_md5_signature_at_indices(
                    self.sent_received_chunks,
                    helper.USED_INDICES_OF_HASH_TRAFFIC_CLASS)
                if tmp == 255:
                    tmp = 254
                if pkt.tc == tmp:
                    if self.sent_received_chunks == 0:
                        self.starttime_stegocommunication = time.perf_counter()
                    self.exfiltrated_data.append((pkt.fl, pkt.tc))

                    self.sent_received_chunks += 1
                    if self.consecutive_stego > 0:
                        self.stegotime = self.sent_received_chunks % self.consecutive_stego != 0
            else:
                self.clean_counter += 1
                self.stegotime = self.clean_counter % self.consecutive_nonstego == 0

            if pkt.fl == Flow_Label_CC.END_SIGNATURE:
                self.endtime_stegocommunication = time.perf_counter()
                self.stegotime = True
                self.number_of_repetitions_done += 1
                self.statistical_evaluation_received_packets()
                self.write_csv()
                self.injection_exfiltration_time_sum = 0
                self.sent_received_chunks = 0
                self.exfiltrated_data = []

            if self.sent_received_chunks != 0:
                self.injection_exfiltration_time_sum += time.perf_counter(
                ) - tmp1
        packet.accept()
Пример #4
0
    def inject(self, packet):
        '''
	   	The inject method of the sender, which is bound the the netfilter queue NETFILTERQUEUE_NUMBER.
	   	This method injects the i-th chunks of the secret message (i.e., self.chunks[self.sent_received_chunks])
	   	into the targeted field, accordingly to the sending mode used (i.e., interleaved or burst).
	   	:param Packet packet: The NetfilterQueue Packet object packet.
	   	'''
        if self.number_of_repetitions_done < self.number_of_repetitions:
            tmp1 = time.perf_counter()
            pkt = IPv6(packet.get_payload())
            if pkt.nh == 6:
                if self.sent_received_chunks < len(self.int_chunks):

                    # If no monotonically increasing sequence number in the flow => retransmission
                    if pkt[TCP].seq < self.next_expected_seq:

                        # Get the signature and the value of the exfiltrated data
                        buf = [
                            x for x in self.exfiltrated_data[-5:]
                            if pkt[TCP].seq == x[2]
                        ]

                        # If a value was inserted in the stegotime
                        if buf != []:
                            pkt.tc = buf[0][1]
                            pkt.fl = buf[0][0]
                            self.count_stego_retransmissions += 1

                    # If it is monotonically increasing
                    else:

                        # If the first packet, set the seq. number
                        if self.sent_received_chunks == 0:
                            self.starttime_stegocommunication = time.perf_counter(
                            )
                            self.next_expected_seq = pkt[TCP].seq

                        # If it is the stegotime, set the value an dthe signature
                        if self.stegotime:
                            pkt.tc = helper.get_md5_signature_at_indices(
                                self.sent_received_chunks,
                                helper.USED_INDICES_OF_HASH_TRAFFIC_CLASS)
                            #tocheck: with TC == 255, problems will occurs in the receinving side
                            if pkt.tc == 255:
                                pkt.tc = 254
                            pkt.fl = int(
                                self.chunks[self.sent_received_chunks], 2)

                            self.exfiltrated_data.append(
                                (pkt.fl, pkt.tc, pkt[TCP].seq))

                            self.sent_received_chunks += 1

                            if self.consecutive_stego > 0:
                                self.stegotime = self.sent_received_chunks % self.consecutive_stego != 0
                        else:
                            self.clean_counter += 1
                            self.stegotime = self.clean_counter % self.consecutive_nonstego == 0

                        # Calculate the next expected value
                        self.next_expected_seq += len(pkt[TCP].payload)

                else:
                    pkt.fl = Flow_Label_CC.END_SIGNATURE
                    self.endtime_stegocommunication = time.perf_counter()
                    self.stegotime = True
                    self.number_of_repetitions_done += 1
                    self.statistical_evaluation_sent_packets()
                    self.write_csv()
                    self.injection_exfiltration_time_sum = 0
                    self.sent_received_chunks = 0
                    self.exfiltrated_data = []
                    self.count_stego_retransmissions = 0

            packet.set_payload(bytes(pkt))
            if self.sent_received_chunks != 0:
                self.injection_exfiltration_time_sum += time.perf_counter(
                ) - tmp1
        packet.accept()
Пример #5
0
    def inject(self, packet):
        '''
	   	The inject method of the sender, which is bound the the netfilter queue NETFILTERQUEUE_NUMBER.
	   	This method injects the i-th chunks of the secret message (i.e., self.chunks[self.sent_received_chunks])
	   	into the targeted field, accordingly to the sending mode used (i.e., interleaved or burst).
	   	:param Packet packet: The NetfilterQueue Packet object packet.
	   	'''
        #tocheck: sleep necessary for HL: it can handle the big amount of packets in the queue of this cc

        # if self.sleep:
        # 	time.sleep(1)
        # 	self.sleep = False

        if self.number_of_repetitions_done < self.number_of_repetitions:
            tmp1 = time.perf_counter()
            pkt = IPv6(packet.get_payload())
            if pkt.nh == 6:
                if self.sent_received_chunks < len(self.chunks):

                    # If no monotonically increasing sequence number in the flow => retransmission
                    if pkt[TCP].seq < self.next_expected_seq:

                        # Get the signature and the value of the exfiltrated data
                        buf = [
                            x for x in self.exfiltrated_data[-5:]
                            if pkt[TCP].seq == x[2]
                        ]

                        # If a value was inserted in the stegotime
                        if buf != []:
                            pkt.hl = buf[0][0]
                            pkt.fl = buf[0][1]
                            self.count_stego_retransmissions += 1

                    # If it is monotonically increasing
                    else:

                        # If the first packet, set the seq. number
                        if self.sent_received_chunks == 0:
                            self.starttime_stegocommunication = time.perf_counter(
                            )
                            self.next_expected_seq = pkt[TCP].seq

                        # If it is the stegotime, set the value an dthe signature
                        if self.stegotime:
                            pkt.fl = helper.get_md5_signature_at_indices(
                                self.sent_received_chunks,
                                helper.USED_INDICES_OF_HASH_FLOW_LABEL)

                            if self.chunks[self.sent_received_chunks] == '1':
                                pkt.hlim += self.hoplimit_delta
                                self.exfiltrated_data.append(
                                    ('1', pkt.fl, pkt[TCP].seq))
                            else:
                                pkt.hlim -= self.hoplimit_delta
                                self.exfiltrated_data.append(
                                    ('0', pkt.fl, pkt[TCP].seq))

                            self.sent_received_chunks += 1

                            if self.consecutive_stego > 0:
                                self.stegotime = self.sent_received_chunks % self.consecutive_stego != 0
                        else:
                            self.clean_counter += 1
                            self.stegotime = self.clean_counter % self.consecutive_nonstego == 0

                        # Calculate the next expected value
                        self.next_expected_seq += len(pkt[TCP].payload)
                else:
                    pkt.fl = Hop_Limit_CC.END_SIGNATURE
                    self.endtime_stegocommunication = time.perf_counter()
                    self.stegotime = True
                    self.number_of_repetitions_done += 1
                    self.statistical_evaluation_sent_packets()
                    self.write_csv()
                    self.injection_exfiltration_time_sum = 0
                    self.sent_received_chunks = 0
                    self.exfiltrated_data = []
                    #self.sleep = True
                    self.count_stego_retransmissions = 0

            packet.set_payload(bytes(pkt))
            if self.sent_received_chunks != 0:
                self.injection_exfiltration_time_sum += time.perf_counter(
                ) - tmp1
        packet.accept()