diff --git a/README.md b/README.md index 92cf1cd..490b4c0 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ The key incantations are: `-i` Disables computer and share discovery, requires a path to a directory in which to perform file discovery. -`-n` Disables computer discovery, takes a comma-separated list of hosts to do share and file discovery on. +`-n` Disables computer discovery, takes a comma-separated list of hosts or input file to do share and file discovery on. Note if supplying a file, the input needs to be a path so C:\targets.txt or .\targets.txt as an example. `-y` TSV-formats the output. diff --git a/Snaffler/Config.cs b/Snaffler/Config.cs index 66d575d..0a7e9a5 100644 --- a/Snaffler/Config.cs +++ b/Snaffler/Config.cs @@ -1,4 +1,4 @@ -using CommandLineParser.Arguments; +using CommandLineParser.Arguments; using Nett; using NLog; using SnaffCore.Concurrency; @@ -101,7 +101,7 @@ private static Options ParseImpl(string[] args) SwitchArgument findSharesOnlyArg = new SwitchArgument('a', "sharesonly", "Stops after finding shares, doesn't walk their filesystems.", false); ValueArgument compExclusionArg = new ValueArgument('k', "exclusions", "Path to a file containing a list of computers to exclude from scanning."); - ValueArgument compTargetArg = new ValueArgument('n', "comptarget", "Computer (or comma separated list) to target."); + ValueArgument compTargetArg = new ValueArgument('n', "comptarget", "List of computers in a file(e.g C:\targets.txt), a single Computer (or comma separated list) to target."); ValueArgument ruleDirArg = new ValueArgument('p', "rulespath", "Path to a directory full of toml-formatted rules. Snaffler will load all of these in place of the default ruleset."); ValueArgument logType = new ValueArgument('t', "logtype", "Type of log you would like to output. Currently supported options are plain and JSON. Defaults to plain."); ValueArgument timeOutArg = new ValueArgument('e', "timeout", @@ -235,19 +235,23 @@ private static Options ParseImpl(string[] args) throw new Exception("Failed to get a valid list of excluded computers from the excluded computers list."); } } + if (compTargetArg.Parsed) { - string[] compTargets = null; - if (compTargetArg.Value.Contains(",")) + List compTargets = new List(); + if (compTargetArg.Value.Contains(Path.DirectorySeparatorChar)) { - compTargets = compTargetArg.Value.Split(','); - + compTargets.AddRange(File.ReadLines(compTargetArg.Value).Select(line => line.Trim())); + } + else if (compTargetArg.Value.Contains(",")) + { + compTargets.AddRange(compTargetArg.Value.Split(',').Select(x => x.Trim())); } else { - compTargets = new string[] { compTargetArg.Value }; + compTargets.Add(compTargetArg.Value.Trim()); } - parsedConfig.ComputerTargets = compTargets; + parsedConfig.ComputerTargets = compTargets.ToArray(); } if (findSharesOnlyArg.Parsed)