Skip to content

Commit

Permalink
Enhanced comments for deeper understanding and minor refactoring of u…
Browse files Browse the repository at this point in the history
…ser output. GeoIP Location working well.
  • Loading branch information
dcodev1702 committed Jan 19, 2025
1 parent 54cd832 commit 599f733
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Hawk/functions/User/Get-HawkUserAuthHistory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
Single UPN of a user, comma seperated list of UPNs, or array of objects that contain UPNs.
.PARAMETER ResolveIPLocations
Resolved IP Locations
If this option is specified, it will attempt to resolve IP locations (GeoIP) using ipstack.com API (API Key Required)
.OUTPUTS
File: Converted_Authentication_Logs.csv
Expand Down Expand Up @@ -100,13 +102,13 @@
}


# Add IP Geo Location information to the data
# Add Geo IP location information to the data
if ($PSBoundParameters.ContainsKey('ResolveIPLocations')) {
Out-LogFile "Resolving IP Locations" -Action
# Setup our counter
$i = 0

# Loop thru each connection and get the location
# Loop thru each connection and get the Geo IP location
while ($i -lt $ExpandedUserLogonLogs.Count) {

if ([bool]($i % 25)) { }
Expand Down
7 changes: 6 additions & 1 deletion Hawk/functions/User/Start-HawkUserInvestigation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@
}

try {
# Call Initialize-HawkGlobalObject in case of non-interactive mode
if ($PSBoundParameters.ContainsKey('EnableGeoIPLocation')) {
Initialize-HawkGlobalObject -StartDate $StartDate -EndDate $EndDate `
-DaysToLookBack $DaysToLookBack -FilePath $FilePath `
-SkipUpdate:$SkipUpdate -NonInteractive:$NonInteractive -EnableGeoIPLocation:$EnableGeoIPLocation
} else {
} else {
# Call Initialize-HawkGlobalObject in case of interactive mode for EnableGeoIPLocation
Initialize-HawkGlobalObject -StartDate $StartDate -EndDate $EndDate `
-DaysToLookBack $DaysToLookBack -FilePath $FilePath `
-SkipUpdate:$SkipUpdate -NonInteractive:$NonInteractive
Expand Down Expand Up @@ -201,6 +203,9 @@

if ($PSCmdlet.ShouldProcess("Running Get-HawkUserAuthHistory for $User")) {
Out-LogFile "Running Get-HawkUserAuthHistory" -Action
# Two different use cases (interactive and non-interactive) have to be considered here
# $Hawk.EnableGeoIPLocation is to account for interactive mode
# $PSBoundParameters.ContainsKey('EnableGeoIPLocation') is to account for non-interactive mode
if ($Hawk.EnableGeoIPLocation -or $PSBoundParameters.ContainsKey('EnableGeoIPLocation')) {
Out-LogFile "Calling Get-HawkUserAuthHistory WITH ResolveIPLocations enabled." -Information
Get-HawkUserAuthHistory -User $User -ResolveIPLocations
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/functions/Clear-HawkEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Function Clear-HawkEnvironment {
}
}

# Clear the error variable
# Clear error variables
$Error.Clear()

Write-Verbose "Hawk environment cleanup completed successfully"
Expand Down
11 changes: 6 additions & 5 deletions Hawk/internal/functions/Get-IPGeolocation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Function Get-IPGeolocation {
# if there is no value of access_key then we need to get it from the user
if ([string]::IsNullOrEmpty($HawkAppData.access_key)) {

Out-LogFile "IpStack.com now requires an API access key to gather GeoIP information from their API.`nPlease get a Free access key from https://ipstack.com/ and provide it below." -Information
Out-LogFile "IpStack.com now requires an API access key to gather GeoIP information from their API." -Information
Out-LogFile "Please get a Free access key from https://ipstack.com/ and provide it below." -Information

Out-LogFile "`nIP Stack API Key Configuration" -Action
Out-LogFile "Get your free API key at: https://ipstack.com/`n" -Action
Out-LogFile "Get your free API key at: https://ipstack.com/" -Information

# get the access key from the user
Out-LogFile "Provide your IP Stack API key: " -isPrompt -NoNewLine
Expand All @@ -47,7 +47,7 @@ Function Get-IPGeolocation {
throw "API key cannot be empty or whitespace."
}

# If testing is requested, validate the key
# Geo IP location is requested, validate the key first (using Google DNS).
if ($AccessKey) {
Out-LogFile "Testing API key against Google DNS..." -Action
$testUrl = "http://api.ipstack.com/8.8.8.8?access_key=$AccessKey"
Expand All @@ -60,7 +60,7 @@ Function Get-IPGeolocation {
}
Out-LogFile "API key validated successfully!" -Information

# Save to disk
# Save to disk (C:\Users\%USERPROFILE%\AppData\Local\Hawk\Hawk.json)
Out-HawkAppData
}
catch {
Expand All @@ -74,6 +74,7 @@ Function Get-IPGeolocation {
Add-HawkAppData -name access_key -Value $AccessKey
}
else {
# API Key is already exists from the appdata file (Hawk\Hawk.json)
$AccessKey = $HawkAppData.access_key
}
}
Expand Down

0 comments on commit 599f733

Please sign in to comment.