Ejemplo n.º 1
0
  def ParseArguments(self, arguments):
    """Parses the command line arguments.

    Args:
      arguments (list[str]): command line arguments.

    Raises:
      CommandLineParseError: If arguments could not be parsed.
    """
    help_text = self._GenerateHelpText()

    argument_parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=help_text)

    self._AddRecipeOptions(argument_parser)

    self._command_line_options = argument_parser.parse_args(arguments)

    if not getattr(self._command_line_options, 'recipe', None):
      error_message = '\nPlease specify a recipe.\n' + help_text
      raise errors.CommandLineParseError(error_message)

    self._recipe = self._command_line_options.recipe

    self._state = DFTimewolfState(config.Config)
    logger.info('Loading recipe {0:s}...'.format(self._recipe['name']))
    # Raises errors.RecipeParseError on error.
    self._state.LoadRecipe(self._recipe)

    number_of_modules = len(self._recipe['modules'])
    logger.info('Loaded recipe {0:s} with {1:d} modules'.format(
        self._recipe['name'], number_of_modules))

    self._state.command_line_options = vars(self._command_line_options)
Ejemplo n.º 2
0
  def ParseArguments(self, arguments):
    """Parses the command line arguments.

    Args:
      arguments (list[str]): command line arguments.

    Returns:
      bool: True if the arguments were successfully parsed.
    """
    help_text = self._GenerateHelpText()

    argument_parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=help_text)

    self._AddRecipeOptions(argument_parser)

    self._command_line_options = argument_parser.parse_args(arguments)
    self._recipe = self._command_line_options.recipe

    self._state = DFTimewolfState(config.Config)
    print('Loading recipe...')
    self._state.load_recipe(self._recipe)

    number_of_modules = len(self._recipe['modules'])
    print('Loaded recipe {0:s} with {1:d} modules'.format(
        self._recipe['name'], number_of_modules))

    return True
Ejemplo n.º 3
0
def main():
    """Main function for DFTimewolf."""
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=generate_help())

    subparsers = parser.add_subparsers()

    for registered_recipe in config.Config.get_registered_recipes():
        recipe, recipe_args, documentation = registered_recipe
        subparser = subparsers.add_parser(
            recipe['name'],
            formatter_class=utils.DFTimewolfFormatterClass,
            description='{0:s}'.format(documentation))
        subparser.set_defaults(recipe=recipe)
        for switch, help_text, default in recipe_args:
            subparser.add_argument(switch, help=help_text, default=default)
        # Override recipe defaults with those specified in Config
        # so that they can in turn be overridden in the commandline
        subparser.set_defaults(**config.Config.get_extra())

    args = parser.parse_args()
    recipe = args.recipe

    # Thread all collectors.
    state = DFTimewolfState()

    for module_description in recipe['modules']:
        # Combine CLI args with args from the recipe description
        new_args = utils.import_args_from_dict(module_description['args'],
                                               vars(args), config.Config)

        # Create the module object and start processing
        module_name = module_description['name']
        print('Running module {0:s}'.format(module_name))
        module = config.Config.get_module(module_name)(state)
        module.setup(**new_args)
        state.check_errors()
        try:
            module.process()
        except DFTimewolfError as error:
            state.add_error(error.message, critical=True)

        # Check for eventual errors and clean up after each round.
        state.check_errors()
        state.cleanup()

    print('Recipe executed successfully.')
Ejemplo n.º 4
0
def main():
    """Main function for DFTimewolf."""
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=generate_help())

    subparsers = parser.add_subparsers()

    for registered_recipe in config.Config.get_registered_recipes():
        recipe, recipe_args, documentation = registered_recipe
        subparser = subparsers.add_parser(
            recipe['name'],
            formatter_class=utils.DFTimewolfFormatterClass,
            description='{0:s}'.format(documentation))
        subparser.set_defaults(recipe=recipe)
        for switch, help_text, default in recipe_args:
            subparser.add_argument(switch, help=help_text, default=default)
        # Override recipe defaults with those specified in Config
        # so that they can in turn be overridden in the commandline
        subparser.set_defaults(**config.Config.get_extra())

    args = parser.parse_args()
    recipe = args.recipe

    state = DFTimewolfState(config.Config)
    print('Loading recipes...')
    state.load_recipe(recipe)
    print('Loaded recipe {0:s} with {1:d} modules'.format(
        recipe['name'], len(recipe['modules'])))

    print('Setting up modules...')
    state.setup_modules(args)
    print('Modules successfully set up!')

    print('Running modules...')
    state.run_modules()
    print('Recipe {0:s} executed successfully.'.format(recipe['name']))