Skip to content

Commit 429ad8b

Browse files
authored
Merge pull request #152 from ZephrFish/master
Updated -n flag to take an input file allowing for parsing list of target hosts
2 parents 0d3b420 + 851b3d3 commit 429ad8b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The key incantations are:
5252

5353
`-i` Disables computer and share discovery, requires a path to a directory in which to perform file discovery.
5454

55-
`-n` Disables computer discovery, takes a comma-separated list of hosts to do share and file discovery on.
55+
`-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.
5656

5757
`-y` TSV-formats the output.
5858

Snaffler/Config.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CommandLineParser.Arguments;
1+
using CommandLineParser.Arguments;
22
using Nett;
33
using NLog;
44
using SnaffCore.Concurrency;
@@ -101,7 +101,7 @@ private static Options ParseImpl(string[] args)
101101
SwitchArgument findSharesOnlyArg = new SwitchArgument('a', "sharesonly",
102102
"Stops after finding shares, doesn't walk their filesystems.", false);
103103
ValueArgument<string> compExclusionArg = new ValueArgument<string>('k', "exclusions", "Path to a file containing a list of computers to exclude from scanning.");
104-
ValueArgument<string> compTargetArg = new ValueArgument<string>('n', "comptarget", "Computer (or comma separated list) to target.");
104+
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.");
105105
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.");
106106
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.");
107107
ValueArgument<string> timeOutArg = new ValueArgument<string>('e', "timeout",
@@ -235,19 +235,23 @@ private static Options ParseImpl(string[] args)
235235
throw new Exception("Failed to get a valid list of excluded computers from the excluded computers list.");
236236
}
237237
}
238+
238239
if (compTargetArg.Parsed)
239240
{
240-
string[] compTargets = null;
241-
if (compTargetArg.Value.Contains(","))
241+
List<string> compTargets = new List<string>();
242+
if (compTargetArg.Value.Contains(Path.DirectorySeparatorChar))
242243
{
243-
compTargets = compTargetArg.Value.Split(',');
244-
244+
compTargets.AddRange(File.ReadLines(compTargetArg.Value).Select(line => line.Trim()));
245+
}
246+
else if (compTargetArg.Value.Contains(","))
247+
{
248+
compTargets.AddRange(compTargetArg.Value.Split(',').Select(x => x.Trim()));
245249
}
246250
else
247251
{
248-
compTargets = new string[] { compTargetArg.Value };
252+
compTargets.Add(compTargetArg.Value.Trim());
249253
}
250-
parsedConfig.ComputerTargets = compTargets;
254+
parsedConfig.ComputerTargets = compTargets.ToArray();
251255
}
252256

253257
if (findSharesOnlyArg.Parsed)

0 commit comments

Comments
 (0)