Skip to content

Commit

Permalink
Add ability to ouput computers csv
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1ll committed Jan 31, 2018
1 parent 3f349f6 commit 05be1c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/NtdsAudit/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private static void Main(string[] args)
var systemHivePath = commandLineApplication.Option("-s | --system <file>", "The path of the associated SYSTEM hive, required when using the pwdump option.", CommandOptionType.SingleValue);
var pwdumpPath = commandLineApplication.Option("-p | --pwdump <file>", "The path to output hashes in pwdump format.", CommandOptionType.SingleValue);
var usersCsvPath = commandLineApplication.Option("-u | --users-csv <file>", "The path to output user details in CSV format.", CommandOptionType.SingleValue);
var computersCsvPath = commandLineApplication.Option("-c | --computers-csv <file>", "The path to output computer details in CSV format.", CommandOptionType.SingleValue);
var includeHistoryHashes = commandLineApplication.Option("--history-hashes", "Include history hashes in the pdwump output.", CommandOptionType.NoValue);
var dumpReversiblePath = commandLineApplication.Option("--dump-reversible <file>", "The path to output clear text passwords, if reversible encryption is enabled.", CommandOptionType.SingleValue);
var wordlistPath = commandLineApplication.Option("--wordlist", "The path to a wordlist of weak passwords for basic hash cracking. Warning, using this option is slow, the use of a dedicated password cracker, such as 'john', is recommended instead.", CommandOptionType.SingleValue);
Expand Down Expand Up @@ -97,6 +98,12 @@ private static void Main(string[] args)
argumentsValid = false;
}

if (computersCsvPath.HasValue() && !string.IsNullOrEmpty(Path.GetDirectoryName(computersCsvPath.Value())) && !Directory.Exists(Path.GetDirectoryName(computersCsvPath.Value())))
{
ConsoleEx.WriteError($"Computers CSV output directory \"{Path.GetDirectoryName(computersCsvPath.Value())}\" does not exist.");
argumentsValid = false;
}

if (dumpReversiblePath.HasValue() && !string.IsNullOrEmpty(Path.GetDirectoryName(dumpReversiblePath.Value())) && !Directory.Exists(Path.GetDirectoryName(dumpReversiblePath.Value())))
{
ConsoleEx.WriteError($"Dump Reverible output directory \"{Path.GetDirectoryName(dumpReversiblePath.Value())}\" does not exist.");
Expand Down Expand Up @@ -131,6 +138,11 @@ private static void Main(string[] args)
{
WriteUsersCsvFile(usersCsvPath.Value(), ntdsAudit, baseDateTime);
}

if (computersCsvPath.HasValue())
{
WriteComputersCsvFile(computersCsvPath.Value(), ntdsAudit, baseDateTime);
}
}

return argumentsValid ? 0 : -1;
Expand Down Expand Up @@ -203,6 +215,19 @@ private static void PrintConsoleStatistics(NtdsAudit ntdsAudit, DateTime baseDat
}
}

private static void WriteComputersCsvFile(string computersCsvPath, NtdsAudit ntdsAudit, DateTime baseDateTime)
{
using (var file = new StreamWriter(computersCsvPath, false))
{
file.WriteLine("Domain,Computer,Disabled,Last Logon");
foreach (var computer in ntdsAudit.Computers)
{
var domain = ntdsAudit.Domains.Single(x => x.Sid == computer.DomainSid);
file.WriteLine($"{domain.Fqdn},{computer.Name},{computer.Disabled},{computer.LastLogon}");
}
}
}

private static void WritePwDumpFile(string pwdumpPath, NtdsAudit ntdsAudit, DateTime baseDateTime, bool includeHistoryHashes, bool wordlistInUse, string dumpReversiblePath)
{
DomainInfo domain = null;
Expand Down
4 changes: 2 additions & 2 deletions src/NtdsAudit/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.4.0")]
[assembly: AssemblyFileVersion("2.0.4.0")]
[assembly: AssemblyVersion("2.0.5.0")]
[assembly: AssemblyFileVersion("2.0.5.0")]
[assembly: CLSCompliant(true)]

0 comments on commit 05be1c8

Please sign in to comment.