Пример #1
0
def ListGrrBinaries(
    context: api_context.GrrApiContext) -> utils.ItemsIterator[GrrBinary]:
  """Lists all registered Grr binaries."""

  items = context.SendIteratorRequest("ListGrrBinaries", None)
  return utils.MapItemsIterator(
      lambda data: GrrBinary(data=data, context=context), items)
Пример #2
0
def ListHunts(context: context_lib.GrrApiContext) -> utils.ItemsIterator[Hunt]:
    """List all GRR hunts."""

    items = context.SendIteratorRequest("ListHunts",
                                        hunt_pb2.ApiListHuntsArgs())
    return utils.MapItemsIterator(
        lambda data: Hunt(data=data, context=context), items)
Пример #3
0
def CreatePerClientFileCollectionHunt(
        hunt_args: hunt_pb2.ApiCreatePerClientFileCollectionHuntArgs,
        context: context_lib.GrrApiContext) -> Hunt:
    """Createt a per-client file collection hunt."""

    data = context.SendRequest("CreatePerClientFileCollectionHunt", hunt_args)
    return Hunt(data=data, context=context)
Пример #4
0
def ListArtifacts(
        context: api_context.GrrApiContext) -> utils.ItemsIterator[Artifact]:
    """Lists all registered Grr artifacts."""
    args = api_artifact_pb2.ApiListArtifactsArgs()

    items = context.SendIteratorRequest("ListArtifacts", args)
    return utils.MapItemsIterator(
        lambda data: Artifact(data=data, context=context), items)
Пример #5
0
def GetOpenApiDescription(
    context: api_context.GrrApiContext = None, ) -> Dict[str, Any]:
    """Returns the OpenAPI description of the GRR API as a dictionary."""
    if not context:
        raise ValueError("context can't be empty")

    openapi_proto = context.SendRequest("GetOpenApiDescription", None)
    openapi_json = openapi_proto.openapi_description

    return json.loads(openapi_json)
Пример #6
0
def CreatePerClientFileCollectionHunt(
        hunt_args: hunt_pb2.ApiCreatePerClientFileCollectionHuntArgs,
        context: context_lib.GrrApiContext) -> Hunt:
    """Createt a per-client file collection hunt."""

    data = context.SendRequest("CreatePerClientFileCollectionHunt", hunt_args)
    if not isinstance(data, hunt_pb2.ApiHunt):
        raise TypeError(f"Unexpected response type: '{type(data)}'")

    return Hunt(data=data, context=context)
Пример #7
0
def ListHuntApprovals(
        context: context_lib.GrrApiContext
) -> utils.ItemsIterator[HuntApproval]:
    """List all hunt approvals belonging to requesting user."""
    items = context.SendIteratorRequest("ListHuntApprovals",
                                        user_pb2.ApiListHuntApprovalsArgs())

    def MapHuntApproval(data):
        return HuntApproval(data=data,
                            username=context.username,
                            context=context)

    return utils.MapItemsIterator(MapHuntApproval, items)
Пример #8
0
def GetOpenApiDescription(
    context: api_context.GrrApiContext = None, ) -> Dict[str, Any]:
    """Returns the OpenAPI description of the GRR API as a dictionary."""
    if not context:
        raise ValueError("context can't be empty")

    openapi_proto = context.SendRequest("GetOpenApiDescription", None)
    if not isinstance(openapi_proto, metadata_pb2.ApiGetGrrVersionResult):
        raise TypeError(f"Unexpected response type: {type(openapi_proto)}")

    openapi_json = openapi_proto.openapi_description

    return json.loads(openapi_json)
Пример #9
0
def UploadYaraSignature(
    signature: Text,
    context: api_context.GrrApiContext,
) -> bytes:
    """Uploads the specified YARA signature.

  Args:
    signature: A YARA signature to upload.
    context: An GRR API context object.

  Returns:
    A reference to the uploaded blob.
  """
    args = yara_pb2.ApiUploadYaraSignatureArgs(signature=signature)

    response = context.SendRequest("UploadYaraSignature", args)
    if not isinstance(response, yara_pb2.ApiUploadYaraSignatureResult):
        raise TypeError(f"Unexpected response type: {type(response)}")

    return response.blob_id
Пример #10
0
def CreateHunt(
    flow_name: str,
    flow_args: message.Message,
    hunt_runner_args: flows_pb2.HuntRunnerArgs,
    context: context_lib.GrrApiContext,
) -> Hunt:
    """Creates a new hunt.

  Args:
    flow_name: String with a name of a flow that will run on all the clients
        in the hunt.
    flow_args: Flow arguments to be used. A proto, that depends on a flow.
    hunt_runner_args: flows_pb2.HuntRunnerArgs instance. Used to specify
        description, client_rule_set, output_plugins and other useful
        hunt attributes.
    context: API context.

  Raises:
    ValueError: if flow_name is empty.

  Returns:
    Hunt object corresponding to the created hunt.
  """
    if not flow_name:
        raise ValueError("flow_name can't be empty")

    request = hunt_pb2.ApiCreateHuntArgs(flow_name=flow_name)
    if flow_args:
        request.flow_args.value = flow_args.SerializeToString()
        request.flow_args.type_url = utils.GetTypeUrl(flow_args)

    if hunt_runner_args:
        request.hunt_runner_args.CopyFrom(hunt_runner_args)

    data = context.SendRequest("CreateHunt", request)
    if not isinstance(data, hunt_pb2.ApiHunt):
        raise TypeError(f"Unexpected response type: '{type(data)}'")

    return Hunt(data=data, context=context)