def main(unused_args):
    # Allow per platform configuration.
    config_lib.CONFIG.AddContext(
        "Client Context", "Context applied when we run the client process.")

    startup.ClientInit()

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

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

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

    enrollment_necessary = not config_lib.CONFIG.Get("Client.private_key")
    # Instantiating the client will create a private_key so we need to use a flag.
    client = GRRClient()
    if enrollment_necessary:
        logging.info("No private key found, starting enrollment.")
        client.client.InitiateEnrolment(comms.Status())

    if flags.FLAGS.break_on_start:
        pdb.set_trace()
    else:
        client.Run()
Exemplo n.º 2
0
def main(_):
    """Launch the appropriate builder."""
    config_lib.CONFIG.AddContext(
        "ClientBuilder Context",
        "Context applied when we run the client builder script.")

    startup.ClientInit()

    # The following is used to change the identity of the builder based on the
    # target platform.
    context = flags.FLAGS.context
    if args.arch == "amd64":
        context.append("Arch:amd64")
    else:
        context.append("Arch:i386")

    if args.subparser_name == "build":
        builder_obj = GetBuilder(context)
        builder_obj.MakeExecutableTemplate()

    elif args.subparser_name == "repack":
        deployer = GetDeployer(context)
        deployer.RepackInstaller(open(args.package, "rb").read(), args.output)

    elif args.subparser_name == "deploy":
        if args.plugins:
            config_lib.CONFIG.Set("Client.plugins", args.plugins)

        deployer = GetDeployer(context)
        template_path = args.template or config_lib.CONFIG.Get(
            "ClientBuilder.template_path", context=deployer.context)

        deployer.MakeDeployableBinary(template_path, args.output)
Exemplo n.º 3
0
def main(_):
    """Launch the appropriate builder."""
    config_lib.CONFIG.AddContext(
        "ClientBuilder Context",
        "Context applied when we run the client builder script.")

    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]

    context = flags.FLAGS.context
    context = SetContextFromArgs(context)
    signer = None

    if args.sign:
        if not args.templatedir:
            raise RuntimeError(
                "Signing must be performed on the host system since "
                "that's where the keys are. If you want signed "
                "binaries you need to build templates in the vagrant "
                "vms then pass the templatedir here to do the repack "
                "and sign operation on the host.")

        signer = GetSigner(context)

    if args.subparser_name == "build":
        template_path = None
        if flags.FLAGS.output:
            template_path = os.path.join(
                flags.FLAGS.output,
                config_lib.CONFIG.Get("PyInstaller.template_filename",
                                      context=context))

        builder_obj = GetBuilder(context)
        builder_obj.MakeExecutableTemplate(output_file=template_path)
    elif args.subparser_name == "repack":
        Repack(context, signer=signer)
    elif args.subparser_name == "deploy":
        Deploy(context, signer=signer)
    elif args.subparser_name == "buildanddeploy":
        if args.platform == "windows":
            # Handle windows differently because we do 32, 64, and debug builds all at
            # once.
            BuildAndDeployWindows(signer=signer)
        else:
            BuildAndDeploy(context, signer=signer)

    elif args.subparser_name == "build_components":
        component.BuildComponents(output_dir=flags.FLAGS.output)

    elif args.subparser_name == "build_component":
        component.BuildComponent(flags.FLAGS.setup_file,
                                 output_dir=flags.FLAGS.output)
Exemplo n.º 4
0
def main(_):
  """Launch the appropriate builder."""
  config_lib.CONFIG.AddContext(
      "ClientBuilder Context",
      "Context applied when we run the client builder script.")

  startup.ClientInit()

  # The following is used to change the identity of the builder based on the
  # target platform.
  context = flags.FLAGS.context
  if args.arch == "amd64":
    context.append("Arch:amd64")
  else:
    context.append("Arch:i386")

  if args.subparser_name == "build":
    builder_obj = GetBuilder(context)
    builder_obj.MakeExecutableTemplate()

  elif args.subparser_name == "repack":
    if args.plugins:
      config_lib.CONFIG.Set("Client.plugins", args.plugins)

    if args.debug_build:
      context += ["DebugClientBuild Context"]

    deployer = GetDeployer(context)
    output_filename = os.path.join(
        args.outputdir, config_lib.CONFIG.Get(
            "ClientBuilder.output_filename", context=deployer.context))

    deployer.RepackInstaller(open(args.template, "rb").read(), args.output or
                             output_filename)

  elif args.subparser_name == "deploy":
    if args.plugins:
      config_lib.CONFIG.Set("Client.plugins", args.plugins)

    if args.debug_build:
      context += ["DebugClientBuild Context"]

    deployer = GetDeployer(context)
    template_path = (args.template or TemplateInputFilename(deployer.context) or
                     config_lib.CONFIG.Get("ClientBuilder.template_path",
                                           context=deployer.context))

    # If output filename isn't specified, write to args.outputdir with a
    # .deployed extension so we can distinguish it from repacked binaries.
    filename = ".".join(
        (config_lib.CONFIG.Get("ClientBuilder.output_filename",
                               context=deployer.context), "deployed"))

    deployer.MakeDeployableBinary(template_path, args.output or os.path.join(
        args.outputdir, filename))
Exemplo n.º 5
0
def main(_):
  """Launch the appropriate builder."""
  config_lib.CONFIG.AddContext(
      "ClientBuilder Context",
      "Context applied when we run the client builder script.")

  startup.ClientInit()

  # Make sure we have all the secondary configs since they may be set under the
  # ClientBuilder Context
  for secondconfig in config_lib.CONFIG["ConfigIncludes"]:
    config_lib.CONFIG.LoadSecondaryConfig(secondconfig)

  # 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]

  context = flags.FLAGS.context
  context = SetContextFromArgs(context)
  signer = None
  if args.sign:
    signer = GetSigner(context)

  if args.subparser_name == "build":
    builder_obj = GetBuilder(context)
    builder_obj.MakeExecutableTemplate()
  elif args.subparser_name == "repack":
    Repack(context, signer=signer)
  elif args.subparser_name == "deploy":
    Deploy(context, signer=signer)
  elif args.subparser_name == "buildanddeploy":
    if args.platform == "windows":
      # Handle windows differently because we do 32, 64, and debug builds all at
      # once.
      BuildAndDeployWindows(signer=signer)
    else:
      BuildAndDeploy(context, signer=signer)
  elif args.subparser_name == "build_component":
    setup_file = flags.FLAGS.setup_file
    client_component = component.BuildComponent(setup_file)
    output = os.path.join(flags.FLAGS.output, "%s_%s_%s.bin" % (
        client_component.summary.name, client_component.summary.version,
        client_component.summary.build_system.signature()))

    with open(output, "wb") as fd:
      fd.write(client_component.SerializeToString())
      print "Built component %s" % output
Exemplo n.º 6
0
def main(_):
    """Launch the appropriate builder."""
    # We deliberately use flags.FLAGS.context because startup.py pollutes
    # config_lib.CONFIG.context with the running system context.
    context = flags.FLAGS.context
    context.append("ClientBuilder Context")
    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=flags.FLAGS.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":
        MultiTemplateRepacker().RepackTemplates(
            args.repack_configs,
            args.templates,
            args.output_dir,
            config=args.config,
            sign=args.sign,
            signed_template=args.signed_template)
    elif args.subparser_name == "build_components":
        component.BuildComponents(output_dir=flags.FLAGS.output)
    elif args.subparser_name == "build_component":
        component.BuildComponent(flags.FLAGS.setup_file,
                                 output_dir=flags.FLAGS.output)
    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")
Exemplo n.º 7
0
def main(unused_argv):
  """Main."""

  config_lib.CONFIG.AddContext("DataServer Context")
  startup.ClientInit()

  manager = Manager()
  if not manager.Start():
    print "Failed to start manager"
    return

  atexit.register(manager.SaveHistory)
  try:
    manager.Run()
  except (EOFError, KeyboardInterrupt):
    print
Exemplo n.º 8
0
def main(unused_argv):
  config_lib.CONFIG.AddContext("PoolClient Context",
                               "Context applied when we run the pool client.")

  startup.ClientInit()

  config_lib.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)
Exemplo n.º 9
0
def main(_):
    """Launch the appropriate builder."""
    config_lib.CONFIG.AddContext(
        "ClientBuilder Context",
        "Context applied when we run the client builder script.")

    startup.ClientInit()

    # Make sure we have all the secondary configs since they may be set under the
    # ClientBuilder Context
    for secondconfig in config_lib.CONFIG["ConfigIncludes"]:
        config_lib.CONFIG.LoadSecondaryConfig(secondconfig)

    # 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]

    context = flags.FLAGS.context
    context = SetContextFromArgs(context)
    signer = None
    if args.sign:
        signer = GetSigner(context)

    if args.subparser_name == "build":
        builder_obj = GetBuilder(context)
        builder_obj.MakeExecutableTemplate()
    elif args.subparser_name == "repack":
        Repack(context, signer=signer)
    elif args.subparser_name == "deploy":
        Deploy(context, signer=signer)
    elif args.subparser_name == "buildanddeploy":
        if args.platform == "windows":
            # Handle windows differently because we do 32, 64, and debug builds all at
            # once.
            BuildAndDeployWindows(signer=signer)
        else:
            BuildAndDeploy(context, signer=signer)

    elif args.subparser_name == "build_components":
        component.BuildComponents(output_dir=flags.FLAGS.output)

    elif args.subparser_name == "build_component":
        component.BuildComponent(flags.FLAGS.setup_file,
                                 output_dir=flags.FLAGS.output)
Exemplo n.º 10
0
def main(unused_args):
    # Allow per platform configuration.
    config_lib.CONFIG.AddContext(
        "Client Context", "Context applied when we run the client process.")

    startup.ClientInit()

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

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

    if not errors:
        client = GRRClient()
    elif errors.keys() == ["Client.private_key"]:
        client = GRRClient()
        client.client.InitiateEnrolment(comms.Status())
    else:
        raise config_lib.ConfigFormatError(errors)

    if flags.FLAGS.break_on_start:
        pdb.set_trace()
    else:
        client.Run()
Exemplo n.º 11
0
def main(_):
    """Launch the appropriate builder."""
    config_lib.CONFIG.AddContext(
        "ClientBuilder Context",
        "Context applied when we run the client builder script.")

    startup.ClientInit()

    # Make sure we have all the secondary configs since they may be set under the
    # ClientBuilder Context
    for secondconfig in config_lib.CONFIG["ConfigIncludes"]:
        config_lib.CONFIG.LoadSecondaryConfig(secondconfig)

    # 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]

    # The following is used to change the identity of the builder based on the
    # target platform.
    context = flags.FLAGS.context
    if args.arch == "amd64":
        context.append("Arch:amd64")
    else:
        context.append("Arch:i386")

    if args.subparser_name == "build":
        builder_obj = GetBuilder(context)
        builder_obj.MakeExecutableTemplate()

    elif args.subparser_name == "repack":
        if args.plugins:
            config_lib.CONFIG.Set("Client.plugins", args.plugins)

        if args.debug_build:
            context += ["DebugClientBuild Context"]

        deployer = GetDeployer(context)
        output_filename = os.path.join(
            args.outputdir,
            config_lib.CONFIG.Get("ClientBuilder.output_filename",
                                  context=deployer.context))

        deployer.RepackInstaller(
            open(args.template, "rb").read(), args.output or output_filename)

    elif args.subparser_name == "deploy":
        if args.plugins:
            config_lib.CONFIG.Set("Client.plugins", args.plugins)

        if args.debug_build:
            context += ["DebugClientBuild Context"]

        deployer = GetDeployer(context)
        template_path = (args.template or TemplateInputFilename(
            deployer.context) or config_lib.CONFIG.Get(
                "ClientBuilder.template_path", context=deployer.context))

        # If neither output filename or output directory is specified,
        # use the default location from the config file.
        output = None
        if args.output:
            output = args.output
        elif args.outputdir:
            # If output filename isn't specified, write to args.outputdir with a
            # .deployed extension so we can distinguish it from repacked binaries.
            filename = ".".join(
                (config_lib.CONFIG.Get("ClientBuilder.output_filename",
                                       context=deployer.context), "deployed"))
            output = os.path.join(args.outputdir, filename)

        deployer.MakeDeployableBinary(template_path, output)

    elif args.subparser_name == "buildanddeploy":
        BuildAndDeploy(context)