-
-
Save tothi/8d6c0c3c90dd781368ad5e44a6bac2d6 to your computer and use it in GitHub Desktop.
Split large SharpHound datasets (JSON files) into smaller files that can more easily be imported into BloodHound. Especially useful due to the Electron memory limitations and BloodHound CE (running in browser) 1GB file size limitation.
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
#!/usr/bin/python3 | |
# Based on https://gist.github.com/deltronzero/7c23bacf97b4b61c7a2f2950ef6f35d8 | |
# updated to current BloodHound JSON format (compatible with SharpHound 2.x and BloodHound CE) | |
# pip install simplejson | |
import simplejson | |
import sys | |
def splitfile(file_name, object_limit): | |
print(f"[*] Loading {file_name}") | |
with open(file_name) as f: | |
data = simplejson.load(f) | |
total_objects = data['meta']['count'] | |
#file_type = data['meta']['type'] | |
file_type = 'data' | |
print(f"Total Objects: {total_objects}") | |
object_count = 0 | |
file_count = 0 | |
while object_count < total_objects: | |
a = {} | |
a[file_type] = data[file_type][object_count:][:object_limit] | |
object_count += len(a[file_type]) | |
a['meta'] = data['meta'] | |
a['meta']['count'] = object_count | |
f_split = file_name.split("\\")[-1].split(".") | |
file_name_out = f"{f_split[0]}_{file_count}.{f_split[1]}" | |
print(f"[*] Writing {file_name_out} - {object_count} of {total_objects}") | |
f_out = open(file_name_out, "w") | |
simplejson.dump(a, f_out) | |
f_out.close() | |
file_count += 1 | |
def main(): | |
if len(sys.argv) < 2: | |
print(sys.argv[0] + " filename.json [object_limit]") | |
return | |
if len(sys.argv) < 3: | |
splitfile(sys.argv[1], 20000) | |
else: | |
splitfile(sys.argv[1], int(sys.argv[2])) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment