-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathchophound.ps1
48 lines (38 loc) · 1.36 KB
/
chophound.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
param ([Parameter(Mandatory)]$File, [int]$ChunkSize=5000)
# Banner
"ChopHoundPS v1.0 ( https://github.com/bitsadmin/chophound/ )"
# Read file into memory
Write-Warning "Reading file $File"
$name_no_ext = [System.IO.Path]::GetFileNameWithoutExtension($File)
$js = Get-Content -Raw $File | ConvertFrom-Json
if(-not $?)
{
Write-Warning "Error while reading file. Quitting."
return
}
# Determine data tag name
$tagname = $js.meta.type
if($js.meta.version -gt 3)
{ $tagname = 'data' }
# Calculate number of blocks
$numblocks = [Math]::Ceiling($js.data.Count / $ChunkSize)
Write-Warning "Splitting in $numblocks blocks of $ChunkSize elements"
$i = 0
# Perform splitting
while($i*$ChunkSize -lt $js.data.Count)
{
$outname = "{0}_{1:0000}.json" -f $name_no_ext,$i
# meta -> count
$meta = $js.meta
$meta.count = $ChunkSize
if(($i+1)*$ChunkSize -gt $js.data.Count)
{ $meta.count = $js.data.Count - ($i*$ChunkSize)}
Write-Warning "Writing file $outname"
# Meta tag MUST be after the data, otherwise BloodHound won't find it
'{{"{0}":{1},"meta":{2}}}' -f `
$tagname, `
($js.data[($i*$ChunkSize)..((($i+1)*$ChunkSize)-1)] | ConvertTo-Json -Depth 100 -Compress), `
($meta | ConvertTo-Json -Compress) `
| Out-File $outname -NoNewline -Encoding UTF8BOM
$i++
}