-
Notifications
You must be signed in to change notification settings - Fork 138
/
Get-CRTReport.ps1
2039 lines (1886 loc) · 88.7 KB
/
Get-CRTReport.ps1
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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.SYNOPSIS
Retrieves various configurations from the Azure AD/O365 tenant to provide insight during threat hunting.
.DESCRIPTION
This tool queries the following configurations in the Azure AD/O365 tenant which can shed light on hard to find permissions and configuration settings in order to assist organizations in securing these environments.
Exchange Online (O365):
- Federation Configuration
- Federation Trust
- Client Access Settings Configured on Mailboxes
- Mail Forwarding Rules for Remote Domains
- Mailbox SMTP Forwarding Rules
- Mail Transport Rules
- Delegates with 'Full Access' Permission Granted
- Delegates with Any Permissions Granted
- Delegates with 'Send As' or 'SendOnBehalf' Permissions
- Exchange Online PowerShell Enabled Users
- Users with 'Audit Bypass' Enabled
- Mailboxes Hidden from the Global Address List (GAL)
Azure AD:
- Service Principal Objects with KeyCredentials
- O365 Admin Groups Report
- Delegated Permissions & Application Permissions
Querying Tenant Partner Information:
NOTE: In order to view Tenant Partner Information, including roles assigned to your partners, you must log into the Azure Admin Portal as Global Admin:
https://admin.microsoft.com/AdminPortal/Home#/partners
.OUTPUTS
This tool will return most queries in .CSV format, and a few in .TXT format. Additionally, all JSON results will be in the 'json' subdirectory.
.PARAMETER JobName
[OPTIONAL] Use the JobName parameter to distinguish between different customer tenants. If no JobName is specified, a Date/Time formatted folder will be placed within the working directory.
.PARAMETER WorkingDirectory
[OPTIONAL] If you want to specify a different working directory for your jobs, you can do so with this parameter. The default working directory is the directory the script is being called from.
.PARAMETER Commands
[OPTIONAL] With this parameter, specify the specific commands you want to run in quotes, comma or space separated.
.PARAMETER Interactive
[OPTIONAL] Some commands may take a long time to process depending on the amount of data in the tenant. Using the Interactive parameter, you will have the option to skip any particular command prior to the module running.
.PARAMETER ExchangeEnvironmentName
[OPTIONAL] Valid options are: O365China,O365Default,O365GermanyCloud,O365USGovDoD,O365USGovGCCHigh
.PARAMETER AzureEnvironmentName
[OPTIONAL] Valid options are: AzureChinaCloud,AzureCloud,AzureGermanyCloud,AzurePPE,AzureUSGovernment
.EXAMPLE
.\Get-CRTReport.ps1
.EXAMPLE
.\Get-CRTReport.ps1 -JobName MyJobName
.EXAMPLE
.\Get-CRTReport.ps1 -WorkingDirectory 'C:\Path\to\Job'
.EXAMPLE
.\Get-CRTReport.ps1 -JobName MyJobName -WorkingDirectory 'C:\Path\to\Job'
.EXAMPLE
.\Get-CRTReport.ps1 -JobName MyJobName -WorkingDirectory 'C:\Path\to\Job' -Interactive
.EXAMPLE
.\Get-CRTReport.ps1 -JobName MyJobName -WorkingDirectory 'C:\Path\to\Job' -Commands "Command1,Command2"
.EXAMPLE
.\Get-CRTReport.ps1 -ExchangeEnvironmentName O365USGovGCCHigh -AzureEnvironmentName AzureUSGovernment
.NOTES
CrowdStrike Reporting Tool for Azure (CRT)
Written by CrowdStrike Endpoint Recovery Services
Version History:
V1.3 04/06/2023
- Fix bug where the PrimarySMTPAdress of a user may include an apostrophe(')
- Force install of version >3.1.0 of ExchangeOnline Module
V1.2, 04/07/2021
- Added additional params for users to specify AzureEnvironmentName and ExchangeEnvironmentName
- Added command for collection of Unified Audit Log Status (Get-AdminAuditLogConfig)
V1.1, 01/14/2021
- Added Mail Transport Rules query
- Fixed typos
- Added '-Encoding Default' to Export-Csv commands
- Separated Exchange online and Azure AD logons
V1.0, 12/23/2020 - Initial version
License:
Copyright (c) 2020 CrowdStrike
Copyright (c) 2020 panavarr
Copyright (c) 2017 Paul Cunningham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>
Param (
[Switch]$BasicAuth,
[String]$Commands,
[Switch]$Interactive,
[String]$JobName,
[System.IO.FileInfo]$WorkingDirectory,
[ValidateSet("O365China","O365Default","O365GermanyCloud","O365USGovDoD","O365USGovGCCHigh")][String]$ExchangeEnvironmentName,
[ValidateSet("AzureChinaCloud","AzureCloud","AzureGermanyCloud","AzurePPE","AzureUSGovernment")][String]$AzureEnvironmentName
);
#...................................
# Functions
#...................................
# Function to process results to _CRTReportSummary.txt
Function Out-Summary {
Param
(
[string]$string,
[switch]$NewReport,
[switch]$Summary
)
# Get the current date
[string]$date = [DateTime]::UtcNow.ToString((Get-Culture).DateTimeFormat.UniversalSortableDateTimePattern);
# Get _CRTReportSummary.txt file path
$SummaryFile = Join-path $LogDirectory "_CRTReportSummary.txt";
if(-not(Test-Path $SummaryFile)) {
# Create new _CRTReportSummary.txt file
[string]$ReportHeader = "##################################################################`r####### CrowdStrike Reporting Tool for Azure (CRT) Summary #######`r#################################################################`r`rReview the following findings from your query for anomalies. Refer to the investigative tips in each section for guidance.";
$ReportHeader | Out-File -FilePath $SummaryFile
};
if($NewReport) {
[string]$sumstring = ("`r### " + $string + " ###")
}
elseif ($Summary) {
[string]$sumstring = ($string)
}
else {
[string]$sumstring = ( "[" + $date + "] - " + $string)
};
# Write everything to our report summary file
if ($null -ne $sumstring) {
$sumstring | Out-File -FilePath $SummaryFile -Append
}
};
# Function to process results to output.log
Function Out-LogFile {
Param
(
[string]$string,
[switch]$warning
)
# Get our log file path
$LogFile = Join-path $LogDirectory "output.log";
$ScreenOutput = $true;
$LogOutput = $true;
# Get the current date
[string]$date = [DateTime]::UtcNow.ToString((Get-Culture).DateTimeFormat.UniversalSortableDateTimePattern);
# If -warning is set
if ($warning) {
[string]$logstring = ("[" + $date + "] - [WARNING] - " + $string);
$ScreenOutput = $false
}
# Normal output
else {
[string]$logstring = ( "[" + $date + "] - " + $string)
};
# Write everything to output.log file
if ($LogOutput) {
$logstring | Out-File -FilePath $LogFile -Append
};
# Output to the screen
if ($ScreenOutput) {
Write-Information -MessageData $logstring -InformationAction Continue
}
};
#..........................................
# Functions for AzureADPSPermissions Script
#..........................................
# Function to add an object to the cache
function CacheObject ($Object) {
if ($Object) {
if (-not $script:ObjectByObjectClassId.ContainsKey($Object.ObjectType)) {
$script:ObjectByObjectClassId[$Object.ObjectType] = @{}
}
$script:ObjectByObjectClassId[$Object.ObjectType][$Object.ObjectId] = $Object;
$script:ObjectByObjectId[$Object.ObjectId] = $Object
}
};
# Function to retrieve an object from the cache (if it's there), or from Azure AD (if not).
function GetObjectByObjectId ($ObjectId) {
if (-not $script:ObjectByObjectId.ContainsKey($ObjectId)) {
Write-Verbose ("Querying Azure AD for object '{0}'" -f $ObjectId);
try {
$object = Get-AzureADObjectByObjectId -ObjectId $ObjectId;
CacheObject -Object $object
} catch {
Write-Verbose "Object not found."
}
};
return $script:ObjectByObjectId[$ObjectId]
};
function GetOAuth2PermissionGrants ([switch]$FastMode) {
if ($FastMode) {
Get-AzureADOAuth2PermissionGrant -All $true
} else {
$script:ObjectByObjectClassId['ServicePrincipal'].GetEnumerator() | ForEach-Object { $i = 0 } {
Write-Progress -Activity "Retrieving delegated permissions..." `
-Status ("Checked {0}/{1} apps" -f $i++, $servicePrincipalCount) `
-PercentComplete (($i / $servicePrincipalCount) * 100);
$client = $_.Value;
Get-AzureADServicePrincipalOAuth2PermissionGrant -ObjectId $client.ObjectId
}
}
};
#..............................................
# Ensure -Commands includes at least one module
#..............................................
if ($Commands) {
$availableCommands = @(
"FedConfig",
"FedTrust",
"ClientAccess",
"RemoteDomains",
"SMTPForward",
"TransportRules",
"FullAccessGranted",
"AnyAccessGranted",
"SendAsGranted",
"EXOPowerShell",
"AuditBypassEnabled",
"HiddenMailboxes",
"KeyCredentials",
"O365AdminGroups",
"DelegateAppPerms",
"AdminAuditLogConfig"
);
$SplitChar = [regex]::Match($Commands,"\W").Value;
$allCommands = $Commands.Split($SplitChar);
$goodCommands = 0;
foreach ($CommandFound in $allCommands) {
if ($availableCommands.Contains($CommandFound)) {
$goodCommands += 1
}
};
if ($goodCommands -eq 0) {
Write-Host -ForegroundColor Red "No modules found to run. Be sure to specify at least one of the following:"
foreach ($availableCommand in $availableCommands) {
Write-Host -ForegroundColor Red " - $availableCommand"
};
return
}
};
#...................................
# Build Working Directory Structure
#...................................
if ($WorkingDirectory -and $JobName) {
if (-not (Test-Path -Path $WorkingDirectory)) {
New-Item -Path $WorkingDirectory -ItemType "directory" | Out-Null
};
$baseFolder = (Resolve-Path -Path $WorkingDirectory).Path;
$jobFolder = "$baseFolder\$JobName";
if (-not (Test-Path -Path $jobFolder)) {
New-Item -Path $jobFolder -ItemType "directory" | Out-Null
};
$runTime = Get-Date -Format "yyyyMMddTHHmm";
$runFolder = "$jobFolder\$runTime";
if (-not (Test-Path -Path $runFolder)) {
New-Item -Path $runFolder -ItemType "directory" | Out-Null
}
} elseif ($WorkingDirectory) {
if (-not (Test-Path -Path $WorkingDirectory)) {
New-Item -Path $WorkingDirectory -ItemType "directory" | Out-Null
};
$baseFolder = (Resolve-Path -Path $WorkingDirectory).Path;
$runTime = Get-Date -Format "yyyyMMddTHHmm";
$runFolder = "$baseFolder\$runTime";
if (-not (Test-Path -Path $runFolder)) {
New-Item -Path $runFolder -ItemType "directory" | Out-Null
}
} elseif ($JobName) {
if (-not (Test-Path -Path $JobName)) {
New-Item -Path $JobName -ItemType "directory" | Out-Null
};
$baseFolder = (Resolve-Path -Path $JobName).Path;
$runTime = Get-Date -Format "yyyyMMddTHHmm";
$runFolder = "$baseFolder\$runTime";
if (-not (Test-Path -Path $runFolder)) {
New-Item -Path $runFolder -ItemType "directory" | Out-Null
}
} else {
$baseFolder = (Get-Item -Path .).FullName;
$runTime = Get-Date -Format "yyyyMMddTHHmm";
$runFolder = "$baseFolder\$runTime";
if (-not (Test-Path -Path $runFolder)) {
New-Item -Path $runFolder -ItemType "directory" | Out-Null
}
};
if ($JobName) {
$baseFolderName = $JobName
} else {
$baseFolderName = (Get-Item -Path $baseFolder).Name
};
$Global:runFolderShort = "$baseFolderName\$((Get-Item -Path $runFolder).Name)";
$Global:reportsFolder = Join-Path -Path $runFolder -ChildPath "Reports";
if (-not (Test-Path -Path $reportsFolder)) {
New-Item -Path $reportsFolder -ItemType "directory" | Out-Null
};
$Global:jsonFolder = Join-Path -Path $reportsFolder -ChildPath "json";
if (-not (Test-Path -Path $jsonFolder)) {
New-Item -Path $jsonFolder -ItemType "directory" | Out-Null
}; # Output should be saved to the $runFolder directory.
# Set LogDirectory global variable for logging functions
$Global:LogDirectory = $runFolder;
# Check for the Azure AD and Exchange Online Management Modules, and install if not already available
Out-LogFile "Checking for PowerShell module prerequisites"
if ((Get-Module -ListAvailable -Name ExchangeOnlineManagement).Version.Major -lt 3) {
try {
Out-LogFile "Uninstalling old versions of the ExchangeOnlineManagement module (< 3.1.0)"
Uninstall-Module ExchangeOnlineManagement -AllVersions -Force -ErrorAction SilentlyContinue
Out-LogFile "Installing ExchangeOnlineManagement module";
Install-Module -Scope CurrentUser -Name ExchangeOnlineManagement -RequiredVersion 3.1.0 -Force
} catch {
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to install module ExchangeOnlineManagement."
}
};
if (-not (Get-Module -ListAvailable -Name AzureAD)) {
try {
Out-LogFile "Installing AzureAD module";
Install-Module -Scope CurrentUser -Name AzureAD -Force
} catch {
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to install module AzureAD."
}
};
#...................................
# Authentication
#...................................
# Create a login credential variable
if ($BasicAuth -and (-not $loginCreds)) {
$Global:loginCreds = Get-Credential
} elseif (-not $BasicAuth) {
Write-Host -ForegroundColor Yellow "NOTE: Using default authentication. This method will prompt you for login credentials multiple times.";
Start-Sleep -Seconds 5
};
#...................................
# Script Commands
#...................................
if ($Interactive) {
$InteractiveMessage = "Press any key to skip this module...";
$InteractiveSkipMessage = "Skipping module.";
$InteractiveContMessage = "Running module...";
$InteractiveWaitSeconds = 3
};
#............................................................................................................................................
# Exchange Online
#............................................................................................................................................
#...................................
# Authentication
#...................................
# Connect to Exchange Online
Out-LogFile "Beginning authentication";
Out-LogFile "Authenticating to Exchange Online";
try {
if ($BasicAuth) {
if($ExchangeEnvironmentName) {
Connect-ExchangeOnline -Credential $loginCreds -ExchangeEnvironmentName $ExchangeEnvironmentName -ShowBanner:$false -ErrorAction Stop 6>$null}
else {
Connect-ExchangeOnline -Credential $loginCreds -ShowBanner:$false -ErrorAction Stop 6>$null
}
} else {
if($ExchangeEnvironmentName) {
Connect-ExchangeOnline -ExchangeEnvironmentName $ExchangeEnvironmentName -ShowBanner:$false -ErrorAction Stop 6>$null
}
else {
Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop 6>$null
}
};
Out-LogFile "Successfully connected to Exchange Online"
} catch {
if($_.Exception.Message -match "you have exceeded the maximum number of connections allowed"){
try {
Disconnect-ExchangeOnline -Confirm:$false 6>$null;
Out-LogFile "Disconnected from previous Exchange Online session(s)"
} catch {
throw $_.Exception.Message
};
try {
if ($BasicAuth) {
if($ExchangeEnvironmentName) {
Connect-ExchangeOnline -Credential $loginCreds -ExchangeEnvironmentName $ExchangeEnvironmentName -ShowBanner:$false -ErrorAction Stop 6>$null
}
else {
Connect-ExchangeOnline -Credential $loginCreds -ShowBanner:$false -ErrorAction Stop 6>$null
}
}
else {
if($ExchangeEnvironmentName) {
Connect-ExchangeOnline -ExchangeEnvironmentName $ExchangeEnvironmentName -ShowBanner:$false -ErrorAction Stop 6>$null
}
else {
Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop 6>$null
}
};
Out-LogFile "Successfully connected to Exchange Online"
} catch {
throw $_.Exception.Message
}
} else {
throw $_.Exception.Message
}
};
#............................................................................................................................................
# Begin Command: FedConfig (Review Federation Configuration)
#
$moduleMessage = "Retrieving Federation configuration information";
if ($Commands -and $Commands -notmatch "FedConfig") {
$continue = $false
} elseif ($Interactive) {
Out-LogFile $moduleMessage;
$startTimer = [System.Diagnostics.Stopwatch]::StartNew();
Write-Host $InteractiveMessage;
$skip = $null;
$continue = $null;
do {
if ($startTimer.Elapsed.Seconds -gt $InteractiveWaitSeconds) {
$continue = $true;;
};
if ([Console]::KeyAvailable) {
$keyPress = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
if ($keyPress) {
$skip = $true
}
}
} while((-not $skip) -and (-not $continue))
} else {
$continue = $true
};
if ($continue) {
if (-not $Interactive) {
Out-LogFile $moduleMessage
}
if ($Interactive) {
Write-Host $InteractiveContMessage
};
try {
$FedConfig = Get-FederatedOrganizationIdentifier -IncludeExtendedDomainInfo;
if($null -ne $FedConfig) {
try {
$FedConfig | Out-File "$reportsFolder\FederationConfiguration.txt"
} catch {
Out-LogFile "Unable to write 'FederationConfiguration.txt' to disk" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to write 'FederationConfiguration.txt' to disk"
};
try {
$FedConfig | ConvertTo-Json -Depth 10 | Out-File "$jsonFolder\FederationConfiguration.json"
} catch {
Out-LogFile "Unable to write 'FederationConfiguration.json' to disk" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to write 'FederationConfiguration.json' to disk"
};
try {
Out-LogFile "[+] Review Federation configuration. Output saved to '$runFolderShort\Reports\FederationConfiguration.txt'";
Out-Summary "Federation Configuration" -NewReport;
Out-Summary "[+] Review Federation configuration. Output saved to '$runFolderShort\Reports\FederationConfiguration.txt'";
Out-Summary "`rINVESTIGATIVE TIPS:
- Review existing Federations. Identify unauthorized or unrecognized Federations then revoke them.
- Threat actors can create unauthorized federations and use them to log into your tenant and perform actions. The user accounts used to do this will not appear in your directory, thereby allowing the threat actor to persist longer.
- NOTE: This is a known SUNBURST TTP." -Summary
} catch {
Out-LogFile "There was a problem logging the Federation Configuration query" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] There was a problem logging the Federation Configuration query"
}
}
} catch {
Out-LogFile "Unable to retrieve Federation configuration. Check user permissions" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to retrieve Federation configuration. Check user permissions"
};
# End Module Run
} else {
if ($Interactive) {
Write-Host $InteractiveSkipMessage
}
};
#
# End Command: FedConfig
#............................................................................................................................................
#............................................................................................................................................
# Begin Command: FedTrust (Review Federation Trust Information)
#
$moduleMessage = "Retrieving Federation trust information"
if ($Commands -and $Commands -notmatch "FedTrust") {
$continue = $false
} elseif ($Interactive) {
Out-LogFile $moduleMessage;
$startTimer = [System.Diagnostics.Stopwatch]::StartNew();
Write-Host $InteractiveMessage;
$skip = $null;
$continue = $null;
do {
if ($startTimer.Elapsed.Seconds -gt $InteractiveWaitSeconds) {
$continue = $true
}
if ([Console]::KeyAvailable) {
$keyPress = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
if ($keyPress) {
$skip = $true
}
}
} while((-not $skip) -and (-not $continue))
} else {
$continue = $true
};
if ($continue) {
if (-not $Interactive) {
Out-LogFile $moduleMessage
}
if ($Interactive) {
Write-Host $InteractiveContMessage
};
try {
$FedTrust = Get-FederationTrust;
if($null -ne $FedTrust) {
try {
$FedTrust | Format-List | Out-File "$reportsFolder\FederationTrust.txt";
$FedTrust | ConvertTo-Json | Out-File "$jsonFolder\FederationTrust.json"
} catch {
Out-LogFile "Unable to write output to disk" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to write output to disk"
};
try {
Out-LogFile "[+] Review Federation Trust information. Output saved to '$runFolderShort\Reports\FederationTrust.txt'";
Out-Summary "Federation Trust Information" -NewReport;
Out-Summary "[+] Review Federation Trust. Output saved to '$runFolderShort\Reports\FederationTrust.txt'";
Out-Summary "`rINVESTIGATIVE TIPS:
- Review the certificates for the trust. Investigate any recent changes based on date and ensure they are authorized & expected." -Summary
} catch {
Out-LogFile "There was a problem logging this query" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] There was a problem logging this query"
}
}
} catch {
Out-LogFile "Unable to retrieve Federation trust information" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to retrieve Federation trust information"
};
} else {
if ($Interactive) {
Write-Host $InteractiveSkipMessage
}
};
#
# End Command: FedTrust
#............................................................................................................................................
#............................................................................................................................................
# Begin Command: ClientAccess (Client Access Settings Configured on Mailboxes)
#
$moduleMessage = "Retrieving Client Access Settings Configured on Mailboxes";
if ($Commands -and $Commands -notmatch "ClientAccess") {
$continue = $false
} elseif ($Interactive) {
Out-LogFile $moduleMessage;
$startTimer = [System.Diagnostics.Stopwatch]::StartNew();
Write-Host $InteractiveMessage;
$skip = $null;
$continue = $null;
do {
if ($startTimer.Elapsed.Seconds -gt $InteractiveWaitSeconds) {
$continue = $true
}
if ([Console]::KeyAvailable) {
$keyPress = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
if ($keyPress) {
$skip = $true
}
}
} while((-not $skip) -and (-not $continue))
} else {
$continue = $true
};
if ($continue) {
if (-not $Interactive) {
Out-LogFile $moduleMessage
}
if ($Interactive) {
Write-Host $InteractiveContMessage
};
$ClientAccessSettings = $null;
try {
[array]$ClientAccessSettings = Get-EXOCASMailbox -ResultSize Unlimited;
if($ClientAccessSettings.Count -gt 0) {
try {
$ClientAccessSettings | Export-Csv "$reportsFolder\ClientAccessSettingsMailboxes.csv" -NoTypeInformation -Encoding Default;
$ClientAccessSettings | ConvertTo-Json -Depth 10 | Out-File "$jsonFolder\ClientAccessSettingsMailboxes.json"
} catch {
Out-LogFile "Unable to write output to disk" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to write output to disk"
};
try {
Out-LogFile ("[+] Found " + $ClientAccessSettings.count + " Client Access Settings on Mailboxes");
Out-LogFile "[+] Review Client Access Settings Configured on Mailboxes. Output saved to '$runFolderShort\Reports\ClientAccessSettingsMailboxes.csv'";
Out-Summary "Client Access Settings Configured on Mailboxes" -NewReport;
Out-Summary ("[+] Found " + $ClientAccessSettings.count + " Client Access Settings on Mailboxes");
Out-Summary "[+] Review Client Access Settings Configured on Mailboxes. Output saved to '$runFolderShort\Reports\ClientAccessSettingsMailboxes.csv'";
Out-Summary "`rINVESTIGATIVE TIPS:
- Review for any legacy protocols being used (SMTP, IMAP, ActiveSync, POP, etc.).
- Legacy protocols can be used to access sensitive data without using MFA.
- Risk for being used for testing password stuffing attacks which can later be used to try to log into VPNs without MFA." -Summary
} catch {
Out-LogFile "There was a problem logging this query" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] There was a problem logging this query"
}
}
} catch {
Out-LogFile "Unable to retrieve Client Access Settings Configured on Mailboxes" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to retrieve Client Access Settings Configured on Mailboxes"
};
} else {
if ($Interactive) {
Write-Host $InteractiveSkipMessage
}
};
#
# End Command: ClientAccess
#............................................................................................................................................
#............................................................................................................................................
# Begin Command: RemoteDomains (Mail Forwarding Rules for Remote Domains)
#
$moduleMessage = "Retrieving Mail Forwarding Rules for Remote Domains";
if ($Commands -and $Commands -notmatch "RemoteDomains") {
$continue = $false
} elseif ($Interactive) {
Out-LogFile $moduleMessage;
$startTimer = [System.Diagnostics.Stopwatch]::StartNew();
Write-Host $InteractiveMessage;
$skip = $null;
$continue = $null;
do {
if ($startTimer.Elapsed.Seconds -gt $InteractiveWaitSeconds) {
$continue = $true
}
if ([Console]::KeyAvailable) {
$keyPress = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
if ($keyPress) {
$skip = $true
}
}
} while((-not $skip) -and (-not $continue))
} else {
$continue = $true
};
if ($continue) {
if (-not $Interactive) {
Out-LogFile $moduleMessage
}
if ($Interactive) {
Write-Host $InteractiveContMessage
};
$RemoteDomains = $null;
try {
[array]$RemoteDomains = Get-RemoteDomain | Select-Object Name,DomainName,AllowedOOFType,AutoForwardEnabled;
if($RemoteDomains.Count -gt 0) {
try {
$RemoteDomains | Export-Csv "$reportsFolder\RemoteDomainNames.csv" -NoTypeInformation -Encoding Default;
$RemoteDomains | ConvertTo-Json -Depth 10 | Out-File "$jsonFolder\RemoteDomainNames.json"
} catch {
Out-LogFile "Unable to write output to disk" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to write output to disk"
};
try {
Out-LogFile ("[+] Found " + $RemoteDomains.count + " Remote Domain(s)");
Out-LogFile "[+] Review Mail Forwarding Rules for Remote Domains. Output saved to '$runFolderShort\Reports\RemoteDomainNames.csv'";
Out-Summary "Mail Forwarding Rules for Remote Domains" -NewReport;
Out-Summary ("[+] Found " + $RemoteDomains.count + " Remote Domain(s)");
Out-Summary "[+] Review Mail Forwarding Rules for Remote Domains. Output saved to '$runFolderShort\Reports\RemoteDomainNames.csv'";
Out-Summary "`rINVESTIGATIVE TIPS:
- Look for any domain names that are suspicious in nature.
- Threat Actors can add forwarding rules to send messages to mailboxes they control.
- Ability to forward to remote domains should be either disabled or restricted.
- The default setting when remote forwarding is enabled is a wildcard (“*”) but domains list should be limited to trusted & approved email domains, such as for subsidiaries/parent organizations and contractor staff.
- Retrieving hidden rules is outside of this tool's scope." -Summary
} catch {
Out-LogFile "There was a problem logging this query" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] There was a problem logging this query"
}
}
} catch {
Out-LogFile "Unable to retrieve Mail Forwarding Rules for Remote Domains" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to retrieve Mail Forwarding Rules for Remote Domains"
};
} else {
if ($Interactive) {
Write-Host $InteractiveSkipMessage
}
};
#
# End Command: RemoteDomains
#............................................................................................................................................
#............................................................................................................................................
# Begin Command: SMTPForward (Mailbox SMTP forwarding for All Mailboxes)
#
$moduleMessage = "Retrieving Mailbox SMTP forwarding rules for all mailboxes";
if ($Commands -and $Commands -notmatch "SMTPForward") {
$continue = $false
} elseif ($Interactive) {
Out-LogFile $moduleMessage;
$startTimer = [System.Diagnostics.Stopwatch]::StartNew();
Write-Host $InteractiveMessage;
$skip = $null;
$continue = $null;
do {
if ($startTimer.Elapsed.Seconds -gt $InteractiveWaitSeconds) {
$continue = $true
}
if ([Console]::KeyAvailable) {
$keyPress = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
if ($keyPress) {
$skip = $true
}
}
} while((-not $skip) -and (-not $continue))
} else {
$continue = $true
};
if ($continue) {
if (-not $Interactive) {
Out-LogFile $moduleMessage
}
if ($Interactive) {
Write-Host $InteractiveContMessage
};
$SMTPForward = $null;
try {
[array]$SMTPForward = Get-EXOMailbox -PropertySets Minimum,Delivery -ResultSize Unlimited | Where-Object {($_.ForwardingAddress -ne $null -or $_.ForwardingSMTPAddress -ne $null)} | Select-Object Name,ForwardingAddress,ForwardingSMTPAddress,DeliverToMailboxAndForward;
if($SMTPForward.Count -gt 0) {
try {
$SMTPForward | Export-Csv "$reportsFolder\MailForwardingRules.csv" -NoTypeInformation -Encoding Default;
$SMTPForward | ConvertTo-Json -Depth 10 | Out-File "$jsonFolder\MailForwardingRules.json"
} catch {
Out-LogFile "Unable to write output to disk" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to write output to disk"
};
try {
Out-LogFile ("[+] Found " + $SMTPForward.count + " Mailbox SMTP forwarding rule(s)");
Out-LogFile "[+] Review Mailbox SMTP forwarding rules for all mailboxes. Output saved to '$runFolderShort\Reports\MailForwardingRules.csv'";
Out-Summary "Mailbox SMTP Forwarding Rules" -NewReport;
Out-Summary ("[+] Found " + $SMTPForward.count + " Mailbox SMTP forwarding rule(s)");
Out-Summary "[+] Review Mailbox SMTP forwarding rules for all mailboxes. Output saved to '$runFolderShort\Reports\MailForwardingRules.csv'";
Out-Summary "`rINVESTIGATIVE TIPS:
- Review all forwarding addresses for each mailbox and verify they are legitimate and approved.
" -Summary
} catch {
Out-LogFile "There was a problem logging this query" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] There was a problem logging this query"
}
}
} catch {
Out-LogFile "Unable to retrieve Mailbox SMTP forwarding rules for all mailboxes" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to retrieve Mailbox SMTP forwarding rules for all mailboxes"
};
} else {
if ($Interactive) {
Write-Host $InteractiveSkipMessage
}
};
#
# End Command: SMTPForward
#............................................................................................................................................
#............................................................................................................................................
# Begin Command: TransportRules (Mail Transport Rules)
#
$moduleMessage = "Retrieving Mail Transport Rules";
if ($Commands -and $Commands -notmatch "TransportRules") {
$continue = $false
} elseif ($Interactive) {
Out-LogFile $moduleMessage;
$startTimer = [System.Diagnostics.Stopwatch]::StartNew();
Write-Host $InteractiveMessage;
$skip = $null;
$continue = $null;
do {
if ($startTimer.Elapsed.Seconds -gt $InteractiveWaitSeconds) {
$continue = $true
}
if ([Console]::KeyAvailable) {
$keyPress = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
if ($keyPress) {
$skip = $true
}
}
} while((-not $skip) -and (-not $continue))
} else {
$continue = $true
};
if ($continue) {
if (-not $Interactive) {
Out-LogFile $moduleMessage
}
if ($Interactive) {
Write-Host $InteractiveContMessage
};
$TransportRules = $null;
try {
[array]$TransportRules = Get-TransportRule -ResultSize Unlimited;
if($TransportRules.Count -gt 0) {
try {
$TransportRules | Select-Object Name,IsValid,WhenChanged,LastModifiedBy,ActivationDate,ExpiryDate,Mode,State,Actions | Export-Csv "$reportsFolder\MailTransportRules.csv" -NoTypeInformation -Encoding Default;
$TransportRules | ConvertTo-Json -Depth 10 | Out-File "$jsonFolder\MailTransportRules.json"
} catch {
Out-LogFile "Unable to write output to disk" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to write output to disk"
};
try {
Out-LogFile ("[+] Found " + $TransportRules.count + " transport rule(s)");
Out-LogFile "[+] Review all Transport Rules. Output saved to '$runFolderShort\Reports\MailTransportRules.csv'";
Out-Summary "Transport Rules" -NewReport;
Out-Summary ("[+] Found " + $TransportRules.count + " transport rule(s)");
Out-Summary "[+] Review all Transport Rules. Output saved to '$runFolderShort\Reports\MailTransportRules.csv'";
Out-Summary "`rINVESTIGATIVE TIPS:
- Review all forwarding addresses for each transport rule and verify they are legitimate and approved.
" -Summary
} catch {
Out-LogFile "There was a problem logging this query" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] There was a problem logging this query"
}
}
} catch {
Out-LogFile "Unable to retrieve Mail Transport Rules" -warning;
Write-Error $_.Exception.Message;
Write-Host -ForegroundColor Red "[!] Unable to retrieve Mail Transport Rules"
};
} else {
if ($Interactive) {
Write-Host $InteractiveSkipMessage
}
};
#
# End Command: TransportRules
#............................................................................................................................................
#............................................................................................................................................
# Begin Command: FullAccessGranted (Mailbox Delegates where "Full Access" Permission is Granted)
#
$moduleMessage = "Retrieving Mailbox Delegates where 'Full Access' permission is granted";
if ($Commands -and $Commands -notmatch "FullAccessGranted") {
$continue = $false
} elseif ($Interactive) {
Out-LogFile $moduleMessage;
$startTimer = [System.Diagnostics.Stopwatch]::StartNew();
Write-Host $InteractiveMessage;
$skip = $null;
$continue = $null;
do {
if ($startTimer.Elapsed.Seconds -gt $InteractiveWaitSeconds) {
$continue = $true
}
if ([Console]::KeyAvailable) {
$keyPress = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
if ($keyPress) {
$skip = $true
}
}
} while((-not $skip) -and (-not $continue))
} else {
$continue = $true
};
if ($continue) {
if (-not $Interactive) {
Out-LogFile $moduleMessage
}
if ($Interactive) {
Write-Host $InteractiveContMessage
};
Write-Host -ForegroundColor Yellow "This make take awhile; please be patient...";
$FullAccessPerms = @();
$FullAccessPermsResults = @();
try {
$FullAccessPerms += Get-EXOMailbox -ResultSize Unlimited -ErrorAction SilentlyContinue | foreach {$_.PrimarySmtpAddress.Replace("'","")}| Get-EXOMailboxPermission -ErrorAction Stop | Where-Object { ($_.AccessRights -eq "FullAccess") -and ($_.IsInherited -eq $false) -and -not ($_.User -like "NT AUTHORITY\SELF")}
} catch {
if($_.Exception.Message -match "Cannot validate argument on parameter"){
try {
$incompleteRun = $true;
Out-LogFile "We ran into an error retrieving Mailbox Delegates where 'FullAccess' permission is granted. If a report is generated, it may not be complete." -warning;
Write-Host -ForegroundColor Red "[!] We ran into an error retrieving Mailbox Delegates where 'FullAccess' permission is granted. If a report is generated, it may not be complete.";
Write-Host -ForegroundColor Yellow "Try using the following command to obtain this report manually:"
Write-Host -ForegroundColor Yellow 'Get-EXOMailbox -ResultSize Unlimited | Get-EXOMailboxPermission | Where-Object { ($_.AccessRights -eq "FullAccess") -and ($_.IsInherited -eq $false) -and -not ($_.User -like "NT AUTHORITY\SELF")} | Export-Csv "FullAccessPerms.csv" -NoTypeInformation -Encoding Default'
} catch {
Write-Error $_.Exception.Message
}
} else {
throw $_.Exception.Message
}
};
if($FullAccessPerms.Count -gt 0) {
foreach ($obj in $FullAccessPerms){
$ObjectProperties = [Ordered]@{
Identity = $obj | Select-Object -exp Identity
User = $obj | Select-Object -exp User
AccessRights = $obj | Select-Object -exp AccessRights
IsInherited = $obj | Select-Object -exp IsInherited
Deny = $obj | Select-Object -exp Deny
InheritanceType = $obj | Select-Object -exp InheritanceType
};
$FullAccessPermsResults += New-Object -TypeName PSObject -Property $ObjectProperties
};
try {