Ejemplo n.º 1
0
def main(unused_args):
    # Allow per platform configuration.
    config.CONFIG.AddContext(
        contexts.CLIENT_CONTEXT,
        "Context applied when we run the client process.")

    client_startup.ClientInit()

    if flags.FLAGS.install:
        installer.RunInstaller()

    errors = config.CONFIG.Validate(["Client", "CA", "Logging"])

    if errors and errors.keys() != ["Client.private_key"]:
        raise config_lib.ConfigFormatError(errors)

    enrollment_necessary = not config.CONFIG.Get("Client.private_key")
    # Instantiating the client will create a private_key so we need to use a flag.
    client = comms.GRRHTTPClient(ca_cert=config.CONFIG["CA.certificate"],
                                 private_key=config.CONFIG.Get(
                                     "Client.private_key", default=None))

    if enrollment_necessary:
        logging.info("No private key found, starting enrollment.")
        client.InitiateEnrolment()

    if flags.FLAGS.break_on_start:
        pdb.set_trace()
    else:
        client.Run()
Ejemplo n.º 2
0
def main(_):
    """Launch the appropriate builder."""
    args = flags.FLAGS
    if args.subparser_name == "generate_client_config":
        # We don't need a full init to just build a config.
        GetClientConfig(args.client_config_output)
        return

    # We deliberately use args.context because client_startup.py pollutes
    # grr_config.CONFIG.context with the running system context.
    context = args.context
    context.append("ClientBuilder Context")
    client_startup.ClientInit()

    # Use basic console output logging so we can see what is happening.
    logger = logging.getLogger()
    handler = logging.StreamHandler()
    handler.setLevel(logging.INFO)
    logger.handlers = [handler]

    if args.subparser_name == "build":
        TemplateBuilder().BuildTemplate(context=context, output=args.output)
    elif args.subparser_name == "repack":
        if args.debug_build:
            context.append("DebugClientBuild Context")
        result_path = repacking.TemplateRepacker().RepackTemplate(
            args.template,
            args.output_dir,
            context=context,
            sign=args.sign,
            signed_template=args.signed_template)

        if not result_path:
            raise ErrorDuringRepacking(" ".join(sys.argv[:]))
    elif args.subparser_name == "repack_multiple":

        # Resolve globs manually on Windows.
        templates = args.templates
        if templates and "*" in templates[0]:
            templates = glob.glob(templates[0])

        repack_configs = args.repack_configs
        if repack_configs and "*" in repack_configs[0]:
            repack_configs = glob.glob(repack_configs[0])

        MultiTemplateRepacker().RepackTemplates(
            repack_configs,
            templates,
            args.output_dir,
            config=args.config,
            sign=args.sign,
            signed_template=args.signed_template)
    elif args.subparser_name == "sign_template":
        repacking.TemplateRepacker().SignTemplate(args.template,
                                                  args.output_file,
                                                  context=context)
        if not os.path.exists(args.output_file):
            raise RuntimeError("Signing failed: output not written")
Ejemplo n.º 3
0
def main(unused_args):
  config.CONFIG.AddContext(contexts.CLIENT_CONTEXT,
                           "Context applied when we run the client process.")

  client_startup.ClientInit()

  if flags.FLAGS.install:
    installer.RunInstaller()

  if flags.FLAGS.break_on_start:
    pdb.set_trace()
  else:
    fleetspeak_client.GRRFleetspeakClient().Run()
Ejemplo n.º 4
0
def main(argv):
  del argv  # Unused.
  config.CONFIG.AddContext(contexts.POOL_CLIENT_CONTEXT,
                           "Context applied when we run the pool client.")

  client_startup.ClientInit()

  config.CONFIG.SetWriteBack("/dev/null")

  CheckLocation()

  # Let the OS handler also handle sleuthkit requests since sleuthkit is not
  # thread safe.
  tsk = rdf_paths.PathSpec.PathType.TSK
  os = rdf_paths.PathSpec.PathType.OS
  vfs.VFS_HANDLERS[tsk] = vfs.VFS_HANDLERS[os]

  CreateClientPool(flags.FLAGS.nrclients)
Ejemplo n.º 5
0
def main(_):
  """Launch the appropriate builder."""
  args = flags.FLAGS
  if args.subparser_name == "generate_client_config":
    # We don't need a full init to just build a config.
    GetClientConfig(args.client_config_output)
    return

  # We deliberately use args.context because client_startup.py pollutes
  # grr_config.CONFIG.context with the running system context.
  context = args.context
  context.append("ClientBuilder Context")
  client_startup.ClientInit()

  # Use basic console output logging so we can see what is happening.
  logger = logging.getLogger()
  handler = logging.StreamHandler()
  handler.setLevel(logging.INFO)
  logger.handlers = [handler]

  if args.subparser_name == "build":
    if grr_config.CONFIG.Get("ClientBuilder.fleetspeak_enabled"):
      if not args.fleetspeak_service_config:
        raise RuntimeError("--fleetspeak_service_config must be provided.")
      if not grr_config.CONFIG.Get("ClientBuilder.install_dir"):
        raise RuntimeError("ClientBuilder.install_dir must be set.")
      if not grr_config.CONFIG.Get("ClientBuilder.fleetspeak_plist_path"):
        raise RuntimeError("ClientBuilder.fleetspeak_plist_path must be set.")
      grr_config.CONFIG.Set("ClientBuilder.client_path",
                            "grr.client.grr_fs_client")
    TemplateBuilder().BuildTemplate(context=context, output=args.output)
  elif args.subparser_name == "repack":
    if args.debug_build:
      context.append("DebugClientBuild Context")
    result_path = repacking.TemplateRepacker().RepackTemplate(
        args.template,
        args.output_dir,
        context=context,
        sign=args.sign,
        signed_template=args.signed_template)

    if not result_path:
      raise ErrorDuringRepacking(" ".join(sys.argv[:]))
  elif args.subparser_name == "repack_multiple":

    # Resolve globs manually on Windows.
    templates = []
    for template in args.templates:
      if "*" in template:
        templates.extend(glob.glob(template))
      else:
        # This could go through glob but then we'd swallow errors for
        # non existing files.
        templates.append(template)

    repack_configs = []
    for repack_config in args.repack_configs:
      if "*" in repack_config:
        repack_configs.extend(glob.glob(repack_config))
      else:
        # This could go through glob but then we'd swallow errors for
        # non existing files.
        repack_configs.append(repack_config)

    MultiTemplateRepacker().RepackTemplates(
        repack_configs,
        templates,
        args.output_dir,
        config=args.config,
        sign=args.sign,
        signed_template=args.signed_template)
  elif args.subparser_name == "sign_template":
    repacking.TemplateRepacker().SignTemplate(
        args.template, args.output_file, context=context)
    if not os.path.exists(args.output_file):
      raise RuntimeError("Signing failed: output not written")