forked from thinkst/canary-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoke-GetFactoryAuth.ps1
40 lines (31 loc) · 1.33 KB
/
Invoke-GetFactoryAuth.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
# VARIABLES - Dynamic/ChangeMe
$Memo = "tokendropper-created-by-thinkst-support"
# Connect to API
# Get Console Domain
$ApiHost = [string]::Empty
Do {
$ApiHost = Read-Host -Prompt "[+] Enter your Full Canary domain (e.g. 'xyz.canary.tools')"
} Until (($ApiHost.Length -gt 0) -and ([System.Net.Dns]::GetHostEntry($ApiHost).AddressList[0].IPAddressToString))
# Get API Auth Token
$ApiTokenSecure = New-Object System.Security.SecureString
Do {
$ApiTokenSecure = Read-Host -AsSecureString -Prompt "[+] Enter your Canary API key"
} Until ($ApiTokenSecure.Length -gt 0)
$ApiToken = (New-Object System.Management.Automation.PSCredential "user", $ApiTokenSecure).GetNetworkCredential().Password
Write-Host -ForegroundColor Green "[*] Starting Script with the following params:
Console Domain = $ApiHost
"
$ApiBaseURL = '/api/v1'
Write-Host -ForegroundColor Green "[*] Pinging Console..."
$PingResult = Invoke-RestMethod -Method Get -Uri "https://$ApiHost$ApiBaseURL/ping?auth_token=$ApiToken"
$Result = $PingResult.result
If ($Result -ne 'success') {
Write-Host -ForegroundColor Red "[X] Cannot ping Canary API. Bad token?"
Exit
}
Else {
Write-Host -ForegroundColor Green "[*] Canary API available for service!"
}
curl.exe -s https://$ApiHost$ApiBaseURL/canarytoken/create_factory `
-d auth_token=$ApiToken `
-d memo=$Memo