Changeset 5899

Show
Ignore:
Timestamp:
04/09/11 10:10:51 (2 years ago)
Author:
ignotus
Message:

Removing trailing spaces.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • zion/trunk/umit/zion/core/zion.py

    r5835 r5899  
    5959        """ 
    6060        return self.__option 
    61      
     61 
    6262    def reset_options(self): 
    6363        """ 
     
    7979        """ 
    8080        self.notify('update_status', "Host scanning started\n") 
    81          
     81 
    8282        if self.__option.has(options.OPTION_PORTS): 
    8383            ports = self.__option.get(options.OPTION_PORTS) 
     
    9494        for target in self.__target: 
    9595            print target 
    96              
     96 
    9797        self.notify('scan_finished', self.__target[0]) 
    98              
     98 
    9999    def do_capture(self, dev=None): 
    100100        """ 
     
    134134        if mode == options.FORGE_MODE_SYN: 
    135135            self.do_scan() 
    136              
     136 
    137137            self.notify('update_status', 'Capturing packets\n') 
    138              
     138 
    139139            if fields!=None: 
    140140                s.fields = fields 
     
    150150            print 'Unimplemented forge mode %s.' % mode 
    151151 
    152              
     152 
    153153    def do_forge_mode_syn(self, s, target, target_port, addr, port): 
    154154        """ 
    155155        """ 
    156          
     156 
    157157        amount = self.__option.get(options.OPTION_CAPTURE_AMOUNT) 
    158158 
     
    184184        except KeyboardInterrupt: 
    185185            packet.stop() 
    186                          
     186 
    187187 
    188188    def run(self, outq=None): 
     
    190190        """ 
    191191        self.__outq = outq 
    192          
     192 
    193193        if self.__option.has(options.OPTION_HELP): 
    194194 
    195195            print options.HELP_TEXT 
    196              
     196 
    197197        elif self.__option.has(options.OPTION_DETECT): 
    198              
     198 
    199199            self.notify('update_status', 'OS Detection Started\n') 
    200              
     200 
    201201            print 
    202202            print 'OS Detection' 
    203203            print '------------' 
    204              
     204 
    205205            # configure parameters for OS detection 
    206206            if not self.__option.has(options.OPTION_CAPTURE_AMOUNT): 
    207207                self.__option.add('--capture-amount',AMOUNT_OS_DETECTION) 
    208208            if not self.__option.has(options.OPTION_SEND_INTERVAL): 
    209                 self.__option.add('-i',SEND_INTERVAL)                 
     209                self.__option.add('-i',SEND_INTERVAL) 
    210210            self.__option.add('-f','syn') 
    211              
     211 
    212212            print 'Capturing packets' 
    213213            self.do_forge(['tcp.seq']) 
    214              
     214 
    215215            self.notify('update_status', 'Creating time series\n') 
    216216 
    217217            print 'Calculating PRNG' 
    218218            Rt = self.calculate_PRNG() 
    219              
     219 
    220220            self.notify('update_status', 'Building attractors\n') 
    221              
     221 
    222222            print 'Creating attractors' 
    223223            self.__classification(Rt) 
    224              
     224 
    225225            self.notify('update_status', 'Performing OS fingerprint matching\n') 
    226              
     226 
    227227            print 'Matching' 
    228228            result = self.__matching() 
    229          
     229 
    230230            self.notify('matching_finished', result) 
    231              
    232              
     231 
     232 
    233233        elif self.__option.has(options.OPTION_SYNPROXY): 
    234              
     234 
    235235            self.notify('update_status', 'Syn Proxy Detection Started\n\n') 
    236              
     236 
    237237            synproxy = self.synproxy_detection() 
    238238            if synproxy==True: 
     
    240240            else: 
    241241                print 'Target isnt synproxy' 
    242                  
     242 
    243243            self.notify('synproxy_finished', synproxy) 
    244              
     244 
    245245        elif self.__option.has(options.OPTION_HONEYD): 
    246              
     246 
    247247            self.notify('update_status', 'Honeyd Detection Started\n') 
    248              
     248 
    249249            honeyd = self.honeyd_detection() 
    250250            if honeyd==False: 
     
    252252            else: 
    253253                print 'Target is honeyd' 
    254                  
     254 
    255255            self.notify('honeyd_finished', honeyd) 
    256256 
    257257        elif self.__option.has(options.OPTION_FORGE): 
    258              
     258 
    259259            self.notify('update_status', 'Forge started\n') 
    260260 
     
    268268 
    269269            self.notify('update_status', 'Scanning host\n') 
    270              
     270 
    271271            print 
    272272            print 'TCP SYN port scan results' 
     
    274274 
    275275            self.do_scan() 
    276                  
     276 
    277277        elif self.__option.has(options.OPTION_CAPTURE): 
    278278 
     
    281281            print '-----------------' 
    282282 
    283             self.do_capture()                 
     283            self.do_capture() 
    284284 
    285285        else: 
    286286            print options.HELP_TEXT 
    287              
    288              
     287 
     288 
    289289    def honeyd_detection(self): 
    290         """ Detect if target are an honeyd. """         
     290        """ Detect if target are an honeyd. """ 
    291291        # configure parameters for honeyd detection 
    292292        if not self.__option.has(options.OPTION_CAPTURE_AMOUNT): 
    293293            self.__option.add('--capture-amount',AMOUNT_HONEYD_DETECTION) 
    294294        self.__option.add('-f','syn') 
    295                  
     295 
    296296        self.do_forge(['tcp.seq']) 
    297297        Rt = self.calculate_PRNG() 
    298          
     298 
    299299        if len(Rt) > 0: 
    300300 
     
    304304                if not len(values)==1: 
    305305                    return False 
    306                      
     306 
    307307            # verify constant increments 
    308308            cycle = Rt[:5] 
     
    314314                if increments.count(k)==4: 
    315315                    return True 
    316              
     316 
    317317            return False 
    318318        else: 
    319319            return False 
    320              
    321  
    322          
     320 
     321 
     322 
    323323    def synproxy_detection(self): 
    324324        """ Detect if target is an syn proxy. """ 
    325                  
     325 
    326326        # configure parameters for honeyd detection 
    327327        if not self.__option.has(options.OPTION_CAPTURE_AMOUNT): 
    328328            self.__option.add('--capture-amount',1) 
    329329        self.__option.add('-f','syn') 
    330          
     330 
    331331        self.notify('update_status','Searching for open ports\n') 
    332          
     332 
    333333        target = self.__target[0] 
    334          
     334 
    335335        # search for open ports in target 
    336336        self.do_scan() 
    337337        ports = target.get_open_ports() 
    338          
     338 
    339339        self.notify('update_status','Generate random ports\n') 
    340          
     340 
    341341        origin_port1 = random.randint(1024, 65535) 
    342342        while True: 
     
    347347        s = sniff.Sniff() 
    348348        addr = self.__option.get(options.OPTION_FORGE_ADDR) 
    349          
     349 
    350350        self.notify('update_status','Sending packets\n') 
    351351        s.fields = ['tcp.seq'] 
     
    358358        self.do_forge_mode_syn(s, target, ports[0], addr, origin_port1) 
    359359        isn3 = self.__capture_result[0][1] 
    360          
     360 
    361361        if isn1!=isn2 and isn1==isn3: 
    362362            return True 
    363363        else: 
    364364            return False 
    365          
    366              
     365 
     366 
    367367    def calculate_PRNG(self): 
    368368        """ Calculate Pseudo Random Number Generator from ISN captured. """ 
    369          
     369 
    370370        if len(self.__capture_result) == 0: 
    371371            print 'Error: no results available' 
     
    375375                if self.__capture_result[i][1][0] <> 'None': 
    376376                    isn.append(int(self.__capture_result[i][1][0])) 
    377          
     377 
    378378        ordered = True 
    379          
     379 
    380380        # verify if isn numbers are ordered ascendly 
    381381        for i in range(1,len(isn)): 
     
    383383                ordered = False 
    384384                break 
    385              
     385 
    386386        Rt = [] 
    387          
     387 
    388388        if ordered==False: 
    389389            Rt = isn 
     
    391391            for i in range(len(isn)-1): 
    392392                Rt.append(isn[i+1] - isn[i]) 
    393                      
     393 
    394394        return Rt 
    395      
    396          
     395 
     396 
    397397    def __classification(self,Rt): 
    398398        """ Get attractors and put them in SOM. """ 
    399                  
     399 
    400400        self.__attractors = [] 
    401                  
     401 
    402402        # normalize results 
    403403        max_val = max(Rt) 
    404404        min_val = min(Rt) 
    405405        ratio = 2/(max_val-min_val) 
    406          
     406 
    407407        self.__som = som.new(2,(30,30)) 
    408408        self.__matrix = matrix.new(len(Rt)-1,2) 
    409                  
     409 
    410410        for i in range(len(Rt)-1): 
    411411            x = Rt[i+1] 
     
    414414            matrix.set(self.__matrix, i, 0, x) 
    415415            matrix.set(self.__matrix, i, 1, y) 
    416              
    417         self.notify('attractors_built', self.__attractors)     
     416 
     417        self.notify('attractors_built', self.__attractors) 
    418418 
    419419        som.caracterization(self.__som, self.__matrix, EPOCHS) 
    420      
     420 
    421421    def __matching(self): 
    422422        """ 
     
    425425        dmin = sys.maxint 
    426426        id_min = None 
    427          
     427 
    428428        conn = sqlite3.connect('umit/zion/db/db.sqlite') 
    429429        c = conn.cursor() 
    430430        c.execute('SELECT software.pk, s_attractor.fp FROM software INNER JOIN fingerprint ON software.pk = fingerprint.fk_software INNER JOIN s_attractor ON s_attractor.pk = fingerprint.fk_sig1') 
    431          
     431 
    432432        for fingerprint in c: 
    433433            attractor = cPickle.loads(str(fingerprint[1])) 
     
    437437                dmin = d 
    438438                id_min = fingerprint[0] 
    439                          
     439 
    440440        details = None 
    441441        if id_min!=None: 
     
    445445        else: 
    446446            print 'no fingerprints available in database' 
    447          
     447 
    448448        return details 
    449          
     449 
    450450    def get_attractors(self): 
    451451        """ Return the list of attractors. """ 
    452452        return self.__attractors 
    453      
     453 
    454454    def notify(self, signal, param=None): 
    455455        """