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 branch 'KelvinTegelaar:master' into master
- Loading branch information
Showing
27 changed files
with
801 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action | ||
# More GitHub Actions for Azure: https://github.com/Azure/actions | ||
|
||
name: Build and deploy Powershell project to Azure Function App - cippwuxwa | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
workflow_dispatch: | ||
|
||
env: | ||
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root | ||
|
||
jobs: | ||
deploy: | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- name: 'Checkout GitHub Action' | ||
uses: actions/checkout@v4 | ||
|
||
- name: 'Run Azure Functions Action' | ||
uses: Azure/functions-action@v1 | ||
id: fa | ||
with: | ||
app-name: 'cippwuxwa' | ||
slot-name: 'Production' | ||
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} | ||
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_1FC84D1E2F0943369990DCD13A4AEB3A }} |
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
Oops, something went wrong.