Esempio n. 1
0
    def Run(self):
        action = self.job.args.hunt_cron_action
        token = access_control.ACLToken(username="******")

        hunt_args = rdf_hunts.GenericHuntArgs(
            flow_args=action.flow_args,
            flow_runner_args=rdf_flow_runner.FlowRunnerArgs(
                flow_name=action.flow_name))
        with implementation.StartHunt(hunt_name=GenericHunt.__name__,
                                      args=hunt_args,
                                      runner_args=action.hunt_runner_args,
                                      token=token) as hunt:

            hunt.Run()
Esempio n. 2
0
File: hunt.py Progetto: hfakar/grr
    def Handle(self, args, token=None):
        """Creates a new hunt."""

        # We only create generic hunts with /hunts/create requests.
        generic_hunt_args = rdf_hunts.GenericHuntArgs()
        generic_hunt_args.flow_runner_args.flow_name = args.flow_name
        generic_hunt_args.flow_args = args.flow_args

        # Clear all fields marked with HIDDEN, except for output_plugins - they are
        # marked HIDDEN, because we have a separate UI for them, not because they
        # shouldn't be shown to the user at all.
        #
        # TODO(user): Refactor the code to remove the HIDDEN label from
        # HuntRunnerArgs.output_plugins.
        args.hunt_runner_args.ClearFieldsWithLabel(
            rdf_structs.SemanticDescriptor.Labels.HIDDEN,
            exceptions="output_plugins")
        args.hunt_runner_args.hunt_name = standard.GenericHunt.__name__

        if args.original_hunt and args.original_flow:
            raise ValueError(
                "A hunt can't be a copy of a flow and a hunt at the same time."
            )
        if args.original_hunt:
            ref = rdf_hunts.FlowLikeObjectReference.FromHuntId(
                utils.SmartStr(args.original_hunt.hunt_id))
            args.hunt_runner_args.original_object = ref
        elif args.original_flow:
            ref = rdf_hunts.FlowLikeObjectReference.FromFlowIdAndClientId(
                utils.SmartStr(args.original_flow.flow_id),
                utils.SmartStr(args.original_flow.client_id))
            args.hunt_runner_args.original_object = ref

        # Anyone can create the hunt but it will be created in the paused
        # state. Permissions are required to actually start it.
        with implementation.StartHunt(runner_args=args.hunt_runner_args,
                                      args=generic_hunt_args,
                                      token=token) as hunt:

            # Nothing really to do here - hunts are always created in the paused
            # state.
            logging.info("User %s created a new %s hunt (%s)", token.username,
                         hunt.args.flow_runner_args.flow_name, hunt.urn)

            return ApiHunt().InitFromAff4Object(hunt, with_full_summary=True)
Esempio n. 3
0
    def Run(self):
        if data_store.RelationalDBReadEnabled("hunts"):
            hra = self.job.args.hunt_cron_action.hunt_runner_args
            anbpcl = hra.avg_network_bytes_per_client_limit
            expiry_time = rdfvalue.RDFDatetime.Now() + hra.expiry_time
            hunt.CreateAndStartHunt(
                self.job.args.hunt_cron_action.flow_name,
                self.job.args.hunt_cron_action.flow_args,
                "Cron",
                avg_cpu_seconds_per_client_limit=hra.
                avg_cpu_seconds_per_client_limit,
                avg_network_bytes_per_client_limit=anbpcl,
                avg_results_per_client_limit=hra.avg_results_per_client_limit,
                client_limit=hra.client_limit,
                client_rate=hra.client_rate,
                client_rule_set=hra.client_rule_set,
                crash_limit=hra.crash_limit,
                description=hra.description,
                expiry_time=expiry_time,
                original_object=hra.original_object,
                output_plugins=hra.output_plugins,
                per_client_cpu_limit=hra.per_client_cpu_limit,
                per_client_network_bytes_limit=hra.
                per_client_network_limit_bytes,
            )
        else:
            action = self.job.args.hunt_cron_action
            token = access_control.ACLToken(username="******")

            hunt_args = rdf_hunts.GenericHuntArgs(
                flow_args=action.flow_args,
                flow_runner_args=rdf_flow_runner.FlowRunnerArgs(
                    flow_name=action.flow_name))
            with implementation.StartHunt(hunt_name=GenericHunt.__name__,
                                          args=hunt_args,
                                          runner_args=action.hunt_runner_args,
                                          token=token) as hunt_obj:

                hunt_obj.Run()