示例#1
0
文件: ospd.py 项目: pkjmesra/ospd
    def start_scan(self, scan_id, target_str):
        """ Starts the scan with scan_id. """

        os.setsid()
        logger.info("{0}: Scan started.".format(scan_id))
        target_list = target_str_to_list(target_str)
        if target_list is None:
            raise OSPDError('Erroneous targets list', 'start_scan')
        for index, target in enumerate(target_list):
            progress = float(index) * 100 / len(target_list)
            self.set_scan_progress(scan_id, int(progress))
            logger.info("{0}: Host scan started.".format(target))
            try:
                ret = self.exec_scan(scan_id, target)
                if ret == 0:
                    self.add_scan_host_detail(scan_id, name='host_status',
                                              host=target, value='0')
                elif ret == 1:
                    self.add_scan_host_detail(scan_id, name='host_status',
                                              host=target, value='1')
                elif ret == 2:
                    self.add_scan_host_detail(scan_id, name='host_status',
                                              host=target, value='2')
                else:
                    logger.debug('{0}: No host status returned'.format(target))
            except Exception as e:
                self.add_scan_error(scan_id, name='', host=target,
                                    value='Host process failure (%s).' % e)
                logger.exception('While scanning {0}:'.format(target))
            else:
                logger.info("{0}: Host scan finished.".format(target))

        self.finish_scan(scan_id)
示例#2
0
 def update_progress(self, scan_id, target, msg):
     """ Calculate porcentage and update the scan status
     for the progress bar. """
     host_progress_dict = dict()
     prog = str.split(msg, '/')
     if float(prog[1]) == 0:
         return
     host_prog = (float(prog[0]) / float(prog[1])) * 100
     host_progress_dict[target] = host_prog
     total_host = len(target_str_to_list(target))
     self.set_scan_target_progress(
         scan_id, target,
         sum(host_progress_dict.values()) / total_host)
示例#3
0
文件: ospd.py 项目: pkjmesra/ospd
    def dry_run_scan(self, scan_id, target_str):
        """ Dry runs a scan. """

        os.setsid()
        target_list = target_str_to_list(target_str)
        for _, target in enumerate(target_list):
            host = resolve_hostname(target)
            if host is None:
                logger.info("Couldn't resolve {0}.".format(target))
                continue
            logger.info("{0}: Dry run mode.".format(host))
            self.add_scan_log(scan_id, name='', host=host,
                              value='Dry run result')
        self.finish_scan(scan_id)
示例#4
0
 def update_progress(self, scan_id, target, msg):
     """ Calculate percentage and update the scan status of a target
     for the progress bar.
     Arguments:
         scan_id (uuid): Scan ID to identify the current scan process.
         target (str): Target to be updated with the calculated
                       scan progress.
         msg (str): String with launched and total plugins.
     """
     host_progress_dict = dict()
     try:
         launched, total = msg.split('/')
     except ValueError:
         return
     if float(total) == 0:
         return
     host_prog = (float(launched) / float(total)) * 100
     host_progress_dict[target] = host_prog
     total_host = len(target_str_to_list(target))
     target_progress = sum(host_progress_dict.values()) / total_host
     self.set_scan_target_progress(scan_id, target, target_progress)
示例#5
0
 def test24Net(self):
     addresses = target_str_to_list('195.70.81.0/24')
     self.assertFalse(addresses is None)
     self.assertEqual(len(addresses), 254)
     for i in range(1, 255):
         self.assertTrue('195.70.81.%d' % i in addresses)
示例#6
0
 def testRange(self):
     addresses = target_str_to_list('195.70.81.1-10')
     self.assertFalse(addresses is None)
     self.assertEqual(len(addresses), 10)
     for i in range(1, 10):
         self.assertTrue('195.70.81.%d' % i in addresses)