From 27df23a6821924b87553f667f1d06e2072ee74a1 Mon Sep 17 00:00:00 2001 From: Fabian Bader Date: Tue, 24 Feb 2026 11:32:13 +0100 Subject: [PATCH] feat: Use `NamePrefix` parameter to also prefix `alertDisplayNameFormat` in `alertDetailsOverride` if present --- README.md | 1 + src/public/Convert-SentinelARYamlToArm.ps1 | 4 ++ tests/Convert-SentinelARYamlToArm.tests.ps1 | 60 +++++++++++++++++++ .../ScheduledWithAlertDetailsOverride.yaml | 41 +++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 tests/examples/ScheduledWithAlertDetailsOverride.yaml diff --git a/README.md b/README.md index 269fa8a..b11ff91 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,7 @@ Notice that: ### 2.5.0 * FEATURE: Add support for default values in variable replacement syntax `%%VARIABLENAME:DefaultValue%%` * FEATURE: Warn about variables without default values and no parameter file provided + * FEATURE: Use `NamePrefix` parameter to also prefix `alertDisplayNameFormat` in `alertDetailsOverride` if present ### 2.4.4 * FIX: Duplicated MITRE subTechniques in rare cases diff --git a/src/public/Convert-SentinelARYamlToArm.ps1 b/src/public/Convert-SentinelARYamlToArm.ps1 index d7a8650..3f71150 100644 --- a/src/public/Convert-SentinelARYamlToArm.ps1 +++ b/src/public/Convert-SentinelARYamlToArm.ps1 @@ -267,6 +267,10 @@ function Convert-SentinelARYamlToArm { # Add prefix to name if specified if ($NamePrefix) { $analyticRule.name = $NamePrefix + $analyticRule.name + # Also prefix alertDisplayNameFormat in alertDetailsOverride if present + if ($analyticRule.alertDetailsOverride -and $analyticRule.alertDetailsOverride.alertDisplayNameFormat) { + $analyticRule.alertDetailsOverride.alertDisplayNameFormat = $NamePrefix + $analyticRule.alertDetailsOverride.alertDisplayNameFormat + } } # Overwrite severity with custom severity diff --git a/tests/Convert-SentinelARYamlToArm.tests.ps1 b/tests/Convert-SentinelARYamlToArm.tests.ps1 index 18f4b8a..a43ae8c 100644 --- a/tests/Convert-SentinelARYamlToArm.tests.ps1 +++ b/tests/Convert-SentinelARYamlToArm.tests.ps1 @@ -21,6 +21,9 @@ param( [String] $exampleIncidentConfigurationMissingFilePath = "./tests/examples/IncidentConfigurationMissing.yaml", [Parameter()] + [String] + $exampleScheduledWithAlertDetailsOverrideFilePath = "./tests/examples/ScheduledWithAlertDetailsOverride.yaml", + [Parameter()] [Switch] $RetainTestFiles = $false ) @@ -261,6 +264,63 @@ Describe "Convert-SentinelARYamlToArm" { It "Should have the prefix at the start of the displayname" { $armTemplate.resources[0].properties.displayName | Should -Be "TestPrefix Azure WAF matching for Log4j vuln(CVE-2021-44228)" } + + It "Should not fail when alertDetailsOverride is not present" { + $armTemplate.resources[0].properties.alertDetailsOverride | Should -BeNullOrEmpty + } + } + + Context "Scheduled with parameter NamePrefix and alertDetailsOverride" -Tag Integration { + BeforeAll { + Copy-Item -Path $exampleScheduledWithAlertDetailsOverrideFilePath -Destination "TestDrive:/ScheduledWithAlertDetailsOverride.yaml" -Force + $NamePrefix = "TestPrefix " + Convert-SentinelARYamlToArm -Filename "TestDrive:/ScheduledWithAlertDetailsOverride.yaml" -OutFile "TestDrive:/ScheduledWithAlertDetailsOverride.json" -NamePrefix $NamePrefix + $armTemplate = Get-Content -Path "TestDrive:/ScheduledWithAlertDetailsOverride.json" -Raw | ConvertFrom-Json + } + + AfterEach { + if ( -not $RetainTestFiles) { + Remove-Item -Path "TestDrive:/*" -Include *.json -Force + } + } + + It "Should have the prefix at the start of the displayName" { + $armTemplate.resources[0].properties.displayName | Should -Be "TestPrefix Azure WAF matching for Log4j vuln(CVE-2021-44228)" + } + + It "Should have the prefix at the start of the alertDisplayNameFormat" { + $armTemplate.resources[0].properties.alertDetailsOverride.alertDisplayNameFormat | Should -Be "TestPrefix WAF Alert - {{MaliciousCommand}}" + } + + It "Should have the prefix at the start of the alertDisplayNameFormat" { + $armTemplate.resources[0].properties.alertDetailsOverride.alertDisplayNameFormat | Should -Match "^TestPrefix " + } + + It "Should not modify alertDescriptionFormat" { + $armTemplate.resources[0].properties.alertDetailsOverride.alertDescriptionFormat | Should -Be "A WAF rule was triggered by {{MaliciousHost}}" + } + } + + Context "Scheduled without NamePrefix and with alertDetailsOverride" -Tag Integration { + BeforeAll { + Copy-Item -Path $exampleScheduledWithAlertDetailsOverrideFilePath -Destination "TestDrive:/ScheduledWithAlertDetailsOverride.yaml" -Force + Convert-SentinelARYamlToArm -Filename "TestDrive:/ScheduledWithAlertDetailsOverride.yaml" -OutFile "TestDrive:/ScheduledWithAlertDetailsOverride.json" + $armTemplate = Get-Content -Path "TestDrive:/ScheduledWithAlertDetailsOverride.json" -Raw | ConvertFrom-Json + } + + AfterEach { + if ( -not $RetainTestFiles) { + Remove-Item -Path "TestDrive:/*" -Include *.json -Force + } + } + + It "Should not modify alertDisplayNameFormat when NamePrefix is not set" { + $armTemplate.resources[0].properties.alertDetailsOverride.alertDisplayNameFormat | Should -Be "WAF Alert - {{MaliciousCommand}}" + } + + It "Should not modify alertDescriptionFormat when NamePrefix is not set" { + $armTemplate.resources[0].properties.alertDetailsOverride.alertDescriptionFormat | Should -Be "A WAF rule was triggered by {{MaliciousHost}}" + } } Context "Scheduled with parameter Severity" -Tag Integration { diff --git a/tests/examples/ScheduledWithAlertDetailsOverride.yaml b/tests/examples/ScheduledWithAlertDetailsOverride.yaml new file mode 100644 index 0000000..68c0dae --- /dev/null +++ b/tests/examples/ScheduledWithAlertDetailsOverride.yaml @@ -0,0 +1,41 @@ +id: 6bb8e22c-4a5f-4d27-8a26-b60a7952d5af +name: Azure WAF matching for Log4j vuln(CVE-2021-44228) +kind: Scheduled +description: |- + This query will alert on a positive pattern match by Azure WAF for CVE-2021-44228 log4j vulnerability exploitation attempt. If possible, it then decodes the malicious command for further analysis. + Refrence: https://www.microsoft.com/security/blog/2021/12/11/guidance-for-preventing-detecting-and-hunting-for-cve-2021-44228-log4j-2-exploitation/ +severity: High +queryFrequency: 6h +queryPeriod: 6h +triggerOperator: gt +triggerThreshold: 0 +tactics: + - InitialAccess +query: "AzureDiagnostics\n| where ResourceProvider == \"MICROSOFT.NETWORK\" and Category in (\"ApplicationGatewayFirewallLog\", \"FrontdoorWebApplicationFirewallLog\")\n| extend details_data_s = column_ifexists(\"details_data_s\", tostring(AdditionalFields.details_data))\n| where details_data_s has \"jndi:\"\n| parse details_data_s with * '${' MaliciousCommand '} ' *\n| extend EncodeCmd = iff(MaliciousCommand has 'Base64/', split(split(MaliciousCommand, \"Base64/\",1)[0], \"}\", 0)[0], \"\")\n| extend EncodeCmd1 = iff(MaliciousCommand has 'base64/', split(split(MaliciousCommand, \"base64/\",1)[0], \"}\", 0)[0], \"\")\n| extend CmdLine = iff( isnotempty(EncodeCmd), EncodeCmd, EncodeCmd1)\n| extend DecodedCmdLine = base64_decode_tostring(tostring(CmdLine))\n| extend DecodedCmdLine = iff( isnotempty(DecodedCmdLine), DecodedCmdLine, \"Unable to decode/Doesn't need decoding\")\n| project TimeGenerated, Target=column_ifexists(\"hostname_s\", tostring(AdditionalFields.hostname)), MaliciousHost = column_ifexists(\"clientIp_s\", tostring(AdditionalFields.clientIp)) , MaliciousCommand, details_data_s = column_ifexists(\"details_data_s\", tostring(AdditionalFields.details_data)), DecodedCmdLine, Message,\nruleSetType_s = column_ifexists(\"ruleSetType_s\", tostring(AdditionalFields.ruleSetType)), OperationName, SubscriptionId, details_message_s = column_ifexists(\"details_message_s\", tostring(AdditionalFields.details_message)), \ndetails_file_s = column_ifexists(\"details_message_s\", tostring(AdditionalFields.details_file))\n| extend IPCustomEntity = MaliciousHost, timestamp = TimeGenerated" +suppressionEnabled: false +incidentConfiguration: + createIncident: true + groupingConfiguration: + enabled: false + reopenClosedIncident: false + lookbackDuration: 5h + matchingMethod: AllEntities + groupByEntities: + - Account + - IP + - Host + - URL + - FileHash + groupByAlertDetails: + groupByCustomDetails: +eventGroupingSettings: + aggregationKind: SingleAlert +alertDetailsOverride: + alertDisplayNameFormat: "WAF Alert - {{MaliciousCommand}}" + alertDescriptionFormat: "A WAF rule was triggered by {{MaliciousHost}}" +entityMappings: + - entityType: IP + fieldMappings: + - identifier: Address + columnName: IPCustomEntity +suppressionDuration: 1h