From ff41d4e5b0f994115b9cc9045d6bda5a40b8cf75 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Fri, 21 Apr 2017 00:53:08 +0100 Subject: [PATCH] Improve config.json handling, making single_location optional but bypasses the stacker automagic. --- volatility/cli/__init__.py | 18 ++++++++++-------- volatility/framework/automagic/stacker.py | 8 +++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/volatility/cli/__init__.py b/volatility/cli/__init__.py index 80e37a2a1..b62867cab 100644 --- a/volatility/cli/__init__.py +++ b/volatility/cli/__init__.py @@ -98,6 +98,12 @@ class CommandLine(object): plugin = plugin_list[args.plugin] plugin_config_path = interfaces.configuration.path_join('plugins', plugin.__name__) + # UI fills in the config, here we load it from the config file and do it before we process the CL parameters + if args.config: + with open(args.config, "r") as f: + json_val = json.load(f) + ctx.config.splice(plugin_config_path, HierarchicalDict(json_val)) + # Populate the context config based on the returned args # We have already determined these elements must be descended from ConfigurableInterface vargs = vars(args) @@ -113,12 +119,6 @@ class CommandLine(object): extended_path = interfaces.configuration.path_join(config_path, requirement.name) ctx.config[extended_path] = value - # UI fills in the config: - if args.config: - with open(args.config, "r") as f: - json_val = json.load(f) - ctx.config.splice(plugin_config_path, HierarchicalDict(json_val)) - ### # BACK TO THE FRAMEWORK ### @@ -134,8 +134,10 @@ class CommandLine(object): constructed = plugin(ctx, plugin_config_path) - with open("config.json", "w") as f: - json.dump(dict(constructed.build_configuration()), f, sort_keys = True, indent = 2) + if args.verbosity >= 2: + vollog.debug("Writing out configuration data to config.json") + with open("config.json", "w") as f: + json.dump(dict(constructed.build_configuration()), f, sort_keys = True, indent = 2) # Construct and run the plugin QuickTextRenderer().render(constructed.run()) diff --git a/volatility/framework/automagic/stacker.py b/volatility/framework/automagic/stacker.py index 38738b7fa..c05ff03f4 100644 --- a/volatility/framework/automagic/stacker.py +++ b/volatility/framework/automagic/stacker.py @@ -11,8 +11,7 @@ import logging from urllib import parse import volatility -from volatility.framework import configuration -from volatility.framework import interfaces +from volatility.framework import configuration, interfaces from volatility.framework.automagic import construct_layers from volatility.framework.configuration import requirements from volatility.framework.layers import physical @@ -48,6 +47,9 @@ class LayerStacker(interfaces.automagic.AutomagicInterface): vollog.info("Unable to run LayerStacker, unsatisfied requirement: {}".format(unsatisfied)) return unsatisfied location = self.config["single_location"] + if not location: + vollog.info("Unable to run LayerStacker, single_location parameter not provided") + return [] self._check_type(location, str) self._check_type(requirement, interfaces.configuration.RequirementInterface) location = parse.urlparse(location) @@ -135,4 +137,4 @@ class LayerStacker(interfaces.automagic.AutomagicInterface): # This is not optional for the stacker to run, so optional must be marked as False return [requirements.StringRequirement("single_location", description = "Specifies a base location on which to stack", - optional = False)] + optional = True)]