-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-CrowdStrikePlatformProtection.ps1
More file actions
665 lines (612 loc) · 28.7 KB
/
Get-CrowdStrikePlatformProtection.ps1
File metadata and controls
665 lines (612 loc) · 28.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
# Azure Resource Protection Mapping Script
# This script identifies Azure resources and maps them to CrowdStrike protection capabilities
# Ensure Az CLI is installed and logged in
Write-Host "Checking Az CLI login status..." -ForegroundColor Cyan
try {
$loginStatus = az account show 2>$null
if (-not $loginStatus) {
Write-Host "Please login to Azure CLI first using 'az login'" -ForegroundColor Red
exit
}
}
catch {
Write-Host "Error checking login status: $_" -ForegroundColor Red
Write-Host "Please ensure Az CLI is installed and run 'az login'" -ForegroundColor Red
exit
}
Write-Host "Azure CLI is logged in. Proceeding with resource discovery..." -ForegroundColor Green
# Initialize results array
$results = @()
# Function to safely execute Az CLI commands with error handling
function Invoke-AzCommand {
param (
[string]$Command,
[string]$ErrorMessage
)
try {
$output = Invoke-Expression $Command 2>$null
return $output | ConvertFrom-Json
}
catch {
Write-Host "$($ErrorMessage): $_" -ForegroundColor Yellow
return $null
}
}
# Get all subscriptions
$subscriptions = Invoke-AzCommand -Command "az account list --query '[].{Name:name, Id:id}' -o json" -ErrorMessage "Error retrieving subscriptions"
if (-not $subscriptions) {
Write-Host "No subscriptions found or error occurred. Exiting." -ForegroundColor Red
exit
}
Write-Host "Found $($subscriptions.Count) subscription(s)" -ForegroundColor Cyan
foreach ($subscription in $subscriptions) {
Write-Host "Processing subscription: $($subscription.Name)" -ForegroundColor Yellow
az account set --subscription $subscription.Id
# Check for Entra ID (formerly Azure AD)
Write-Host "Checking for Entra ID..." -ForegroundColor Cyan
$entraID = Invoke-AzCommand -Command "az ad signed-in-user show" -ErrorMessage "Error checking Entra ID"
if ($entraID) {
$results += [PSCustomObject]@{
ResourceType = "Entra ID"
ResourceName = "Entra ID"
ResourceGroup = ""
Subscription = $subscription.Name
ProtectionCapabilities = "CIEM, SSPM"
}
}
# Get Virtual Machines (IaaS workloads)
Write-Host "Finding Virtual Machines..." -ForegroundColor Cyan
$vms = Invoke-AzCommand -Command "az vm list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving VMs"
if ($vms) {
foreach ($vm in $vms) {
$results += [PSCustomObject]@{
ResourceType = "Virtual Machine"
ResourceName = $vm.Name
ResourceGroup = $vm.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "EDR, CSPM, CIEM"
}
}
}
# Get Virtual Machine Scale Sets
Write-Host "Finding Virtual Machine Scale Sets..." -ForegroundColor Cyan
$vmss = Invoke-AzCommand -Command "az vmss list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving VM Scale Sets"
if ($vmss) {
foreach ($scaleSet in $vmss) {
$results += [PSCustomObject]@{
ResourceType = "Virtual Machine Scale Set"
ResourceName = $scaleSet.Name
ResourceGroup = $scaleSet.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "EDR, CSPM, CIEM"
}
}
}
# Get AKS Clusters
Write-Host "Finding AKS Clusters..." -ForegroundColor Cyan
$aksClusters = Invoke-AzCommand -Command "az aks list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving AKS clusters"
if ($aksClusters) {
foreach ($cluster in $aksClusters) {
$results += [PSCustomObject]@{
ResourceType = "Kubernetes"
ResourceName = $cluster.Name
ResourceGroup = $cluster.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "EDR, CSPM, CIEM, Image Assessment, Kubernetes Admission Controller"
}
}
}
# Get Storage Accounts (data stores)
Write-Host "Finding Storage Accounts..." -ForegroundColor Cyan
$storageAccounts = Invoke-AzCommand -Command "az storage account list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving storage accounts"
if ($storageAccounts) {
foreach ($storage in $storageAccounts) {
$results += [PSCustomObject]@{
ResourceType = "Storage Account"
ResourceName = $storage.Name
ResourceGroup = $storage.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, DSPM"
}
}
}
# Get SQL Servers and Databases
Write-Host "Finding SQL Databases..." -ForegroundColor Cyan
$sqlServers = Invoke-AzCommand -Command "az sql server list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving SQL servers"
if ($sqlServers) {
foreach ($server in $sqlServers) {
$databases = Invoke-AzCommand -Command "az sql db list --resource-group $($server.ResourceGroup) --server $($server.Name) --query '[].{Name:name}' -o json" -ErrorMessage "Error retrieving databases for server $($server.Name)"
if ($databases) {
foreach ($db in $databases) {
$results += [PSCustomObject]@{
ResourceType = "SQL Database"
ResourceName = "$($server.Name)/$($db.Name)"
ResourceGroup = $server.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, DSPM"
}
}
}
}
}
# Get SQL Server (as a separate resource)
if ($sqlServers) {
foreach ($server in $sqlServers) {
$results += [PSCustomObject]@{
ResourceType = "SQL Server"
ResourceName = $server.Name
ResourceGroup = $server.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get App Services
Write-Host "Finding App Services..." -ForegroundColor Cyan
$appServices = Invoke-AzCommand -Command "az webapp list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving app services"
if ($appServices) {
foreach ($app in $appServices) {
$results += [PSCustomObject]@{
ResourceType = "App Service"
ResourceName = $app.Name
ResourceGroup = $app.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, ASPM"
}
}
}
# Get Azure Functions
Write-Host "Finding Azure Functions..." -ForegroundColor Cyan
$functions = Invoke-AzCommand -Command "az functionapp list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Azure Functions"
if ($functions) {
foreach ($function in $functions) {
$results += [PSCustomObject]@{
ResourceType = "Azure Function"
ResourceName = $function.Name
ResourceGroup = $function.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, ASPM"
}
}
}
# Get Container Instances
Write-Host "Finding Container Instances..." -ForegroundColor Cyan
$containerInstances = Invoke-AzCommand -Command "az container list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving container instances"
if ($containerInstances) {
foreach ($container in $containerInstances) {
$results += [PSCustomObject]@{
ResourceType = "Container Instance"
ResourceName = $container.Name
ResourceGroup = $container.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "EDR, CSPM, Image Assessment"
}
}
}
# Get Container Registries - Updated with EDR, Image Assessment, CSPM
Write-Host "Finding Container Registries..." -ForegroundColor Cyan
$containerRegistries = Invoke-AzCommand -Command "az acr list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving container registries"
if ($containerRegistries) {
foreach ($registry in $containerRegistries) {
$results += [PSCustomObject]@{
ResourceType = "Container Registry"
ResourceName = $registry.Name
ResourceGroup = $registry.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "EDR, CSPM, Image Assessment"
}
}
}
# Get Container Apps - Added with EDR
Write-Host "Finding Container Apps..." -ForegroundColor Cyan
try {
# First check if the extension is installed
$extensionCheck = az extension show --name containerapp 2>&1
if ($extensionCheck -like "*not installed*") {
Write-Host "Container Apps extension not installed. Attempting to install..." -ForegroundColor Yellow
az extension add --name containerapp --yes 2>$null
}
# Now try to list container apps
$containerApps = Invoke-AzCommand -Command "az containerapp list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving container apps"
if ($containerApps) {
foreach ($app in $containerApps) {
$results += [PSCustomObject]@{
ResourceType = "Container Apps"
ResourceName = $app.Name
ResourceGroup = $app.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "EDR, CSPM, Image Assessment"
}
}
}
}
catch {
Write-Host "Container Apps may not be available in your environment: $_" -ForegroundColor Yellow
# Fallback to generic resource search
try {
$containerAppsGeneric = Invoke-AzCommand -Command "az resource list --resource-type Microsoft.App/containerApps --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving container apps with generic method"
if ($containerAppsGeneric) {
foreach ($app in $containerAppsGeneric) {
$results += [PSCustomObject]@{
ResourceType = "Container Apps"
ResourceName = $app.Name
ResourceGroup = $app.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "EDR, CSPM, Image Assessment"
}
}
}
}
catch {
Write-Host "Container Apps could not be detected with fallback method" -ForegroundColor Yellow
}
}
# Get Key Vaults
Write-Host "Finding Key Vaults..." -ForegroundColor Cyan
$keyVaults = Invoke-AzCommand -Command "az keyvault list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving key vaults"
if ($keyVaults) {
foreach ($vault in $keyVaults) {
$results += [PSCustomObject]@{
ResourceType = "Key Vault"
ResourceName = $vault.Name
ResourceGroup = $vault.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, CIEM"
}
}
}
# Get Cosmos DB
Write-Host "Finding Cosmos DB..." -ForegroundColor Cyan
$cosmosDBs = Invoke-AzCommand -Command "az cosmosdb list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Cosmos DB"
if ($cosmosDBs) {
foreach ($cosmosDB in $cosmosDBs) {
$results += [PSCustomObject]@{
ResourceType = "Cosmos DB"
ResourceName = $cosmosDB.Name
ResourceGroup = $cosmosDB.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, DSPM"
}
}
}
# Get Azure Firewall
Write-Host "Finding Azure Firewalls..." -ForegroundColor Cyan
$firewalls = Invoke-AzCommand -Command "az network firewall list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Azure Firewalls"
if ($firewalls) {
foreach ($firewall in $firewalls) {
$results += [PSCustomObject]@{
ResourceType = "Azure Firewall"
ResourceName = $firewall.Name
ResourceGroup = $firewall.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Network Security Groups
Write-Host "Finding Network Security Groups..." -ForegroundColor Cyan
$nsgs = Invoke-AzCommand -Command "az network nsg list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving NSGs"
if ($nsgs) {
foreach ($nsg in $nsgs) {
$results += [PSCustomObject]@{
ResourceType = "Network Security Group"
ResourceName = $nsg.Name
ResourceGroup = $nsg.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Virtual Networks
Write-Host "Finding Virtual Networks..." -ForegroundColor Cyan
$vnets = Invoke-AzCommand -Command "az network vnet list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Virtual Networks"
if ($vnets) {
foreach ($vnet in $vnets) {
$results += [PSCustomObject]@{
ResourceType = "Virtual Network"
ResourceName = $vnet.Name
ResourceGroup = $vnet.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Load Balancers
Write-Host "Finding Load Balancers..." -ForegroundColor Cyan
$lbs = Invoke-AzCommand -Command "az network lb list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Load Balancers"
if ($lbs) {
foreach ($lb in $lbs) {
$results += [PSCustomObject]@{
ResourceType = "Load Balancer"
ResourceName = $lb.Name
ResourceGroup = $lb.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Application Gateways
Write-Host "Finding Application Gateways..." -ForegroundColor Cyan
$appGateways = Invoke-AzCommand -Command "az network application-gateway list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Application Gateways"
if ($appGateways) {
foreach ($gateway in $appGateways) {
$results += [PSCustomObject]@{
ResourceType = "Application Gateway"
ResourceName = $gateway.Name
ResourceGroup = $gateway.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get PostgreSQL servers
Write-Host "Finding PostgreSQL Servers..." -ForegroundColor Cyan
$postgreSQLServers = Invoke-AzCommand -Command "az postgres server list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving PostgreSQL servers"
if ($postgreSQLServers) {
foreach ($server in $postgreSQLServers) {
$results += [PSCustomObject]@{
ResourceType = "PostgreSQL"
ResourceName = $server.Name
ResourceGroup = $server.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, DSPM"
}
}
}
# Get MySQL servers
Write-Host "Finding MySQL Servers..." -ForegroundColor Cyan
$mySQLServers = Invoke-AzCommand -Command "az mysql server list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving MySQL servers"
if ($mySQLServers) {
foreach ($server in $mySQLServers) {
$results += [PSCustomObject]@{
ResourceType = "MySQL"
ResourceName = $server.Name
ResourceGroup = $server.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, DSPM"
}
}
}
# Get MariaDB servers
Write-Host "Finding MariaDB Servers..." -ForegroundColor Cyan
$mariaDBServers = Invoke-AzCommand -Command "az mariadb server list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving MariaDB servers"
if ($mariaDBServers) {
foreach ($server in $mariaDBServers) {
$results += [PSCustomObject]@{
ResourceType = "MariaDB"
ResourceName = $server.Name
ResourceGroup = $server.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, DSPM"
}
}
}
# Get Event Hubs
Write-Host "Finding Event Hubs..." -ForegroundColor Cyan
$eventHubs = Invoke-AzCommand -Command "az eventhubs namespace list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Event Hubs"
if ($eventHubs) {
foreach ($hub in $eventHubs) {
$results += [PSCustomObject]@{
ResourceType = "Event Hub"
ResourceName = $hub.Name
ResourceGroup = $hub.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Front Door
Write-Host "Finding Front Door..." -ForegroundColor Cyan
$frontDoors = Invoke-AzCommand -Command "az network front-door list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Front Door"
if ($frontDoors) {
foreach ($fd in $frontDoors) {
$results += [PSCustomObject]@{
ResourceType = "Front Door"
ResourceName = $fd.Name
ResourceGroup = $fd.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Azure OpenAI
Write-Host "Finding Azure OpenAI Services..." -ForegroundColor Cyan
$openAIServices = Invoke-AzCommand -Command "az cognitiveservices account list --query '[?kind==''OpenAI''].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Azure OpenAI services"
if ($openAIServices) {
foreach ($service in $openAIServices) {
$results += [PSCustomObject]@{
ResourceType = "OpenAI"
ResourceName = $service.Name
ResourceGroup = $service.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Service Fabric clusters
Write-Host "Finding Service Fabric Clusters..." -ForegroundColor Cyan
$serviceFabricClusters = Invoke-AzCommand -Command "az sf cluster list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Service Fabric clusters"
if ($serviceFabricClusters) {
foreach ($cluster in $serviceFabricClusters) {
$results += [PSCustomObject]@{
ResourceType = "Service Fabric"
ResourceName = $cluster.Name
ResourceGroup = $cluster.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Synapse workspaces
Write-Host "Finding Synapse Workspaces..." -ForegroundColor Cyan
$synapseWorkspaces = Invoke-AzCommand -Command "az synapse workspace list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Synapse workspaces"
if ($synapseWorkspaces) {
foreach ($workspace in $synapseWorkspaces) {
$results += [PSCustomObject]@{
ResourceType = "Synapse"
ResourceName = $workspace.Name
ResourceGroup = $workspace.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, DSPM"
}
}
}
# Get Azure Arc servers
Write-Host "Finding Azure Arc Servers..." -ForegroundColor Cyan
$arcServers = Invoke-AzCommand -Command "az connectedmachine list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Azure Arc servers"
if ($arcServers) {
foreach ($server in $arcServers) {
$results += [PSCustomObject]@{
ResourceType = "Azure Arc"
ResourceName = $server.Name
ResourceGroup = $server.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "EDR, CSPM, CIEM"
}
}
}
# Get Azure Machine Learning workspaces
Write-Host "Finding Azure Machine Learning Workspaces..." -ForegroundColor Cyan
$mlWorkspaces = Invoke-AzCommand -Command "az ml workspace list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Machine Learning workspaces"
if ($mlWorkspaces) {
foreach ($workspace in $mlWorkspaces) {
$results += [PSCustomObject]@{
ResourceType = "Azure Machine Learning"
ResourceName = $workspace.Name
ResourceGroup = $workspace.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get CDN profiles
Write-Host "Finding CDN Profiles..." -ForegroundColor Cyan
$cdnProfiles = Invoke-AzCommand -Command "az cdn profile list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving CDN profiles"
if ($cdnProfiles) {
foreach ($profile in $cdnProfiles) {
$results += [PSCustomObject]@{
ResourceType = "CDN"
ResourceName = $profile.Name
ResourceGroup = $profile.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Defender for Cloud
Write-Host "Finding Defender for Cloud..." -ForegroundColor Cyan
try {
$defenderStatus = Invoke-AzCommand -Command "az security auto-provisioning-setting list --query '[0].{Name:name}' -o json" -ErrorMessage "Error retrieving Defender for Cloud status"
if ($defenderStatus) {
$results += [PSCustomObject]@{
ResourceType = "Defender for Cloud"
ResourceName = "Defender for Cloud"
ResourceGroup = ""
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
catch {
Write-Host "Defender for Cloud may not be configured: $_" -ForegroundColor Yellow
}
# Get Disks
Write-Host "Finding Disks..." -ForegroundColor Cyan
$disks = Invoke-AzCommand -Command "az disk list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving disks"
if ($disks) {
foreach ($disk in $disks) {
$results += [PSCustomObject]@{
ResourceType = "Disk"
ResourceName = $disk.Name
ResourceGroup = $disk.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get DNS zones
Write-Host "Finding DNS Zones..." -ForegroundColor Cyan
$dnsZones = Invoke-AzCommand -Command "az network dns zone list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving DNS zones"
if ($dnsZones) {
foreach ($zone in $dnsZones) {
$results += [PSCustomObject]@{
ResourceType = "DNS"
ResourceName = $zone.Name
ResourceGroup = $zone.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Monitor components (Log Analytics workspaces)
Write-Host "Finding Monitor Components (Log Analytics)..." -ForegroundColor Cyan
$logAnalytics = Invoke-AzCommand -Command "az monitor log-analytics workspace list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Log Analytics workspaces"
if ($logAnalytics) {
foreach ($workspace in $logAnalytics) {
$results += [PSCustomObject]@{
ResourceType = "Monitor"
ResourceName = $workspace.Name
ResourceGroup = $workspace.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Spring Cloud services
Write-Host "Finding Spring Cloud Services..." -ForegroundColor Cyan
$springCloud = Invoke-AzCommand -Command "az spring-cloud list --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving Spring Cloud services"
if ($springCloud) {
foreach ($service in $springCloud) {
$results += [PSCustomObject]@{
ResourceType = "Spring Cloud"
ResourceName = $service.Name
ResourceGroup = $service.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM"
}
}
}
# Get Identity resources (AAD Domain Services)
Write-Host "Finding AAD Domain Services..." -ForegroundColor Cyan
$aadDS = Invoke-AzCommand -Command "az resource list --resource-type Microsoft.AAD/domainServices --query '[].{Name:name, ResourceGroup:resourceGroup}' -o json" -ErrorMessage "Error retrieving AAD Domain Services"
if ($aadDS) {
foreach ($ds in $aadDS) {
$results += [PSCustomObject]@{
ResourceType = "AD Domain Services"
ResourceName = $ds.Name
ResourceGroup = $ds.ResourceGroup
Subscription = $subscription.Name
ProtectionCapabilities = "CSPM, CIEM, SSPM"
}
}
}
}
# Display results
if ($results.Count -eq 0) {
Write-Host "`nNo resources found." -ForegroundColor Yellow
}
else {
Write-Host "`nResource Protection Mapping Results:" -ForegroundColor Green
$results | Format-Table -AutoSize
# Export results to CSV
$csvPath = ".\AzureResourceProtectionMapping_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv"
$results | Export-Csv -Path $csvPath -NoTypeInformation
Write-Host "Results exported to $csvPath" -ForegroundColor Green
# Summary of protection coverage
$protectionSummary = @{
"EDR" = ($results | Where-Object { $_.ProtectionCapabilities -like "*EDR*" }).Count
"CSPM" = ($results | Where-Object { $_.ProtectionCapabilities -like "*CSPM*" }).Count
"CIEM" = ($results | Where-Object { $_.ProtectionCapabilities -like "*CIEM*" }).Count
"SSPM" = ($results | Where-Object { $_.ProtectionCapabilities -like "*SSPM*" }).Count
"ASPM" = ($results | Where-Object { $_.ProtectionCapabilities -like "*ASPM*" }).Count
"DSPM" = ($results | Where-Object { $_.ProtectionCapabilities -like "*DSPM*" }).Count
"Image Assessment" = ($results | Where-Object { $_.ProtectionCapabilities -like "*Image Assessment*" }).Count
"Kubernetes Admission Controller" = ($results | Where-Object { $_.ProtectionCapabilities -like "*Kubernetes Admission Controller*" }).Count
}
Write-Host "`nProtection Coverage Summary:" -ForegroundColor Green
$protectionSummary.GetEnumerator() | Sort-Object Name | Format-Table @{Label="Protection Type"; Expression={$_.Key}}, @{Label="Resources Covered"; Expression={$_.Value}} -AutoSize
# Resource type summary
$resourceTypeSummary = $results | Group-Object -Property ResourceType | Select-Object Name, Count | Sort-Object -Property Name
Write-Host "`nResource Type Summary:" -ForegroundColor Green
$resourceTypeSummary | Format-Table -AutoSize
}