Azure Network Security Configuration Modified or Deleted


Description

Identifies when a network security configuration is modified or deleted. This includes Network Security Group (NSG) changes, security rule modifications, NSG joins to subnets/interfaces, and diagnostic settings changes. These actions may indicate defense evasion, persistence, or preparation for data exfiltration.

Query · python

from panther_azureactivity_helpers import azure_activity_alert_context, azure_activity_success

NSG_OPERATIONS = [
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/WRITE",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/DELETE",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/SECURITYRULES/WRITE",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/SECURITYRULES/DELETE",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/JOIN/ACTION",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/PROVIDERS/MICROSOFT.INSIGHTS/DIAGNOSTICSETTINGS/WRITE",
]


def rule(event):
    return event.get("operationName", "").upper() in NSG_OPERATIONS and azure_activity_success(
        event
    )


def title(event):
    operation = event.get("operationName", "").upper()

    # Determine action description based on operation
    if "DELETE" in operation:
        action = "deleted"
    elif "WRITE" in operation:
        action = "modified"
    elif "JOIN" in operation:
        action = "joined"
    else:
        action = "configuration changed for"

    # Determine resource type
    if "SECURITYRULES" in operation:
        resource_type = "Network Security Rule"
    elif "DIAGNOSTICSETTINGS" in operation:
        resource_type = "NSG Diagnostic Settings"
    else:
        resource_type = "Network Security Group"

    return f"Azure {resource_type} {action}"


def alert_context(event):
    return azure_activity_alert_context(event)

Analyst notes

  1. Find all network security group and firewall operations by the callerIpAddress in the 24 hours before and after this alert to identify if multiple security controls are being modified
  2. Query for all network configuration changes from the same caller in the past 7 days to determine if this is part of a broader defense evasion pattern
  3. Check if the callerIpAddress is associated with known VPNs or corporate network ranges used by authorized network administrators
Raw source Azure Network Security Configuration Modified or Deleted · Panther Python
Esc
Published by panther-labs/panther-analysis ↗, licensed under Apache 2.0 ↗. Reproduced here unmodified.
AnalysisType: rule
Filename: azure_nsg_deleted_or_modified.py
RuleID: "Azure.MonitorActivity.Network.NSGModifiedOrDeleted"
DisplayName: "Azure Network Security Configuration Modified or Deleted"
Enabled: true
LogTypes:
  - Azure.MonitorActivity
Severity: Medium
Status: Experimental
Description: >
  Identifies when a network security configuration is modified or deleted.
  This includes Network Security Group (NSG) changes, security rule modifications, NSG joins to subnets/interfaces,
  and diagnostic settings changes. These actions may indicate defense evasion, persistence, or preparation for data exfiltration.
Reports:
  MITRE ATT&CK:
    - TA0005:T1562.007 # Defense Evasion: Impair Defenses - Disable or Modify Cloud Firewall
    - TA0040:T1485 # Impact: Data Destruction
Tags:
  - AZT506
  - Defense Evasion
  - Impact
  - Impair Defenses
  - Disable or Modify Cloud Firewall
  - Data Destruction
Runbook: |
  1. Find all network security group and firewall operations by the callerIpAddress in the 24 hours before and after this alert to identify if multiple security controls are being modified
  2. Query for all network configuration changes from the same caller in the past 7 days to determine if this is part of a broader defense evasion pattern
  3. Check if the callerIpAddress is associated with known VPNs or corporate network ranges used by authorized network administrators
Reference: https://attack.mitre.org/techniques/T1562/007/
SummaryAttributes:
  - resourceId
  - callerIpAddress
  - correlationId
Tests:
  - Name: NSG Deleted Successfully
    ExpectedResult: true
    Log:
      {
        "time": "2024-12-17T10:30:00.0000000Z",
        "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkSecurityGroups/mynsg",
        "operationName": "Microsoft.Network/networkSecurityGroups/delete",
        "operationVersion": "2021-04-01",
        "category": "Administrative",
        "resultType": "Success",
        "resultSignature": "200",
        "callerIpAddress": "1.1.1.1",
        "correlationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
        "location": "",
        "tenantId": "87654321-4321-4321-4321-111111111111"
      }
  - Name: NSG Modified
    ExpectedResult: true
    Log:
      {
        "time": "2024-12-17T13:30:00.0000000Z",
        "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkSecurityGroups/mynsg",
        "operationName": "Microsoft.Network/networkSecurityGroups/write",
        "operationVersion": "2021-04-01",
        "category": "Administrative",
        "resultType": "Success",
        "callerIpAddress": "1.2.3.4",
        "correlationId": "d4e5f6a7-b8c9-0123-def0-333333333333",
        "location": "westus",
        "tenantId": "87654321-4321-4321-4321-111111111111"
      }
  - Name: Security Rule Created
    ExpectedResult: true
    Log:
      {
        "time": "2024-12-17T14:00:00.0000000Z",
        "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkSecurityGroups/mynsg/securityRules/AllowRDP",
        "operationName": "Microsoft.Network/networkSecurityGroups/securityRules/write",
        "operationVersion": "2021-04-01",
        "category": "Administrative",
        "resultType": "Success",
        "callerIpAddress": "4.4.4.4",
        "correlationId": "b2c3d4e5-f6a7-8901-bcde-f01234567890",
        "location": "westus",
        "tenantId": "87654321-4321-4321-4321-111111111111"
      }
  - Name: Security Rule Deleted
    ExpectedResult: true
    Log:
      {
        "time": "2024-12-17T14:15:00.0000000Z",
        "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkSecurityGroups/mynsg/securityRules/DenyAll",
        "operationName": "Microsoft.Network/networkSecurityGroups/securityRules/delete",
        "operationVersion": "2021-04-01",
        "category": "Administrative",
        "resultType": "Success",
        "callerIpAddress": "3.3.3.3",
        "correlationId": "c3d4e5f6-a7b8-9012-cdef-555555555555",
        "location": "eastus",
        "tenantId": "87654321-4321-4321-4321-111111111111"
      }
  - Name: NSG Join Action
    ExpectedResult: true
    Log:
      {
        "time": "2024-12-17T14:30:00.0000000Z",
        "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkSecurityGroups/mynsg",
        "operationName": "Microsoft.Network/networkSecurityGroups/join/action",
        "operationVersion": "2021-04-01",
        "category": "Administrative",
        "resultType": "Success",
        "callerIpAddress": "2.2.2.2",
        "correlationId": "d4e5f6a7-b8c9-0123-def0-444444444444",
        "location": "westus",
        "tenantId": "87654321-4321-4321-4321-111111111111"
      }
  - Name: Diagnostic Settings Modified
    ExpectedResult: true
    Log:
      {
        "time": "2024-12-17T14:45:00.0000000Z",
        "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkSecurityGroups/mynsg/providers/microsoft.insights/diagnosticSettings/default",
        "operationName": "Microsoft.Network/networkSecurityGroups/providers/microsoft.insights/diagnosticSettings/write",
        "operationVersion": "2021-04-01",
        "category": "Administrative",
        "resultType": "Success",
        "callerIpAddress": "1.1.1.1",
        "correlationId": "e5f6a7b8-c9d0-1234-ef01-333333333333",
        "location": "eastus",
        "tenantId": "87654321-4321-4321-4321-111111111111"
      }
  - Name: Case Insensitive Match
    ExpectedResult: true
    Log:
      {
        "time": "2024-12-17T11:45:00.0000000Z",
        "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/prod-rg/providers/Microsoft.Network/networkSecurityGroups/prodnsg",
        "operationName": "microsoft.network/networksecuritygroups/delete",
        "operationVersion": "2021-04-01",
        "category": "Administrative",
        "resultType": "Succeeded",
        "callerIpAddress": "1.2.3.4",
        "correlationId": "f9e8d7c6-b5a4-3210-9876-fedcba098765",
        "location": "eastus",
        "tenantId": "87654321-4321-4321-4321-111111111111"
      }
  - Name: Different Operation
    ExpectedResult: false
    Log:
      {
        "time": "2024-12-17T15:15:00.0000000Z",
        "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkSecurityGroups/mynsg",
        "operationName": "Microsoft.Network/networkSecurityGroups/read",
        "operationVersion": "2021-04-01",
        "category": "Administrative",
        "resultType": "Success",
        "callerIpAddress": "25.26.27.28",
        "correlationId": "a7b8c9d0-e1f2-3456-0123-456789012345",
        "location": "eastus",
        "tenantId": "87654321-4321-4321-4321-111111111111"
      }

# ------ paired body: azure_nsg_deleted_or_modified.py ------

from panther_azureactivity_helpers import azure_activity_alert_context, azure_activity_success

NSG_OPERATIONS = [
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/WRITE",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/DELETE",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/SECURITYRULES/WRITE",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/SECURITYRULES/DELETE",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/JOIN/ACTION",
    "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/PROVIDERS/MICROSOFT.INSIGHTS/DIAGNOSTICSETTINGS/WRITE",
]


def rule(event):
    return event.get("operationName", "").upper() in NSG_OPERATIONS and azure_activity_success(
        event
    )


def title(event):
    operation = event.get("operationName", "").upper()

    # Determine action description based on operation
    if "DELETE" in operation:
        action = "deleted"
    elif "WRITE" in operation:
        action = "modified"
    elif "JOIN" in operation:
        action = "joined"
    else:
        action = "configuration changed for"

    # Determine resource type
    if "SECURITYRULES" in operation:
        resource_type = "Network Security Rule"
    elif "DIAGNOSTICSETTINGS" in operation:
        resource_type = "NSG Diagnostic Settings"
    else:
        resource_type = "Network Security Group"

    return f"Azure {resource_type} {action}"


def alert_context(event):
    return azure_activity_alert_context(event)

Detection rules belong to the projects that publish them and remain under their own licenses. This site indexes and links to them; it claims no rights in them.