Пример #1
0
def initiate_network_scans_for_organization(self, org_uuid=None, requeue=True):
    """
    Kick off network scans for the given organization and queue up an additional network
    scanning task for the next interval.
    :param org_uuid: The UUID of the organization to scan.
    :param requeue: Whether or not to queue up another network scanning task for the
    configured interval.
    :return: None
    """
    logger.info(
        "Kicking off all network scans for Organization %s."
        % (org_uuid,)
    )
    zmap_scan_organization.si(org_uuid=org_uuid).apply_async()
    if requeue:
        scan_interval = get_network_scan_interval_for_organization(
            org_uuid=org_uuid,
            db_session=self.db_session,
        )
        next_time = DatetimeHelper.seconds_from_now(scan_interval)
        logger.info(
            "Queueing up an additional instance of %s in %s seconds (%s)."
            % (self.name, scan_interval, next_time)
        )
        initiate_network_scans_for_organization.si(org_uuid=org_uuid, requeue=requeue).apply_async(eta=next_time)
    else:
        logger.info("Requeueing not enabled, therefore not queueing up another network scanning task.")
Пример #2
0
def initiate_network_scans_for_order(self, order_uuid=None, requeue=False):
    """
    Initiate all of the network scans for the given order.
    :param order_uuid: The UUID of the order to initiate network scans for.
    :param requeue: Whether or not to requeue the network scans.
    :return: None
    """
    logger.info(
        "Now initiating all network scans for order %s. Requeue is %s." %
        (order_uuid, requeue))
    zmap_scan_order.si(order_uuid=order_uuid).apply_async()
    if requeue:
        org_uuid = get_org_uuid_from_order(order_uuid=order_uuid,
                                           db_session=self.db_session)
        scan_interval = get_network_scan_interval_for_organization(
            org_uuid=org_uuid,
            db_session=self.db_session,
        )
        next_time = DatetimeHelper.seconds_from_now(scan_interval)
        logger.info(
            "Queueing up an additional instance of %s in %s seconds (%s)." %
            (self.name, scan_interval, next_time))
        initiate_network_scans_for_order.si(
            org_uuid=org_uuid, requeue=requeue).apply_async(eta=next_time)
    else:
        logger.info(
            "Requeueing not enabled, therefore not queueing up another network scanning task."
        )
Пример #3
0
def network_service_inspection_pass(self,
                                    service_uuid=None,
                                    org_uuid=None,
                                    schedule_again=True):
    """
    This task performs a single network service scan pass, doing all of the necessary things to
    check on the state of a network service.
    :param service_uuid: The UUID of the OrganizationNetworkService to monitor.
    :param org_uuid: The UUID of the organization to monitor the network service on behalf of.
    :param schedule_again: Whether or not to schedule another monitoring task.
    :return: None
    """
    logger.info(
        "Now starting pass for network service %s. Organization is %s." %
        (service_uuid, org_uuid))

    # TODO check to see if the network service has been dead for the past N times and don't requeue if it has

    should_scan = check_network_service_scanning_status(
        db_session=self.db_session, service_uuid=service_uuid)
    if not should_scan:
        logger.info(
            "Network service %s either is already being scanned or has been scanned too recently to continue now."
            % (service_uuid, ))
        return
    ip_address, port, protocol = self.get_endpoint_information(service_uuid)
    network_service_scan = create_new_network_service_scan(
        network_service_uuid=service_uuid,
        db_session=self.db_session,
    )
    task_signatures = []
    task_signatures.append(
        perform_network_service_inspection.si(
            org_uuid=org_uuid,
            service_uuid=service_uuid,
            scan_uuid=network_service_scan.uuid,
        ))
    task_signatures.append(
        analyze_network_service_scan.si(
            network_service_scan_uuid=network_service_scan.uuid,
            org_uuid=org_uuid,
        ))
    task_signatures.append(
        update_network_service_scan_elasticsearch.si(
            network_service_scan_uuid=network_service_scan.uuid,
            org_uuid=org_uuid,
            network_service_uuid=service_uuid,
        ))
    task_signatures.append(
        update_network_service_scan_completed.si(
            network_service_scan_uuid=network_service_scan.uuid,
            org_uuid=org_uuid,
            network_service_uuid=service_uuid,
        ))
    task_signatures.append(
        inspect_service_application.si(
            org_uuid=org_uuid,
            network_service_scan_uuid=network_service_scan.uuid,
            network_service_uuid=service_uuid,
        ))
    canvas_sig = chain(task_signatures)
    canvas_sig.apply_async()
    if not config.task_network_service_monitoring_enabled:
        logger.info(
            "Not scheduling another monitoring task as network service monitoring is disabled."
        )
    elif not schedule_again:
        logger.info(
            "Not scheduling another monitoring task as schedule_again was False."
        )
    else:
        scan_interval = get_network_service_scan_interval_for_organization(
            org_uuid=org_uuid,
            db_session=self.db_session,
        )
        next_time = DatetimeHelper.seconds_from_now(scan_interval)
        logger.info(
            "Queueing up an additional instance of %s in %s seconds (%s). Endpoint is %s:%s (%s)."
            %
            (self.name, scan_interval, next_time, ip_address, port, protocol))
        init_sig = network_service_inspection_pass.si(
            service_uuid=service_uuid,
            org_uuid=org_uuid,
            schedule_again=True,
        )
        init_sig.apply_async(eta=next_time)