forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request KelvinTegelaar#1077 from KelvinTegelaar/dev
Dev to release
- Loading branch information
Showing
26 changed files
with
771 additions
and
403 deletions.
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
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
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
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
44 changes: 44 additions & 0 deletions
44
Modules/CIPPCore/Public/Alerts/Get-CIPPAlertHuntressRogueApps.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,44 @@ | ||
function Get-CIPPAlertHuntressRogueApps { | ||
<# | ||
.SYNOPSIS | ||
Check for rogue apps in a Tenant | ||
.DESCRIPTION | ||
This function checks for rogue apps in the tenant by comparing the service principals in the tenant with a list of known rogue apps provided by Huntress. | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.LINK | ||
https://huntresslabs.github.io/rogueapps/ | ||
#> | ||
[CmdletBinding()] | ||
Param ( | ||
[Parameter(Mandatory = $false)] | ||
[Alias('input')] | ||
$InputValue, | ||
$TenantFilter | ||
) | ||
|
||
try { | ||
$RogueApps = Invoke-RestMethod -Uri 'https://raw.githubusercontent.com/huntresslabs/rogueapps/main/public/rogueapps.json' | ||
$RogueAppFilter = $RogueApps.appId -join "','" | ||
$ServicePrincipals = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/servicePrincipals?`$filter=appId in ('$RogueAppFilter')" -tenantid $TenantFilter | ||
|
||
if (($ServicePrincipals | Measure-Object).Count -gt 0) { | ||
$AlertData = foreach ($ServicePrincipal in $ServicePrincipals) { | ||
$RogueApp = $RogueApps | Where-Object { $_.appId -eq $ServicePrincipal.appId } | ||
[pscustomobject]@{ | ||
'App Name' = $RogueApp.appDisplayName | ||
'App Id' = $RogueApp.appId | ||
'Description' = $RogueApp.description | ||
'Enabled' = $ServicePrincipal.accountEnabled | ||
'Created' = $ServicePrincipal.createdDateTime | ||
'Tags' = $RogueApp.tags -join ', ' | ||
'References' = $RogueApp.references -join ', ' | ||
'Huntress Added' = $RogueApp.dateAdded | ||
} | ||
} | ||
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData | ||
} | ||
} catch { | ||
#Write-AlertMessage -tenant $($TenantFilter) -message "Failed to check for rogue apps for $($TenantFilter): $(Get-NormalizedError -message $_.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
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
69 changes: 69 additions & 0 deletions
69
...les/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecServicePrincipals.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,69 @@ | ||
function Invoke-ExecServicePrincipals { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
CIPP.Core.ReadWrite | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$TenantFilter = $env:TenantId | ||
|
||
$Success = $true | ||
|
||
$Action = $Request.Query.Action ?? 'Default' | ||
try { | ||
switch ($Request.Query.Action) { | ||
'Create' { | ||
$Action = 'Create' | ||
if ($Request.Query.AppId -match '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$') { | ||
$Body = @{ | ||
'appId' = $Request.Query.AppId | ||
} | ConvertTo-Json -Compress | ||
try { | ||
$Results = New-GraphPostRequest -Uri 'https://graph.microsoft.com/beta/servicePrincipals' -tenantid $TenantFilter -type POST -body $Body | ||
} catch { | ||
$Results = "Unable to create service principal: $($_.Exception.Message)" | ||
$Success = $false | ||
} | ||
} else { | ||
$Results = 'Invalid AppId' | ||
$Success = $false | ||
} | ||
} | ||
default { | ||
if ($Request.Query.AppId) { | ||
$Action = 'Get' | ||
$Results = New-GraphGetRequest -Uri "https://graph.microsoft.com/beta/servicePrincipals(appId='$($Request.Query.AppId)')" -tenantid $TenantFilter -NoAuthCheck $true | ||
} else { | ||
$Action = 'List' | ||
$Results = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/servicePrincipals?$top=999&$orderby=displayName&$count=true' -ComplexFilter -tenantid $TenantFilter -NoAuthCheck $true | ||
} | ||
} | ||
} | ||
} catch { | ||
$Results = $_.Exception.Message | ||
$Success = $false | ||
} | ||
|
||
$Metadata = @{ | ||
'Action' = $Action | ||
'Success' = $Success | ||
} | ||
|
||
if ($Request.Query.AppId) { | ||
$Metadata.AppId = $Request.Query.AppId | ||
} | ||
|
||
$Body = @{ | ||
'Results' = $Results | ||
'Metadata' = $Metadata | ||
} | ||
|
||
$Json = $Body | ConvertTo-Json -Depth 10 -Compress | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = $Json | ||
}) | ||
} |
42 changes: 42 additions & 0 deletions
42
...CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecSAMAppPermissions.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,42 @@ | ||
function Invoke-ExecSAMAppPermissions { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
CIPP.SuperAdmin.ReadWrite | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
switch ($Request.Query.Action) { | ||
'Update' { | ||
try { | ||
$Permissions = $Request.Body.Permissions | ||
$Entity = @{ | ||
'PartitionKey' = 'CIPP-SAM' | ||
'RowKey' = 'CIPP-SAM' | ||
'Permissions' = [string]($Permissions.Permissions | ConvertTo-Json -Depth 10 -Compress) | ||
} | ||
$Table = Get-CIPPTable -TableName 'AppPermissions' | ||
$null = Add-CIPPAzDataTableEntity @Table -Entity $Entity -Force | ||
$Body = @{ | ||
'Results' = 'Permissions Updated' | ||
} | ||
} catch { | ||
$Body = @{ | ||
'Results' = $_.Exception.Message | ||
} | ||
} | ||
} | ||
default { | ||
$Body = Get-CippSamPermissions | ||
} | ||
} | ||
|
||
|
||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = ConvertTo-Json -Depth 10 -InputObject $Body | ||
}) | ||
|
||
} |
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
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
Oops, something went wrong.