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 #4 from KelvinTegelaar/master
[pull] master from KelvinTegelaar:master
- Loading branch information
Showing
32 changed files
with
857 additions
and
422 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 | ||
}) | ||
} |
56 changes: 56 additions & 0 deletions
56
.../CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecOffloadFunctions.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,56 @@ | ||
|
||
Function Invoke-ExecOffloadFunctions { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
CIPP.SuperAdmin.ReadWrite | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$roles = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($request.headers.'x-ms-client-principal')) | ConvertFrom-Json).userRoles | ||
if ('superadmin' -notin $roles) { | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::Forbidden | ||
Body = @{ error = 'You do not have permission to perform this action.' } | ||
}) | ||
return | ||
} else { | ||
$Table = Get-CippTable -tablename 'Config' | ||
|
||
if ($Request.Query.Action -eq 'ListCurrent') { | ||
$CurrentState = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'OffloadFunctions' and RowKey eq 'OffloadFunctions'" | ||
$CurrentState = if (!$CurrentState) { | ||
[PSCustomObject]@{ | ||
OffloadFunctions = $false | ||
} | ||
} else { | ||
[PSCustomObject]@{ | ||
OffloadFunctions = $CurrentState.state | ||
} | ||
} | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = $CurrentState | ||
}) | ||
} else { | ||
Add-CIPPAzDataTableEntity @Table -Entity @{ | ||
PartitionKey = 'OffloadFunctions' | ||
RowKey = 'OffloadFunctions' | ||
state = $request.Body.OffloadFunctions | ||
} -Force | ||
|
||
if ($Request.Body.OffloadFunctions) { | ||
$Results = 'Enabled Offload Functions' | ||
} else { | ||
$Results = 'Disabled Offload Functions' | ||
} | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = [HttpStatusCode]::OK | ||
Body = @{ results = $Results } | ||
}) | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.