From 0d4f0a346a86336c179094e55faede989dc917c2 Mon Sep 17 00:00:00 2001 From: Dominik Schaudel Date: Tue, 9 Aug 2016 21:13:07 -0700 Subject: [PATCH 1/2] Utilizing the Neo4j transactional HTTP endpoint --- PowerShell/BloodHound.ps1 | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/PowerShell/BloodHound.ps1 b/PowerShell/BloodHound.ps1 index 5eb1a5397..435ae007b 100644 --- a/PowerShell/BloodHound.ps1 +++ b/PowerShell/BloodHound.ps1 @@ -13737,7 +13737,7 @@ function Export-BloodHoundData { } $Authorized = $True - $ObjectBuffer = New-Object System.Collections.ArrayList + $Statements = New-Object System.Collections.ArrayList $UserDomainMappings = @{} if(-not $SkipGCDeconfliction) { @@ -14088,20 +14088,14 @@ function Export-BloodHoundData { Write-Verbose "No matching type name" } - # built the batch object submission object for each query ForEach($Query in $Queries) { - $BatchObject = @{ - "method" = "POST"; - "to" = "/cypher"; - "body" = @{"query"=$Query}; - } - $Null = $ObjectBuffer.Add($BatchObject) + $Null = $Statements.Add( @{ "statement"=$Query } ) } - - if ($ObjectBuffer.Count -ge $Throttle) { - $JsonRequest = ConvertTo-Json20 $ObjectBuffer - $Null = $WebClient.UploadString($URI.AbsoluteUri + "db/data/batch", $JsonRequest) - $ObjectBuffer.Clear() + if ($Statements.Count -ge $Throttle) { + $Json = @{ "statements"=[System.Collections.Hashtable[]]$Statements } + $JsonRequest = ConvertTo-Json20 $Json + $Null = $WebClient.UploadStrin($URI.AbsoluteUri + "db/data/transaction/commit", $JsonRequest) + $Statements.Clear() } } else { @@ -14110,9 +14104,10 @@ function Export-BloodHoundData { } end { if($Authorized) { - $JsonRequest = ConvertTo-Json20 $ObjectBuffer - $Null = $WebClient.UploadString($URI.AbsoluteUri + "db/data/batch", $JsonRequest) - $ObjectBuffer.Clear() + $Json = @{ "statements"=[System.Collections.Hashtable[]]$Statements } + $JsonRequest = ConvertTo-Json20 $Json + $Null = $WebClient.UploadStrin($URI.AbsoluteUri + "db/data/transaction/commit", $JsonRequest) + $Statements.Clear() } } } From 7c31109d994c25ee50c0c40ab7276c72ab6dc01f Mon Sep 17 00:00:00 2001 From: Dominik Schaudel Date: Tue, 9 Aug 2016 21:29:48 -0700 Subject: [PATCH 2/2] Fixed typo --- PowerShell/BloodHound.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell/BloodHound.ps1 b/PowerShell/BloodHound.ps1 index 435ae007b..6051b493d 100644 --- a/PowerShell/BloodHound.ps1 +++ b/PowerShell/BloodHound.ps1 @@ -14094,7 +14094,7 @@ function Export-BloodHoundData { if ($Statements.Count -ge $Throttle) { $Json = @{ "statements"=[System.Collections.Hashtable[]]$Statements } $JsonRequest = ConvertTo-Json20 $Json - $Null = $WebClient.UploadStrin($URI.AbsoluteUri + "db/data/transaction/commit", $JsonRequest) + $Null = $WebClient.UploadString($URI.AbsoluteUri + "db/data/transaction/commit", $JsonRequest) $Statements.Clear() } } @@ -14106,7 +14106,7 @@ function Export-BloodHoundData { if($Authorized) { $Json = @{ "statements"=[System.Collections.Hashtable[]]$Statements } $JsonRequest = ConvertTo-Json20 $Json - $Null = $WebClient.UploadStrin($URI.AbsoluteUri + "db/data/transaction/commit", $JsonRequest) + $Null = $WebClient.UploadString($URI.AbsoluteUri + "db/data/transaction/commit", $JsonRequest) $Statements.Clear() } }