Skip to content

Instantly share code, notes, and snippets.

@jonade
jonade / FindDeviceMDOSafeLinksClick.kql
Created August 18, 2025 07:49
Find Device which made MDO SafeLinks click
// Find Device which made MDO SafeLinks click
let Hosts = AlertEvidence
| where Title in ("A potentially malicious URL click was detected","A user clicked through to a potentially malicious URL​") | where EntityType == "Url"
| extend RemoteHost = parse_url(RemoteUrl).Host
| distinct tostring(RemoteHost);
DeviceEvents
| where ActionType == "BrowserLaunchedToOpenUrl"
| extend RemoteHost = tostring(parse_url(RemoteUrl).Host)
| where RemoteHost in (Hosts)
| project Timestamp, ActionType, DeviceId, DeviceName, InitiatingProcessId, InitiatingProcessCommandLine, ReportId, RemoteUrl, RemoteHost
@jonade
jonade / post-renewal.ps1
Created August 4, 2025 09:37
Let's Encrypt post-renewal script
$Thumbprint = (Get-ChildItem -Path cert:\LocalMachine\My | Where-Object {$_.Issuer -Match "Let's Encrypt"} | Sort NotBefore -Descending | Select-Object -First 1).Thumbprint
$WMIpath = (Get-WmiObject -class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices -Filter "TerminalName='RDP-tcp'").__path
Set-WmiInstance -Path $WMIpath -Arguments @{SSLCertificateSHA1Hash=$Thumbprint}
@jonade
jonade / MDO-AdvancedHunting-FalseNegativePositive.kusto
Created April 19, 2024 11:24
MDO Advanced Hunting queries - Tracking FN and FP metrics
// Blocked Phish and Malware in mailflow
let _startTime = datetime(2024-03-22T00:00:00Z);
let _endTime = datetime(2024-04-04T23:59:59Z);
EmailEvents
| where Timestamp between (_startTime .. _endTime)
| extend MDO_detection = parse_json(DetectionMethods)
| extend FirstDetection = iif(isempty(MDO_detection), "Clean", tostring(bag_keys(MDO_detection)[0]))
| extend FirstSubcategory = iif(FirstDetection != "Clean" and array_length(MDO_detection[FirstDetection]) > 0, strcat(FirstDetection, ": ", tostring(MDO_detection[FirstDetection][0])), "No Detection (clean)")
| where FirstSubcategory contains "Malware" or FirstSubcategory contains "Phish"
| summarize count(NetworkMessageId)
@jonade
jonade / MDO-AdvancedHunting-FalseNegativePositive.md
Last active April 4, 2024 12:52
MDO Advanced Hunting queries - False-Negative and False-Positive rates

// Blocked Phish and Malware in mailflow let _startTime = datetime(2024-03-21T11:22:15Z); let _endTime = datetime(2024-04-04T11:22:15Z); EmailEvents | where Timestamp between (_startTime .. _endTime) | extend MDO_detection = parse_json(DetectionMethods) | extend FirstDetection = iif(isempty(MDO_detection), "Clean", tostring(bag_keys(MDO_detection)[0])) | extend FirstSubcategory = iif(FirstDetection != "Clean" and array_length(MDO_detection[FirstDetection]) > 0, strcat(FirstDetection, ": ", tostring(MDO_detection[FirstDetection][0])), "No Detection (clean)") | where FirstSubcategory contains "Malware" or FirstSubcategory contains "Phish" | summarize count(NetworkMessageId)

@jonade
jonade / MDI-AccessToken-APIRequest.md
Last active March 4, 2024 13:34
Defender for Identity - Request MDI Access Token and make API requests

Defender for Identity - API access

Load MSAL

$ExoModule = Get-Module -Name "ExchangeOnlineManagement" -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
$MSAL = Join-Path $ExoModule.ModuleBase "NetFramework\Microsoft.Identity.Client.dll"
Try {Add-Type -LiteralPath $MSAL | Out-Null} Catch {}

Basic Token and API access

@jonade
jonade / BulkCloseFileHandles.ps1
Created September 6, 2023 11:06
Use handles.exe to bulk close file handles on folder
$handles = handle.exe "C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Authentication\2.4.0" -nobanner -v | ConvertFrom-Csv
ForEach ($handle in $handles) {
handle.exe -nobanner -c $handle.handle -p $handle.PID -y
}
@jonade
jonade / PowerShell-ConfigureMMA.ps1
Created May 15, 2023 13:03
Use PowerShell to configure Microsoft Monitoring Agent
$WorkspaceID = "<WorkspaceID>"
$WorkspaceKey = "<WorkspaceKey>"
$mma = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg'
$mma.AddCloudWorkspace($WorkspaceID, $WorkspaceKey, 1)
$mma.ReloadConfiguration()
@jonade
jonade / ExchangeOnline-MTASTS.md
Created May 12, 2022 09:51
Implementing MTA-STS for domain
@jonade
jonade / UpdateXS4ALLIPTVStaticRoute.md
Created January 3, 2022 07:32
Updating XS4ALL IPTV static routes on Unifi USG router

Configuring a Ubiquiti EdgeRouter to automatically update static route for KPN/XS4ALL IPTV platform

*https://kriegsman.io/

sudo vbash -c 'cat > /config/scripts/tvroute.sh' << EOF
#!/bin/vbash
  
# configured static route target
CUR_IP=$(cat /config/config.boot | grep 213.75.112.0/21 -A1 | grep next-hop | awk '{ print $2}');
@jonade
jonade / EXO-ODA-LogAnalyticsQueries.md
Last active February 21, 2022 09:42
Exchange Online On-Demand Assessment - Log Analytics queries

Exchange Online - On-Demand Assessment

General result queries

ExchangeOnlineAssessmentRecommendation | where RecommendationResult == "Failed"

ExchangeOnlineAssessmentRecommendation | where RecommendationResult == "Failed" | sort by TimeGenerated desc

Search for errors

Look for issues with collection, likely due to MFA