-
Notifications
You must be signed in to change notification settings - Fork 1
/
azurehound.ps1
57 lines (47 loc) · 1.7 KB
/
azurehound.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
49
50
51
52
53
54
55
56
57
[CmdletBinding()]
param (
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$refreshToken,
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$domain
)
# Assuming $response and $domain are already set
# $tok = $response.refresh_token
$tok = $refreshToken
# Azure hound bins
# Determine the operating system using the OS environment variable
$osType = $env:OS
$binaryName = ""
$exePath = ""
if ($osType -eq "Windows_NT") {
$os = "windows"
Write-Output "Detected Windows OS."
$binaryName = "azurehound-windows-amd64.zip"
$exePath = ".\azurehound.exe"
} else {
$os = "linux"
Write-Output "Detected Linux OS."
$binaryName = "azurehound-linux-amd64.zip"
$exePath = "./azurehound"
}
# Define the output path
$outputZipFile = $binaryName
# Check if the binary already exists and delete it if it does
if (Test-Path -Path $outputZipFile) {
Remove-Item -Path $outputZipFile -Force
Write-Output "Existing AzureHound binary deleted."
}
# Download the correct AzureHound binary for the detected OS
$downloadUrl = "https://github.com/BloodHoundAD/AzureHound/releases/latest/download/$binaryName"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputZipFile
Write-Output "Downloaded the AzureHound binary for $os."
# Expand the downloaded zip file
Expand-Archive -LiteralPath $outputZipFile -DestinationPath . -Force
Write-Output "Extracted the AzureHound binary."
# Clean up the zip file
Remove-Item -Path $outputZipFile -Force
Write-Output "Cleaned up the downloaded zip file."
# Run AzureHound with the specified parameters
Write-Output "Running Azurehound."
& $exePath -r $tok list --tenant $domain -o azurehound.json
Write-Output "AzureHound command executed for $os."