Skip to content

Commit d89be95

Browse files
committed
Add Azure collectors
1 parent 60485fa commit d89be95

2 files changed

Lines changed: 142 additions & 12 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
function Get-MonkeyAzAppServiceEnvironment {
17+
<#
18+
.SYNOPSIS
19+
Collector to get information from Azure App Service Environment
20+
21+
.DESCRIPTION
22+
Collector to get information from Azure App Service Environment
23+
24+
.INPUTS
25+
26+
.OUTPUTS
27+
28+
.EXAMPLE
29+
30+
.NOTES
31+
Author : Juan Garrido
32+
Twitter : @tr1ana
33+
File Name : Get-MonkeyAzAppServiceEnvironment
34+
Version : 1.0
35+
36+
.LINK
37+
https://github.com/silverhack/monkey365
38+
#>
39+
40+
[CmdletBinding()]
41+
param(
42+
[Parameter(Mandatory = $false,HelpMessage = "Background Collector ID")]
43+
[string]$collectorId
44+
)
45+
begin {
46+
#Collector metadata
47+
$monkey_metadata = @{
48+
Id = "az00163";
49+
Provider = "Azure";
50+
Resource = "App Service Environment";
51+
ResourceType = $null;
52+
resourceName = $null;
53+
collectorName = "Get-MonkeyAzAppServiceEnvironment";
54+
ApiType = "resourceManagement";
55+
description = "Collector to get information from Azure App Service Environment";
56+
Group = @(
57+
"AppServices"
58+
);
59+
Tags = @(
60+
61+
);
62+
references = @(
63+
"https://silverhack.github.io/monkey365/"
64+
);
65+
ruleSuffixes = @(
66+
"az_app_service_environment"
67+
);
68+
dependsOn = @(
69+
70+
);
71+
enabled = $true;
72+
supportClientCredential = $true
73+
}
74+
#config
75+
$config = $O365Object.internal_config.ResourceManager | Where-Object { $_.Name -eq "azureAppServiceEnvironment" } | Select-Object -ExpandProperty resource
76+
#Get all app service hosting environments
77+
$hostingEnvironments = $O365Object.all_resources.Where({ $_.type -eq 'Microsoft.Web/hostingEnvironments' })
78+
if (-not $hostingEnvironments) { continue }
79+
#Set array
80+
$all_environments = [System.Collections.Generic.List[System.Object]]::new()
81+
}
82+
process {
83+
$msg = @{
84+
MessageData = ($message.MonkeyGenericTaskMessage -f $collectorId,"Azure app service environment",$O365Object.current_subscription.displayName);
85+
callStack = (Get-PSCallStack | Select-Object -First 1);
86+
logLevel = 'info';
87+
InformationAction = $O365Object.InformationAction;
88+
Tags = @('AzureAPPServices');
89+
}
90+
Write-Information @msg
91+
if ($hostingEnvironments.Count -gt 0) {
92+
$new_arg = @{
93+
APIVersion = $config.api_version;
94+
}
95+
$p = @{
96+
ScriptBlock = { Get-MonkeyAzAppServiceEnvironmentInfo -InputObject $_ };
97+
Arguments = $new_arg;
98+
Runspacepool = $O365Object.monkey_runspacePool;
99+
ReuseRunspacePool = $true;
100+
Debug = $O365Object.VerboseOptions.Debug;
101+
Verbose = $O365Object.VerboseOptions.Verbose;
102+
MaxQueue = $O365Object.nestedRunspaces.MaxQueue;
103+
BatchSleep = $O365Object.nestedRunspaces.BatchSleep * 2;
104+
BatchSize = [int][Math]::Truncate($O365Object.nestedRunspaces.BatchSize / 3);
105+
}
106+
$all_environments = $hostingEnvironments | Invoke-MonkeyJob @p
107+
}
108+
}
109+
end {
110+
if ($all_environments) {
111+
$all_environments.PSObject.TypeNames.Insert(0,'Monkey365.Azure.AppService.Environment')
112+
[pscustomobject]$obj = @{
113+
Data = $all_environments;
114+
Metadata = $monkey_metadata;
115+
}
116+
$returnData.az_app_service_environment = $obj
117+
}
118+
else {
119+
$msg = @{
120+
MessageData = ($message.MonkeyEmptyResponseMessage -f "Azure app service Environment",$O365Object.TenantID);
121+
callStack = (Get-PSCallStack | Select-Object -First 1);
122+
logLevel = "verbose";
123+
InformationAction = $O365Object.InformationAction;
124+
Tags = @('AzureAppServicesEmptyResponse');
125+
Verbose = $O365Object.Verbose;
126+
}
127+
Write-Verbose @msg
128+
}
129+
}
130+
}
131+
132+
133+
134+
135+
136+
137+
138+
139+

collectors/azure/appservices/Get-MonkeyAzAppServiceInfo.ps1

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function Get-MonkeyAzAppServiceInfo {
7474
#config
7575
$config = $O365Object.internal_config.ResourceManager | Where-Object { $_.Name -eq "azureWebApps" } | Select-Object -ExpandProperty resource
7676
#Get all sites
77-
$app_services = $O365Object.all_resources.Where({ $_.type -eq 'Microsoft.Web/sites' })
77+
$app_services = $O365Object.all_resources.Where({$_.type -eq 'Microsoft.Web/sites' -or $_.type -eq 'Microsoft.Web/sites/slots' })
7878
if (-not $app_services) { continue }
7979
#Set array
8080
$all_apps = New-Object System.Collections.Generic.List[System.Object]
@@ -100,8 +100,8 @@ function Get-MonkeyAzAppServiceInfo {
100100
Debug = $O365Object.VerboseOptions.Debug;
101101
Verbose = $O365Object.VerboseOptions.Verbose;
102102
MaxQueue = $O365Object.nestedRunspaces.MaxQueue;
103-
BatchSleep = $O365Object.nestedRunspaces.BatchSleep;
104-
BatchSize = $O365Object.nestedRunspaces.BatchSize;
103+
BatchSleep = $O365Object.nestedRunspaces.BatchSleep * 2;
104+
BatchSize = [int][Math]::Truncate($O365Object.nestedRunspaces.BatchSize / 3);
105105
}
106106
$all_apps = $app_services | Invoke-MonkeyJob @p
107107
}
@@ -128,12 +128,3 @@ function Get-MonkeyAzAppServiceInfo {
128128
}
129129
}
130130
}
131-
132-
133-
134-
135-
136-
137-
138-
139-

0 commit comments

Comments
 (0)