Created
January 25, 2021 14:33
-
-
Save ashr/20fb4ddd283a0a1ea5180d8d9225822b to your computer and use it in GitHub Desktop.
Generate a CSV containing ParentObject and SPN name from BloodHound export of GetAllSPNS Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
namespace spns | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string json = ""; | |
using (StreamReader reader = new StreamReader("allSPNS.json")){ | |
json = reader.ReadToEnd(); | |
} | |
var parsedJSON = JObject.Parse(json); | |
try{ | |
int nodeCount = 0; | |
//parsedJSON["nodes"].Count(); will get you just as far, i forgot to include system.linq when i wrote this | |
foreach (var element in parsedJSON){ | |
Console.WriteLine(element.Value.Count()); | |
if (element.Key == "nodes"){ | |
nodeCount = element.Value.Count(); | |
} | |
} | |
for (int i = 0;i < nodeCount;i++){ | |
string label = parsedJSON["nodes"][i]["label"].ToString(); | |
for (int ii = 0;ii< parsedJSON["nodes"][i]["props"]["serviceprincipalnames"].Count();ii++){ | |
Console.WriteLine(label + "," + parsedJSON["nodes"][i]["props"]["serviceprincipalnames"][ii]); | |
} | |
} | |
} | |
catch(Exception e){ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uhh, for csv output, just pipe to a file