-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41eb644
commit 5ec4ad6
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Modules/CIPPCore/Public/Entrypoints/Invoke-ListBreachesAccount.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using namespace System.Net | ||
|
||
Function Invoke-ListBreachesAccount { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
CIPP.Core.Read | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$APIName = $TriggerMetadata.FunctionName | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' | ||
|
||
$Results = Get-HIBPRequest "breachedaccount/$($Request.query.account)?truncateResponse=false" | ||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = @($results) | ||
}) | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
Modules/CIPPCore/Public/Entrypoints/Invoke-ListBreachesTenant.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using namespace System.Net | ||
|
||
Function Invoke-ListBreachesTenant { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
CIPP.Core.Read | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$APIName = $TriggerMetadata.FunctionName | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' | ||
$users = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users?`$select=UserPrincipalName,mail" -tenantid $Request.query.TenantFilter | ||
$usersResults = foreach ($user in $users) { | ||
$Results = Get-HIBPRequest "breachedaccount/$($user.UserPrincipalName)?truncateResponse=true" | ||
if ($null -eq $Results) { | ||
$Results = 'No breaches found.' | ||
} | ||
[PSCustomObject]@{ | ||
user = $user.UserPrincipalName | ||
breaches = $Results | ||
} | ||
} | ||
|
||
|
||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = @($usersResults) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function Get-HIBPAuth { | ||
if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true') { | ||
$DevSecretsTable = Get-CIPPTable -tablename 'DevSecrets' | ||
$Secret = (Get-CIPPAzDataTableEntity @DevSecretsTable -Filter "PartitionKey eq 'HIBP' and RowKey eq 'HIBP'").APIKey | ||
} else { | ||
$null = Connect-AzAccount -Identity | ||
$VaultName = ($ENV:WEBSITE_DEPLOYMENT_ID -split '-')[0] | ||
$Secret = Get-AzKeyVaultSecret -VaultName $VaultName -Name 'HIBP' -AsPlainText | ||
} | ||
|
||
return @{ | ||
'User-Agent' = "CIPP-$($ENV:TenantId)" | ||
'Accept' = 'application/json' | ||
'api-version' = '3' | ||
'hibp-api-key' = $Secret | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Modules/CippExtensions/Public/HIBP/Get-HIBPConnectionTest.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function Get-HIBPConnectionTest { | ||
$uri = 'https://haveibeenpwned.com/api/v3/subscription/status' | ||
try { | ||
Invoke-RestMethod -Uri $uri -Headers (Get-HIBPAuth) | ||
} catch { | ||
throw "Failed to connect to HIBP: $($_.Exception.Message)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function Get-HIBPRequest { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter()]$endpoint | ||
|
||
) | ||
$uri = "https://haveibeenpwned.com/api/v3/$endpoint" | ||
try { | ||
Invoke-RestMethod -Uri $uri -Headers (Get-HIBPAuth) | ||
} catch { | ||
#If the error is a 404, it means no breach has been found. Return an empty object. | ||
if ($_.Exception.Response.StatusCode -eq 404) { | ||
return @() | ||
} | ||
throw "Failed to connect to HIBP: $($_.Exception.Message)" | ||
} | ||
} |