コード例 #1
0
ファイル: hunt.py プロジェクト: secureonelabs/grr
  def Handle(self, args, context=None):
    used_names = collections.Counter()
    result = []
    try:
      plugin_states = data_store.REL_DB.ReadHuntOutputPluginsStates(
          str(args.hunt_id))
    except db.UnknownHuntError:
      raise HuntNotFoundError("Hunt with id %s could not be found" %
                              str(args.hunt_id))
    for s in plugin_states:
      name = s.plugin_descriptor.plugin_name
      plugin_id = "%s_%d" % (name, used_names[name])
      used_names[name] += 1

      state = s.plugin_state.Copy()
      if "source_urn" in state:
        del state["source_urn"]
      if "token" in state:
        del state["token"]
      if "errors" in state and not state["errors"]:
        del state["errors"]
      if "logs" in state and not state["logs"]:
        del state["logs"]
      if "error_count" in state and not state["error_count"]:
        del state["error_count"]
      if "success_count" in state and not state["success_count"]:
        del state["success_count"]

      api_plugin = api_output_plugin.ApiOutputPlugin(
          id=plugin_id, plugin_descriptor=s.plugin_descriptor, state=state)
      result.append(api_plugin)

    return ApiListHuntOutputPluginsResult(items=result, total_count=len(result))
コード例 #2
0
ファイル: flow.py プロジェクト: megatronGA/grr
    def Handle(self, args, token=None):
        flow_obj = data_store.REL_DB.ReadFlowObject(str(args.client_id),
                                                    str(args.flow_id))
        output_plugins_states = flow_obj.output_plugins_states

        type_indices = {}
        result = []
        for output_plugin_state in output_plugins_states:
            plugin_state = output_plugin_state.plugin_state.Copy()
            if "source_urn" in plugin_state:
                del plugin_state["source_urn"]
            if "token" in plugin_state:
                del plugin_state["token"]

            plugin_descriptor = output_plugin_state.plugin_descriptor
            type_index = type_indices.setdefault(plugin_descriptor.plugin_name,
                                                 0)
            type_indices[plugin_descriptor.plugin_name] += 1

            # Output plugins states are stored differently for hunts and for flows:
            # as a dictionary for hunts and as a simple list for flows.
            #
            # TODO(user): store output plugins states in the same way for flows
            # and hunts. Until this is done, we can emulate the same interface in
            # the HTTP API.
            api_plugin = api_output_plugin.ApiOutputPlugin(
                id=plugin_descriptor.plugin_name + "_%d" % type_index,
                plugin_descriptor=plugin_descriptor,
                state=plugin_state)
            result.append(api_plugin)

        return ApiListFlowOutputPluginsResult(items=result)
コード例 #3
0
ファイル: flow.py プロジェクト: youngjun-chang/grr
    def Handle(self, args, token=None):
        flow_urn = args.flow_id.ResolveClientFlowURN(args.client_id,
                                                     token=token)
        flow_obj = aff4.FACTORY.Open(flow_urn,
                                     aff4_type=flow.GRRFlow,
                                     mode="r",
                                     token=token)

        output_plugins_states = flow_obj.GetRunner(
        ).context.output_plugins_states

        type_indices = {}
        result = []
        for output_plugin_state in output_plugins_states:
            plugin_descriptor = output_plugin_state.plugin_descriptor
            plugin_state = output_plugin_state.plugin_state
            type_index = type_indices.setdefault(plugin_descriptor.plugin_name,
                                                 0)
            type_indices[plugin_descriptor.plugin_name] += 1

            # Output plugins states are stored differently for hunts and for flows:
            # as a dictionary for hunts and as a simple list for flows.
            #
            # TODO(user): store output plugins states in the same way for flows
            # and hunts. Until this is done, we can emulate the same interface in
            # the HTTP API.
            api_plugin = api_output_plugin.ApiOutputPlugin(
                id=plugin_descriptor.plugin_name + "_%d" % type_index,
                plugin_descriptor=plugin_descriptor,
                state=plugin_state)
            result.append(api_plugin)

        return ApiListFlowOutputPluginsResult(items=result)
コード例 #4
0
  def Handle(self, args, token=None):
    metadata = aff4.FACTORY.Create(
        args.hunt_id.ToURN().Add("ResultsMetadata"),
        mode="r",
        aff4_type=implementation.HuntResultsMetadata,
        token=token)

    plugins = metadata.Get(metadata.Schema.OUTPUT_PLUGINS, {})

    result = []
    for plugin_name, (plugin_descriptor, plugin_state) in plugins.items():
      api_plugin = api_output_plugin.ApiOutputPlugin(
          id=plugin_name,
          plugin_descriptor=plugin_descriptor,
          state=plugin_state)
      result.append(api_plugin)

    return ApiListHuntOutputPluginsResult(items=result, total_count=len(result))