Skip to content

Instantly share code, notes, and snippets.

@ashr
Created January 25, 2021 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashr/20fb4ddd283a0a1ea5180d8d9225822b to your computer and use it in GitHub Desktop.
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
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){
}
}
}
}
@ashr
Copy link
Author

ashr commented Jan 25, 2021

Uhh, for csv output, just pipe to a file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment