Exemplo n.º 1
0
 def __init__(self, interfaces, channel, drone):
     BaseDronePlugin.__init__(self, interfaces, channel, drone,
                              'CapturePlugin.{0}'.format(channel))
     self.logutil.log('Initializing')
     # Select interface
     try:
         self.kb = self.interfaces[0]
         self.kb.set_channel(self.channel)
         self.kb.active = True
     except Exception as e:
         print("failed to use interface")
         self.status = False
     # Pipe from the tasker to the filter module, used to send pickled tasking dictionaries (simple DictManager)
     recv_pconn, recv_cconn = Pipe()
     task_pconn, self.task_cconn = Pipe()
     self.task_queue = JoinableQueue()
     # Start the filter up
     self.p_filt = FilterProcess(recv_pconn, self.task_queue,
                                 self.done_event, self.task_update_event,
                                 self.drone, self.name)
     self.p_filt.start()
     self.logutil.log('Launched FilterProcess ({0})'.format(
         self.p_filt.pid))
     self.childprocesses.append(self.p_filt)
     # Start the receiver up
     self.p_recv = SnifferProcess(recv_cconn, self.kb, self.done_event,
                                  self.drone, self.name)
     self.p_recv.start()
     self.logutil.log('Launched SnifferProcess: ({0})'.format(
         self.p_recv.pid))
     self.childprocesses.append(self.p_recv)
Exemplo n.º 2
0
class CapturePlugin(BaseDronePlugin):
    def __init__(self, interfaces, channel, drone):
        BaseDronePlugin.__init__(self, interfaces, channel, drone, "CapturePlugin.{0}".format(channel))
        self.logutil.log("Initializing")
        # Select interface
        try:
            self.kb = self.interfaces[0]
            self.kb.set_channel(self.channel)
            self.kb.active = True
        except Exception as e:
            print("failed to use interface")
            self.status = False
        # Pipe from the tasker to the filter module, used to send pickled tasking dictionaries (simple DictManager)
        recv_pconn, recv_cconn = Pipe()
        task_pconn, self.task_cconn = Pipe()
        self.task_queue = JoinableQueue()
        # Start the filter up
        self.p_filt = FilterProcess(
            recv_pconn, self.task_queue, self.done_event, self.task_update_event, self.drone, self.name
        )
        self.p_filt.start()
        self.logutil.log("Launched FilterProcess ({0})".format(self.p_filt.pid))
        self.childprocesses.append(self.p_filt)
        # Start the receiver up
        self.p_recv = SnifferProcess(recv_cconn, self.kb, self.done_event, self.drone, self.name)
        self.p_recv.start()
        self.logutil.log("Launched SnifferProcess: ({0})".format(self.p_recv.pid))
        self.childprocesses.append(self.p_recv)

    def task(self, uuid, data):
        self.logutil.log("Adding Task: {0}".format(uuid))
        if uuid in self.tasks:
            return False
        self.tasks[uuid] = data
        self.__update_filter_tasking()
        return True

    def detask(self, uuid):
        res = None
        if uuid in self.tasks:
            res = self.tasks.get(uuid)
            del self.tasks[uuid]
        else:
            return False
        if len(self.tasks) == 0:
            # Time to shut the whole party down, as we don't have any more tasks
            self.logutil.log("No remaining tasks, shutting down plugin")
            self.shutdown()
            # TODO return something to indicate a total shutdown also
        else:
            # We made a change to tasking, let's implement it
            self.__update_filter_tasking()
        # return res
        return True

    def __update_filter_tasking(self):
        self.logutil.log("Sending Task Updates to FilterProcess")
        self.task_queue.put_nowait(cPickle.dumps(self.tasks))
Exemplo n.º 3
0
    def setUp(self):
        from multiprocessing import Pipe, Event
        from cap_filter_process import FilterProcess

        recv_pconn, self.recv_cconn = Pipe()
        self.done_event = Event()

        self.p_filt = FilterProcess(recv_pconn, self.done_event)
        self.p_filt.start()
Exemplo n.º 4
0
 def __init__(self, interfaces, channel, drone):
     BaseDronePlugin.__init__(self, interfaces, channel, drone, "CapturePlugin.{0}".format(channel))
     self.logutil.log("Initializing")
     # Select interface
     try:
         self.kb = self.interfaces[0]
         self.kb.set_channel(self.channel)
         self.kb.active = True
     except Exception as e:
         print("failed to use interface")
         self.status = False
     # Pipe from the tasker to the filter module, used to send pickled tasking dictionaries (simple DictManager)
     recv_pconn, recv_cconn = Pipe()
     task_pconn, self.task_cconn = Pipe()
     self.task_queue = JoinableQueue()
     # Start the filter up
     self.p_filt = FilterProcess(
         recv_pconn, self.task_queue, self.done_event, self.task_update_event, self.drone, self.name
     )
     self.p_filt.start()
     self.logutil.log("Launched FilterProcess ({0})".format(self.p_filt.pid))
     self.childprocesses.append(self.p_filt)
     # Start the receiver up
     self.p_recv = SnifferProcess(recv_cconn, self.kb, self.done_event, self.drone, self.name)
     self.p_recv.start()
     self.logutil.log("Launched SnifferProcess: ({0})".format(self.p_recv.pid))
     self.childprocesses.append(self.p_recv)
Exemplo n.º 5
0
    def setUp(self):
        from multiprocessing import Pipe, Event
        from cap_filter_process import FilterProcess

        recv_pconn, self.recv_cconn = Pipe()
        self.done_event = Event()

        self.p_filt = FilterProcess(recv_pconn, self.done_event)
        self.p_filt.start()
Exemplo n.º 6
0
class TestFilterProcess(unittest.TestCase):
    def setUp(self):
        from multiprocessing import Pipe, Event
        from cap_filter_process import FilterProcess

        recv_pconn, self.recv_cconn = Pipe()
        self.done_event = Event()

        self.p_filt = FilterProcess(recv_pconn, self.done_event)
        self.p_filt.start()

    def cleanUp(self):
        self.done_event.set()
        self.p_filt.join()

    def test_filter_add_remove(self):
        subkeyAllPktFilt = self.p_filt.subscribe(AllPacketFilter(), sample_callback)
        self.assertEqual(self.p_filt.subscription_count(), 1)
        self.p_filt.unsubscribe(subkeyAllPktFilt)
        self.assertEqual(self.p_filt.subscription_count(), 0)

    def test_filter_hit_count(self):
        subkeyAllPktFilt = self.p_filt.subscribe(AllPacketFilter(), sample_callback)
        for pktBytes in frames_beacon_requests:
            self.recv_cconn.send({'bytes': pktBytes}) #minimal 'packet' example
        # We're filtering on AllPacketFilter, so we should get a hit count equal
        # to the number of packets we fed in:
        #TODO need to be able to verify result somehow
        #self.assertEqual(self.p_filt.hit_count(subkeyAllPktFilt), len(frames_beacon_requests))
        self.p_filt.unsubscribe(subkeyAllPktFilt)

    def test_filter_fcfcmd(self):
        fcfcmdfilt = BasicPacketFilter()
        fcfcmdfilt.add_fcf_check(0x0300, 0x0300)
        subkey = self.p_filt.subscribe(fcfcmdfilt, sample_callback)
        for pktBytes in frames_beacon_requests:
            self.recv_cconn.send({'bytes': pktBytes}) #minimal 'packet' example
        #TODO need to be able to verify result somehow
        #self.assertEqual(self.p_filt.hit_count(subkey), len(frames_beacon_requests))
        self.p_filt.unsubscribe(subkey)
Exemplo n.º 7
0
class TestFilterProcess(unittest.TestCase):
    def setUp(self):
        from multiprocessing import Pipe, Event
        from cap_filter_process import FilterProcess

        recv_pconn, self.recv_cconn = Pipe()
        self.done_event = Event()

        self.p_filt = FilterProcess(recv_pconn, self.done_event)
        self.p_filt.start()

    def cleanUp(self):
        self.done_event.set()
        self.p_filt.join()

    def test_filter_add_remove(self):
        subkeyAllPktFilt = self.p_filt.subscribe(AllPacketFilter(),
                                                 sample_callback)
        self.assertEqual(self.p_filt.subscription_count(), 1)
        self.p_filt.unsubscribe(subkeyAllPktFilt)
        self.assertEqual(self.p_filt.subscription_count(), 0)

    def test_filter_hit_count(self):
        subkeyAllPktFilt = self.p_filt.subscribe(AllPacketFilter(),
                                                 sample_callback)
        for pktBytes in frames_beacon_requests:
            self.recv_cconn.send({'bytes':
                                  pktBytes})  #minimal 'packet' example
        # We're filtering on AllPacketFilter, so we should get a hit count equal
        # to the number of packets we fed in:
        #TODO need to be able to verify result somehow
        #self.assertEqual(self.p_filt.hit_count(subkeyAllPktFilt), len(frames_beacon_requests))
        self.p_filt.unsubscribe(subkeyAllPktFilt)

    def test_filter_fcfcmd(self):
        fcfcmdfilt = BasicPacketFilter()
        fcfcmdfilt.add_fcf_check(0x0300, 0x0300)
        subkey = self.p_filt.subscribe(fcfcmdfilt, sample_callback)
        for pktBytes in frames_beacon_requests:
            self.recv_cconn.send({'bytes':
                                  pktBytes})  #minimal 'packet' example
        #TODO need to be able to verify result somehow
        #self.assertEqual(self.p_filt.hit_count(subkey), len(frames_beacon_requests))
        self.p_filt.unsubscribe(subkey)
Exemplo n.º 8
0
class CapturePlugin(BaseDronePlugin):
    def __init__(self, interfaces, channel, drone):
        BaseDronePlugin.__init__(self, interfaces, channel, drone,
                                 'CapturePlugin.{0}'.format(channel))
        self.logutil.log('Initializing')
        # Select interface
        try:
            self.kb = self.interfaces[0]
            self.kb.set_channel(self.channel)
            self.kb.active = True
        except Exception as e:
            print("failed to use interface")
            self.status = False
        # Pipe from the tasker to the filter module, used to send pickled tasking dictionaries (simple DictManager)
        recv_pconn, recv_cconn = Pipe()
        task_pconn, self.task_cconn = Pipe()
        self.task_queue = JoinableQueue()
        # Start the filter up
        self.p_filt = FilterProcess(recv_pconn, self.task_queue,
                                    self.done_event, self.task_update_event,
                                    self.drone, self.name)
        self.p_filt.start()
        self.logutil.log('Launched FilterProcess ({0})'.format(
            self.p_filt.pid))
        self.childprocesses.append(self.p_filt)
        # Start the receiver up
        self.p_recv = SnifferProcess(recv_cconn, self.kb, self.done_event,
                                     self.drone, self.name)
        self.p_recv.start()
        self.logutil.log('Launched SnifferProcess: ({0})'.format(
            self.p_recv.pid))
        self.childprocesses.append(self.p_recv)

    def task(self, uuid, data):
        self.logutil.log('Adding Task: {0}'.format(uuid))
        if uuid in self.tasks:
            return False
        self.tasks[uuid] = data
        self.__update_filter_tasking()
        return True

    def detask(self, uuid):
        res = None
        if uuid in self.tasks:
            res = self.tasks.get(uuid)
            del self.tasks[uuid]
        else:
            return False
        if len(self.tasks) == 0:
            # Time to shut the whole party down, as we don't have any more tasks
            self.logutil.log('No remaining tasks, shutting down plugin')
            self.shutdown()
            #TODO return something to indicate a total shutdown also
        else:
            # We made a change to tasking, let's implement it
            self.__update_filter_tasking()
        #return res
        return True

    def __update_filter_tasking(self):
        self.logutil.log('Sending Task Updates to FilterProcess')
        self.task_queue.put_nowait(cPickle.dumps(self.tasks))