示例#1
0
    def run(self):
        if not self.options['modinfo'] and not self.options['modtree']: #No point in doing surgery if it's modinfo or modtree
            # Figure out where we're reading packets from
            if not self.options['interface']:
                if not self.options['filename']:
                    if not self.options['filelist']:
                        self.send_finished_msg({'status':'error','errors': 'No input Specified'}, True)
                        return
                    else:
                        self.surgeon = Surgeon(self.options['filelist'])
                        self.options['filename'] = self.surgeon.create_fifo()
                        self.surgeon.operate()
                else:
                    if not os.path.exists(self.options['filename']):
                        self.send_finished_msg({'status':'error','errors':"Unable to find file '%s'" % self.options['filename']}, True)
                        return

                    if self.options['aslist']:
                        #input file is a listing of files to process
                        self.surgeon = Surgeon([self.options['filename']], self.options['longrun'])
                        self.options['filename'] = self.surgeon.create_fifo()
                        #TODO operate right away or later?
                        self.surgeon.operate(True)

        #Send options to Process 2 and tell it to setup
        self.kill_lock.acquire()
        try:
            self.tonids.put(['init', self.options])
        except AttributeError:
            #usually means tonids is None
            #possibly being killed?
            pass
        except Exception, e:
            raise ChopLibException(e)
示例#2
0
    def handle_ctrl(self, message):
        if message['data']['msg'] == 'addmod':
            self.cui.add_panel(message['data']['id'],message['data']['name'])

        if message['data']['msg'] == 'finished' and message['data']['status'] == 'error':
            self.stop()
            raise ChopLibException(message['data']['errors'])
示例#3
0
    def __init__(self):
        Thread.__init__(self, name='ChopLib')
        global DEFAULT_MODULE_DIRECTORY
        global DEFAULT_EXTLIB_DIRECTORY

        pyversion = sys.version_info
        pyversion = float(str(pyversion[0]) + "." + str(pyversion[1]))

        if pyversion < 2.6:
            raise ChopLibException("Minimum Python Version 2.6 Required")

        global Queue
        global Process
        from multiprocessing import Process, Queue
        from Queue import Empty
        Queue.Empty = Empty  #I'd prefer to keep this scoped to Queue

        self.options = {
            'mod_dir': [DEFAULT_MODULE_DIRECTORY],
            'ext_dir': [DEFAULT_EXTLIB_DIRECTORY],
            'base_dir': None,
            'filename': '',
            'filelist': None,
            'bpf': None,
            'aslist': False,
            'longrun': False,
            'interface': '',
            'modinfo': False,
            'modtree': False,
            'GMT': False,
            'savefiles': False,  #Should ChopShop handle the saving of files?
            'text': False,
            'pyobjout': False,
            'jsonout': False,
            'modules': ''
        }

        self.stopped = False

        #Setup Interaction Queues
        self.tocaller = Queue()  #output directly to caller
        self.fromnids = Queue()  #input queue from nids process
        self.tonids = Queue()  #output queue to nids process

        #Start up Process 2 (Nids Process)
        self.nidsp = Process(target=self.__nids_core_runner_,
                             args=(self.tonids, self.fromnids, self.tocaller))
        self.nidsp.daemon = True
        self.nidsp.start()

        self.chop = None
        self.surgeon = None

        self.kill_lock = Lock()
示例#4
0
            #usually means tonids is None
            #possibly being killed?
            pass
        except Exception, e:
            raise ChopLibException(e)
        finally:
            self.kill_lock.release()

        #Wait for a reponse
        self.kill_lock.acquire()
        try:
            resp = self.fromnids.get()
        except AttributeError:
            resp = "notok"  #probably means fromnids is None, which should only happen when being killed
        except Exception, e:
            raise ChopLibException(e)
        finally:
            self.kill_lock.release()

        if resp != 'ok':
            self.send_finished_msg({'status': 'error', 'errors': resp}, True)
            return

        if self.options['modinfo']:
            self.kill_lock.acquire()
            try:
                self.tonids.put(['mod_info'])
                resp = self.fromnids.get(
                )  #really just to make sure the functions finish
            except AttributeError:
                pass
示例#5
0
 def handle_ctrl(self, message):
     if message['data']['msg'] == 'finished' and message['data'][
             'status'] == 'error':
         print message['data']['errors']
         raise ChopLibException("Error Shown Above")