Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/public/Convert-SentinelARYamlToArm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions tests/Convert-SentinelARYamlToArm.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ param(
[String]
$exampleIncidentConfigurationMissingFilePath = "./tests/examples/IncidentConfigurationMissing.yaml",
[Parameter()]
[String]
$exampleScheduledWithAlertDetailsOverrideFilePath = "./tests/examples/ScheduledWithAlertDetailsOverride.yaml",
[Parameter()]
[Switch]
$RetainTestFiles = $false
)
Expand Down Expand Up @@ -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 {
Expand Down
41 changes: 41 additions & 0 deletions tests/examples/ScheduledWithAlertDetailsOverride.yaml
Original file line number Diff line number Diff line change
@@ -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