Skip to content

Commit 9620557

Browse files
authored
Merge pull request T0pCyber#88 from T0pCyber/Development
Development
2 parents ded6477 + b80946a commit 9620557

15 files changed

+62
-27
lines changed

Hawk/Hawk.psd1

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'Hawk.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '2.0.3.2'
6+
ModuleVersion = '3.0.0'
77

88
# ID used to uniquely identify this module
99
GUID = '1f6b6b91-79c4-4edf-83a1-66d2dc8c3d85'
@@ -15,7 +15,7 @@
1515
CompanyName = 'Cloud Forensicator'
1616

1717
# Copyright statement for this module
18-
Copyright = 'Copyright (c) 2020 Paul Navarro'
18+
Copyright = 'Copyright (c) 2022 Paul Navarro'
1919

2020
# Description of the functionality provided by this module
2121
Description = 'Microsoft 365 Incident Response and Threat Hunting PowerShell tool.

Hawk/Hawk.psm1

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,33 @@ $importIndividualFiles = Get-PSFConfigValue -FullName Hawk.Import.IndividualFile
1818
if ($Hawk_importIndividualFiles) { $importIndividualFiles = $true }
1919
if (Test-Path (Resolve-PSFPath -Path "$($script:ModuleRoot)\..\.git" -SingleItem -NewChild)) { $importIndividualFiles = $true }
2020
if ("<was not compiled>" -eq '<was not compiled>') { $importIndividualFiles = $true }
21-
21+
2222
function Import-ModuleFile
2323
{
2424
<#
2525
.SYNOPSIS
2626
Loads files into the module on module import.
27-
27+
2828
.DESCRIPTION
2929
This helper function is used during module initialization.
3030
It should always be dotsourced itself, in order to proper function.
31-
31+
3232
This provides a central location to react to files being imported, if later desired
33-
33+
3434
.PARAMETER Path
3535
The path to the file to load
36-
36+
3737
.EXAMPLE
3838
PS C:\> . Import-ModuleFile -File $function.FullName
39-
39+
4040
Imports the file stored in $function according to import policy
4141
#>
4242
[CmdletBinding()]
4343
Param (
4444
[string]
4545
$Path
4646
)
47-
47+
4848
$resolvedPath = $ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($Path).ProviderPath
4949
if ($doDotSource) { . $resolvedPath }
5050
else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($resolvedPath))), $null, $null) }
@@ -57,24 +57,24 @@ if ($importIndividualFiles)
5757
foreach ($path in (& "$ModuleRoot\internal\scripts\preimport.ps1")) {
5858
. Import-ModuleFile -Path $path
5959
}
60-
60+
6161
# Import all internal functions
6262
foreach ($function in (Get-ChildItem "$ModuleRoot\internal\functions" -Filter "*.ps1" -Recurse -ErrorAction Ignore))
6363
{
6464
. Import-ModuleFile -Path $function.FullName
6565
}
66-
66+
6767
# Import all public functions
6868
foreach ($function in (Get-ChildItem "$ModuleRoot\functions" -Filter "*.ps1" -Recurse -ErrorAction Ignore))
6969
{
7070
. Import-ModuleFile -Path $function.FullName
7171
}
72-
72+
7373
# Execute Postimport actions
7474
foreach ($path in (& "$ModuleRoot\internal\scripts\postimport.ps1")) {
7575
. Import-ModuleFile -Path $path
7676
}
77-
77+
7878
# End it here, do not load compiled code below
7979
return
8080
}

Hawk/changelog.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ seeking alternate solution to retrieve Azure AD Sign-in logs.
1818
- Added dependency of Exchange Online Management V2 PowerShell module and updated functions to reflect
1919

2020
## 2.0.3.1 (2021-05-05)
21-
- Fixed MSOnline Requirement to manifest
21+
- Fixed MSOnline Requirement to manifest
22+
23+
## 3.0.0 (2022-04-09)
24+
- Updated community pull requests
25+
a. Encoding to UTF8 - Enhancement - TakayukiTomatsuri
26+
b. Updated $RangeEnd to datetime - Bug - cfc-zcarter
27+
c. Updated Sweep variable - Bug
28+
d. Added Default Tenant Name to Hawk folder name - Issue#86 - Enhancement - Snickasaurus
29+
e. Updated Get-HawkTenantEXOAdmins to accurately list admins that is a group

Hawk/functions/Tenant/Get-HawkTenantAZAdmins.ps1

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
.NOTES
1616
#>
1717
BEGIN{
18+
#Initializing Hawk Object if not present
19+
if ([string]::IsNullOrEmpty($Hawk.FilePath)) {
20+
Initialize-HawkGlobalObject
21+
}
1822
Out-LogFile "Gathering Azure AD Administrators"
1923

2024
Test-AzureADConnection

Hawk/functions/Tenant/Get-HawkTenantAppAndSPNCredentialDetails.ps1

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
.NOTES
2020
#>
2121
BEGIN{
22+
#Initializing Hawk Object if not present
23+
if ([string]::IsNullOrEmpty($Hawk.FilePath)) {
24+
Initialize-HawkGlobalObject
25+
}
2226
Test-AzureADConnection
23-
27+
2428
Out-LogFile "Collecting Azure AD Service Principals"
2529
$spns = get-azureadserviceprincipal -all $true | Sort-Object -Property DisplayName
2630
Out-LogFile "Collecting Azure AD Registered Applications"

Hawk/functions/Tenant/Get-HawkTenantAzureADUsers.ps1

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
.NOTES
1717
#>
1818
BEGIN{
19+
#Initializing Hawk Object if not present
20+
if ([string]::IsNullOrEmpty($Hawk.FilePath)) {
21+
Initialize-HawkGlobalObject
22+
}
1923
Out-LogFile "Gathering Azure AD Users"
2024

2125
Test-AzureADConnection

Hawk/functions/Tenant/Get-HawkTenantEXOAdmins.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PROCESS{
2626
if([string]::IsNullOrWhiteSpace($admin.WindowsLiveId)){
2727
[PSCustomObject]@{
2828
ExchangeAdminGroup = $Role.Name
29-
Members= $admin.name
29+
Members= $admin.DisplayName
3030
RecipientType = $admin.RecipientType
3131
}
3232
}

Hawk/functions/Tenant/Search-HawkTenantEXOAuditLog.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
}
222222

223223
if ($Output.count -gt 1) {
224-
Out-LogFile ("Found " + $Output.cout + " Users/Groups with Impersonation rights. Default is 1") -notice
224+
Out-LogFile ("Found " + $Output.count + " Users/Groups with Impersonation rights. Default is 1") -notice
225225
$Output | Out-MultipleFileType -fileprefix "Impersonation_Rights" -csv -xml
226226
$Output | Out-MultipleFileType -fileprefix "_Investigate_Impersonation_Rights" -csv -xml -Notice
227227
}

Hawk/functions/Tenant/Start-HawkTenantInvestigation.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
2020
R uns all of the tenant investigation cmdlets.
2121
#>
22+
if ([string]::IsNullOrEmpty($Hawk.FilePath)) {
23+
Initialize-HawkGlobalObject
24+
}
2225

2326
Out-LogFile "Starting Tenant Sweep" -action
2427
Send-AIEvent -Event "CmdRun"

Hawk/functions/User/Get-HawkUserInboxRule.ps1

+13-1
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,22 @@ Function Get-HawkUserInboxRule {
7070
# If we have set the Investigate flag then report it and output it to a seperate file
7171
if ($Investigate -eq $true) {
7272
Out-LogFile ("Possible Investigate inbox rule found ID:" + $Rule.Identity + " Rule:" + $Rule.Name) -notice
73+
# Description is multiline
74+
$Rule.Description = $Rule.Description.replace("`r`n", " ").replace("`t", "")
7375
$Rule | Out-MultipleFileType -FilePreFix "_Investigate_InboxRules" -user $user -csv -append -Notice
7476
}
7577
}
7678

79+
# Description is multiline
80+
$inboxrulesRawDescription = $InboxRules
81+
$InboxRules = New-Object -TypeName "System.Collections.ArrayList"
82+
83+
$inboxrulesRawDescription | ForEach-Object {
84+
$_.Description = $_.Description.Replace("`r`n", " ").replace("`t", "")
85+
86+
$null = $InboxRules.Add($_)
87+
}
88+
7789
# Output all of the inbox rules to a generic csv
7890
$InboxRules | Out-MultipleFileType -FilePreFix "InboxRules" -User $user -csv
7991

@@ -86,7 +98,7 @@ Function Get-HawkUserInboxRule {
8698
Out-LogFile ("Gathering Sweep Rules: " + $User) -action
8799
$SweepRules = Get-SweepRule -Mailbox $User
88100

89-
if ($null -eq $SweeRules) { Out-LogFile "No Sweep Rules found" }
101+
if ($null -eq $SweepRules) { Out-LogFile "No Sweep Rules found" }
90102
else {
91103

92104
# Output all rules to a user CSV

Hawk/functions/User/Get-HawkUserMailboxAuditing.ps1

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@
5252

5353
do {
5454
# Get the end of the Range we are going to gather data for
55-
[string]$RangeEnd =[datetime]::parse($RangeStart, [CultureInfo]::CreateSpecificCulture("en-US")).AddDays(5).toString("MM/dd/yyyy")
56-
57-
# Do the actual search
55+
[datetime] $RangeEnd = ($RangeStart.AddDays(5))
56+
# Do the actual search
5857
Out-LogFile ("Searching Range " + [string]$RangeStart + " To " + [string]$RangeEnd)
5958
[array]$Results += Search-MailboxAuditLog -StartDate $RangeStart -EndDate $RangeEnd -identity $User -ShowDetails -ResultSize 250000
6059

Hawk/internal/functions/Get-SimpleAdminAuditLog.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Function Get-SimpleAdminAuditLog {
2626
$SearchResults
2727
)
2828

29-
# Setup to process incomming results
29+
# Setup to process incoming results
3030
Begin {
3131

3232
# Make sure the array is null
@@ -50,7 +50,7 @@ Function Get-SimpleAdminAuditLog {
5050
if ([string]::IsNullOrEmpty($user)) { $user = "***" }
5151

5252
# if we have 'on behalf of' then we need to do some more processing to get the right value
53-
elseif ($_.caller -like "*on ehalf of*") {
53+
elseif ($_.caller -like "*on behalf of*") {
5454
$split = $_.caller.split("/")
5555
$Start = (($Split[3].split(" "))[0]).TrimEnd('"')
5656
$End = $Split[-1].trimend('"')

Hawk/internal/functions/Initialize-HawkGlobalObject.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
param([string]$RootPath)
7979

8080
# Create a folder ID based on date
81-
[string]$FolderID = "Hawk_" + (Get-Date -UFormat %Y%m%d_%H%M).tostring()
81+
[string]$TenantName = (Get-MSolDomain | Where-Object {$_.isDefault}).Name
82+
[string]$FolderID = "Hawk_" + $TenantName.Substring(0, $TenantName.IndexOf('.')) + "_" + (Get-Date -UFormat %Y%m%d_%H%M).tostring()
8283

8384
# Add that ID to the given path
8485
$FullOutputPath = Join-Path $RootPath $FolderID

Hawk/internal/functions/Out-LogFile.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Function Out-LogFile {
4848
[string]$logstring = ( "[" + $date + "] - [ACTION] - " + $string)
4949

5050
}
51-
# If notice is true the we should write this to intersting.txt as well
51+
# If notice is true the we should write this to interesting.txt as well
5252
elseif ($notice) {
5353
[string]$logstring = ( "[" + $date + "] - ## INVESTIGATE ## - " + $string)
5454

Hawk/internal/functions/Out-MultipleFileType.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ Function Out-MultipleFileType {
135135
Out-LogFile ("Appending Data to " + $filename)
136136

137137
# Write it out to csv making sture to append
138-
$AllObject | Export-Csv $filename -NoTypeInformation -Append
138+
$AllObject | Export-Csv $filename -NoTypeInformation -Append -Encoding UTF8
139139
}
140140

141141
# Otherwise overwrite
142142
else {
143143
Out-LogFile ("Writing Data to " + $filename)
144-
$AllObject | Export-Csv $filename -NoTypeInformation
144+
$AllObject | Export-Csv $filename -NoTypeInformation -Encoding UTF8
145145
}
146146

147147
# If notice is set we need to write the file name to _Investigate.txt

0 commit comments

Comments
 (0)