Skip to content

Instantly share code, notes, and snippets.

@mgeeky
Forked from Acebond/bh_split2.py
Created May 25, 2021 09:56
Show Gist options
  • Select an option

  • Save mgeeky/3eb9e9caef9136d5b0f3b4dbd5ad77c4 to your computer and use it in GitHub Desktop.

Select an option

Save mgeeky/3eb9e9caef9136d5b0f3b4dbd5ad77c4 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.
#!/usr/bin/python3
# Based on https://gist.github.com/deltronzero/7c23bacf97b4b61c7a2f2950ef6f35d8
# 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']
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