Changeset 5742

Show
Ignore:
Timestamp:
07/15/10 23:40:31 (3 years ago)
Author:
diogo
Message:

performance increase: thread replaced by process

Location:
zion/trunk/umit
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • zion/trunk/umit/scan/zion/gui/Plot.py

    r5705 r5742  
    140140        """ 
    141141        self.__input = input 
     142        self.__draw_content(self) 
  • zion/trunk/umit/scan/zion/gui/ZionScanNotebookPage.py

    r5741 r5742  
    2525import thread 
    2626import getopt 
     27from multiprocessing import Process, Queue 
    2728 
    2829from higwidgets.higframe import HIGFrameRNet 
     
    4142from umit.scan.zion.gui.AttractorWidget import AttractorWidget 
    4243from umit.zion.scan import probe 
    43 from umit.zion.core import address, options, zion, host, connector 
     44from umit.zion.core import address, options, zion, host 
    4445from umit.zion.core.host import PORT_STATE_OPEN 
    4546 
     
    333334 
    334335        self.pack_end(self.result) 
    335          
    336         # signals needed to update info 
    337         self.connector = connector.Connector() 
    338          
    339         self.connector.connect('scan_finished', self.update_port_info) 
    340         self.connector.connect('isn_samples_finished', self.update_info, 'Creating time series\n') 
    341         self.connector.connect('timeseries_created', self.update_info, 'Building attractors\n') 
    342         self.connector.connect('attractors_built', self.update_attractors) 
    343         self.connector.connect('fingerprint_finished', self.update_info, 'Performing OS fingerprint matching\n') 
    344         self.connector.connect('matching_finished', self.update_host_information) 
    345         self.connector.connect('honeyd_finished', self.honeyd_finished) 
    346         self.connector.connect('synproxy_finished', self.synproxy_finished) 
    347         self.connector.connect('update_status', self.update_info) 
    348          
    349336        self.result.get_hosts_view().set_current_page(0) 
     337         
     338        # construct communication queues 
     339        self.q1 = Queue() 
     340        self.q2 = Queue() 
     341        fd = self.q2._reader.fileno() 
     342        # observe received messages in queue 
     343        gobject.io_add_watch(fd, gobject.IO_IN, self.update) 
    350344 
    351345    def update_target(self, target): 
     
    361355        return False 
    362356     
    363     def update_info(self, obj, text): 
     357    def update_info(self, text): 
    364358        """ 
    365359        Update information page. 
     
    367361        self.result.get_hosts_view().get_scans_page().write(text) 
    368362         
    369     def update_port_info(self, obj, host): 
     363    def update_port_info(self, host): 
    370364        """ 
    371365        Update the port scan information of host. 
    372366        """ 
    373367        self.result.update_host_info(host) 
    374         self.update_info(None, 'Host scanning finished\n') 
    375          
    376     def update_attractors(self, obj, attractors): 
     368        self.update_info('Host scanning finished\n') 
     369         
     370    def update_attractors(self, attractors): 
    377371        """ 
    378372        Update the scans page with the graph of attractors 
    379373        """ 
    380374        self.result.get_hosts_view().get_scans_page().update_attractors(attractors) 
    381         self.update_info(None, 'Building fingerprint\n') 
    382          
    383     def update_host_information(self, obj, info): 
     375         
     376    def update_host_information(self, info): 
    384377        """ 
    385378        Update information about OS running on host. 
    386379        """ 
    387380        self.result.get_hosts_view().get_scans_page().update_os_info(info) 
    388         self.update_info(None, 'OS detection finished\n') 
    389          
    390     def honeyd_finished(self, obj, result): 
     381        self.update_info('OS detection finished\n') 
     382         
     383    def honeyd_finished(self, result): 
    391384        """ 
    392385        Write information about honeyd detection result 
    393386        """ 
    394387        if result: 
    395             self.update_info(None, 'Target is honeyd\n') 
     388            self.update_info('Target is honeyd\n') 
    396389        else: 
    397             self.update_info(None, 'Target isnt honeyd\n') 
    398              
    399     def synproxy_finished(self, obj, result): 
     390            self.update_info('Target isnt honeyd\n') 
     391             
     392    def synproxy_finished(self, result): 
    400393        """ 
    401394        Write information about synproxy detection result 
    402395        """ 
    403396        if result: 
    404             self.update_info(None, 'Target is synproxy\n') 
     397            self.update_info('Target is synproxy\n') 
    405398        else: 
    406             self.update_info(None, 'Target isnt synproxy\n')             
     399            self.update_info('Target isnt synproxy\n')    
     400             
     401    def update(self, fd, cond): 
     402        """ 
     403        Update interface with the information received by zion process 
     404        """ 
     405        signal, params = self.q2.get() 
     406         
     407        if signal=='update_status': 
     408            self.update_info(params) 
     409        elif signal=='scan_finished': 
     410            self.update_port_info(params) 
     411        elif signal=='attractors_built': 
     412            self.update_attractors(params) 
     413        elif signal=='matching_finished': 
     414            self.update_host_information(params) 
     415        elif signal=='honeyd_finished': 
     416            self.honeyd_finished(params) 
     417        elif signal=='synproxy_finished': 
     418            self.synproxy_finished(params) 
     419        return True             
    407420 
    408421class ZionProfileHoneyd(ZionProfile): 
     
    445458                 
    446459        for target in targets: 
    447             z = zion.Zion(opts,  [target], self.connector) 
    448             z.start() 
     460            z = zion.Zion(opts,  [target]) 
     461            p = Process(target=z.run, args=(self.q2,)) 
     462            p.start() 
    449463 
    450464class ZionProfileOS(ZionProfile): 
     
    459473        """ 
    460474        """ 
    461         z = zion.Zion(options.Options(), [], self.connector) 
     475        z = zion.Zion(options.Options(), []) 
    462476         
    463477        self.result.get_hosts_view().get_scans_page().clean() 
     
    487501        z.get_option_object().add("-d") 
    488502        z.get_option_object().add("--forge-addr",saddr) 
    489         z.start() 
     503         
     504        p = Process(target=z.run, args=(self.q2,)) 
     505        p.start() 
     506            
    490507 
    491508class ZionProfilePrompt(ZionProfile): 
     
    538555            self.result.get_hosts_view().get_scans_page().show_attractor_box() 
    539556             
    540         z = zion.Zion(zion_options, [], self.connector) 
     557        z = zion.Zion(zion_options, []) 
    541558             
    542559        for a in addrs: 
     
    552569         
    553570        # run zion 
    554         z.start() 
     571        p = Process(target=z.run, args=(self.q2,)) 
     572        p.start() 
    555573         
    556574 
     
    562580        """ 
    563581        ZionProfile.__init__(self, target) 
     582        # remove attractor box 
     583        self.result.get_hosts_view().get_scans_page().hide_attractor_box() 
    564584         
    565585    def start(self): 
     
    592612                 
    593613        for target in targets: 
    594             z = zion.Zion(opts,  [target], self.connector) 
    595             z.start() 
     614            z = zion.Zion(opts,  [target]) 
     615            p = Process(target=z.run, args=(self.q2,)) 
     616            p.start() 
    596617 
    597618PROFILE_CLASS = {'1': ZionProfileHoneyd, 
  • zion/trunk/umit/zion/core/zion.py

    r5741 r5742  
    2424import random 
    2525import time 
    26 import thread, threading 
    2726import sqlite3 
    2827import sys 
     
    4544ALPHA_LIMIT = 0.1 
    4645 
    47 class Zion(threading.Thread): 
     46class Zion(object): 
    4847    """ 
    4948    """ 
    50     def __init__(self, option, target=[], connector=None): 
     49    def __init__(self, option, target=[]): 
    5150        """ 
    5251        """ 
     
    5554        self.__capture_result = [] 
    5655        self.__attractors = [] 
    57         self.__connector = connector 
    58         threading.Thread.__init__ (self) 
    5956 
    6057    def get_option_object(self): 
     
    185182                         
    186183 
    187     def run(self): 
    188         """ 
    189         """ 
     184    def run(self, outq=None): 
     185        """ 
     186        """ 
     187        self.__outq = outq 
     188         
    190189        if self.__option.has(options.OPTION_HELP): 
    191190 
     
    210209            self.do_forge(['tcp.seq']) 
    211210             
    212             self.notify('isn_samples_finished') 
     211            self.notify('update_status', 'Creating time series\n') 
    213212 
    214213            print 'Calculating PRNG' 
    215214            Rt = self.calculate_PRNG() 
    216215             
    217             self.notify('timeseries_created') 
     216            self.notify('update_status', 'Building attractors\n') 
    218217             
    219218            print 'Creating attractors' 
    220219            self.__classification(Rt) 
    221220             
    222             self.notify('fingerprint_finished') 
     221            self.notify('update_status', 'Performing OS fingerprint matching\n') 
    223222             
    224223            print 'Matching' 
     
    451450    def notify(self, signal, param=None): 
    452451        """ 
    453         If a connector exists, emits the signal. 
    454         """ 
    455         if self.__connector!=None: 
    456             if param==None: 
    457                 self.__connector.emit(signal) 
    458             else: 
    459                 self.__connector.emit(signal, param) 
     452        If a out queue exists, output the information. 
     453        """ 
     454        if self.__outq!=None: 
     455            self.__outq.put((signal, param))