示例#1
0
def CreateAndStartHunt(flow_name, flow_args, creator, **kwargs):
  """Creates and starts a new hunt."""

  # This interface takes a time when the hunt expires. However, the legacy hunt
  # starting interface took an rdfvalue.Duration object which was then added to
  # the current time to get the expiry. This check exists to make sure we don't
  # confuse the two.
  if "duration" in kwargs:
    precondition.AssertType(kwargs["duration"], rdfvalue.Duration)

  hunt_args = rdf_hunt_objects.HuntArguments(
      hunt_type=rdf_hunt_objects.HuntArguments.HuntType.STANDARD,
      standard=rdf_hunt_objects.HuntArgumentsStandard(
          flow_name=flow_name, flow_args=flow_args))

  hunt_obj = rdf_hunt_objects.Hunt(
      creator=creator,
      args=hunt_args,
      create_time=rdfvalue.RDFDatetime.Now(),
      **kwargs)

  CreateHunt(hunt_obj)
  StartHunt(hunt_obj.hunt_id)

  return hunt_obj.hunt_id
示例#2
0
  def CreateHunt(self,
                 flow_runner_args=None,
                 flow_args=None,
                 client_rule_set=None,
                 original_object=None,
                 client_rate=0,
                 duration=None,
                 token=None,
                 **kwargs):
    # Only initialize default flow_args value if default flow_runner_args value
    # is to be used.
    if not flow_runner_args:
      flow_args = (
          flow_args or transfer.GetFileArgs(
              pathspec=rdf_paths.PathSpec(
                  path="/tmp/evil.txt",
                  pathtype=rdf_paths.PathSpec.PathType.OS)))

    flow_runner_args = (
        flow_runner_args or
        rdf_flow_runner.FlowRunnerArgs(flow_name=transfer.GetFile.__name__))

    client_rule_set = (client_rule_set or self._CreateForemanClientRuleSet())

    if data_store.RelationalDBEnabled():
      token = token or self.token

      hunt_args = rdf_hunt_objects.HuntArguments(
          hunt_type=rdf_hunt_objects.HuntArguments.HuntType.STANDARD,
          standard=rdf_hunt_objects.HuntArgumentsStandard(
              flow_name=flow_runner_args.flow_name, flow_args=flow_args))

      hunt_obj = rdf_hunt_objects.Hunt(
          creator=token.username,
          client_rule_set=client_rule_set,
          original_object=original_object,
          client_rate=client_rate,
          duration=duration,
          args=hunt_args,
          **kwargs)
      hunt.CreateHunt(hunt_obj)

      return hunt_obj.hunt_id

    return implementation.StartHunt(
        hunt_name=standard.GenericHunt.__name__,
        flow_runner_args=flow_runner_args,
        flow_args=flow_args,
        client_rule_set=client_rule_set,
        client_rate=client_rate,
        original_object=original_object,
        token=token or self.token,
        **kwargs)
示例#3
0
文件: hunt.py 项目: secureonelabs/grr
  def _ArgsToHuntArgs(
      self, args: ApiCreatePerClientFileCollectionHuntArgs
  ) -> rdf_hunt_objects.HuntArguments:
    flow_groups = []
    for client_arg in args.per_client_args:
      pathspecs = []
      for p in client_arg.paths:
        pathspecs.append(
            rdf_paths.PathSpec(path=p, pathtype=client_arg.path_type))

      flow_name = transfer.MultiGetFile.__name__
      flow_args = transfer.MultiGetFileArgs(pathspecs=pathspecs)

      flow_group = rdf_hunt_objects.VariableHuntFlowGroup(
          client_ids=[client_arg.client_id],
          flow_name=flow_name,
          flow_args=rdf_structs.AnyValue.Pack(flow_args))
      flow_groups.append(flow_group)

    return rdf_hunt_objects.HuntArguments(
        hunt_type=rdf_hunt_objects.HuntArguments.HuntType.VARIABLE,
        variable=rdf_hunt_objects.HuntArgumentsVariable(
            flow_groups=flow_groups))