Beispiel #1
0
  def Handle(self, args, token=None):
    hunt_urn = args.hunt_id.ToURN()
    hunt = aff4.FACTORY.Open(
        hunt_urn, aff4_type=implementation.GRRHunt, token=token)

    hunt_api_object = ApiHunt().InitFromAff4Object(hunt)
    description = (
        "Files downloaded by hunt %s (%s, '%s') created by user %s "
        "on %s" % (hunt_api_object.name, hunt_api_object.urn.Basename(),
                   hunt_api_object.description, hunt_api_object.creator,
                   hunt_api_object.created))

    collection = implementation.GRRHunt.ResultCollectionForHID(hunt_urn)

    target_file_prefix = "hunt_" + hunt.urn.Basename().replace(":", "_")

    if args.archive_format == args.ArchiveFormat.ZIP:
      archive_format = api_call_handler_utils.CollectionArchiveGenerator.ZIP
      file_extension = ".zip"
    elif args.archive_format == args.ArchiveFormat.TAR_GZ:
      archive_format = api_call_handler_utils.CollectionArchiveGenerator.TAR_GZ
      file_extension = ".tar.gz"
    else:
      raise ValueError("Unknown archive format: %s" % args.archive_format)

    generator = api_call_handler_utils.CollectionArchiveGenerator(
        prefix=target_file_prefix,
        description=description,
        archive_format=archive_format)
    content_generator = self._WrapContentGenerator(
        generator, collection, args, token=token)
    return api_call_handler_base.ApiBinaryStream(
        target_file_prefix + file_extension,
        content_generator=content_generator)
Beispiel #2
0
    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)

        flow_api_object = ApiFlow().InitFromAff4Object(flow_obj,
                                                       flow_id=args.flow_id)
        description = (
            "Files downloaded by flow %s (%s) that ran on client %s by "
            "user %s on %s" %
            (flow_api_object.name, args.flow_id, args.client_id,
             flow_api_object.creator, flow_api_object.started_at))

        target_file_prefix = "%s_flow_%s_%s" % (
            args.client_id, flow_obj.runner_args.flow_name,
            flow_urn.Basename().replace(":", "_"))

        collection = flow.GRRFlow.ResultCollectionForFID(flow_urn)

        if args.archive_format == args.ArchiveFormat.ZIP:
            archive_format = api_call_handler_utils.CollectionArchiveGenerator.ZIP
            file_extension = ".zip"
        elif args.archive_format == args.ArchiveFormat.TAR_GZ:
            archive_format = api_call_handler_utils.CollectionArchiveGenerator.TAR_GZ
            file_extension = ".tar.gz"
        else:
            raise ValueError("Unknown archive format: %s" %
                             args.archive_format)

        generator = api_call_handler_utils.CollectionArchiveGenerator(
            prefix=target_file_prefix,
            description=description,
            archive_format=archive_format,
            predicate=self._BuildPredicate(args.client_id, token=token),
            client_id=args.client_id.ToClientURN())
        content_generator = self._WrapContentGenerator(generator,
                                                       collection,
                                                       args,
                                                       token=token)
        return api_call_handler_base.ApiBinaryStream(
            target_file_prefix + file_extension,
            content_generator=content_generator)
    def _GenerateArchive(self,
                         collection,
                         archive_format=api_call_handler_utils.
                         CollectionArchiveGenerator.ZIP,
                         predicate=None):

        fd_path = os.path.join(self.temp_dir, "archive")
        archive_generator = api_call_handler_utils.CollectionArchiveGenerator(
            archive_format=archive_format,
            predicate=predicate,
            prefix="test_prefix",
            description="Test description",
            client_id=self.client_id)
        with open(fd_path, "wb") as out_fd:
            for chunk in archive_generator.Generate(collection,
                                                    token=self.token):
                out_fd.write(chunk)

        return fd_path