Skip to content

Commit

Permalink
Merge pull request #152 from ZephrFish/master
Browse files Browse the repository at this point in the history
Updated -n flag to take an input file allowing for parsing list of target hosts
  • Loading branch information
l0ss authored Oct 1, 2024
2 parents 0d3b420 + 851b3d3 commit 429ad8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
20 changes: 12 additions & 8 deletions Snaffler/Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommandLineParser.Arguments;
using CommandLineParser.Arguments;
using Nett;
using NLog;
using SnaffCore.Concurrency;
Expand Down Expand Up @@ -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<string> compExclusionArg = new ValueArgument<string>('k', "exclusions", "Path to a file containing a list of computers to exclude from scanning.");
ValueArgument<string> compTargetArg = new ValueArgument<string>('n', "comptarget", "Computer (or comma separated list) to target.");
ValueArgument<string> compTargetArg = new ValueArgument<string>('n', "comptarget", "List of computers in a file(e.g C:\targets.txt), a single Computer (or comma separated list) to target.");
ValueArgument<string> ruleDirArg = new ValueArgument<string>('p', "rulespath", "Path to a directory full of toml-formatted rules. Snaffler will load all of these in place of the default ruleset.");
ValueArgument<string> logType = new ValueArgument<string>('t', "logtype", "Type of log you would like to output. Currently supported options are plain and JSON. Defaults to plain.");
ValueArgument<string> timeOutArg = new ValueArgument<string>('e', "timeout",
Expand Down Expand Up @@ -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<string> compTargets = new List<string>();
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)
Expand Down

0 comments on commit 429ad8b

Please sign in to comment.