An attacker opens a database to the internet with a wide firewall rule or public network access, signs in with a stolen SQL login or account key, and reads or exports the data. A typical run on Azure adds a 0.0.0.0 to 255.255.255.255 server rule, lists Cosmos DB keys, or exports a BACPAC to a storage account the attacker controls. Save the firewall rules first, then close the database and rotate its keys and passwords.
Look here
Log
Search for
AzureActivity (Azure SQL)
Firewall, network, export, admin and auditing changes. The operations sit under Microsoft.Sql/servers: firewallRules/write, write (public network access), databases/export/action, administrators/write, auditingSettings/write and securityAlertPolicies/write. Query them: AzureActivity | where OperationNameValue has "Microsoft.Sql/servers" | project TimeGenerated, Caller, CallerIpAddress, OperationNameValue, _ResourceId
AzureActivity (Cosmos DB, PostgreSQL, MySQL)
Key and connection string listing, account changes, and firewall rules on flexible servers: AzureActivity | where OperationNameValue in~ ("Microsoft.DocumentDB/databaseAccounts/listKeys/action", "Microsoft.DocumentDB/databaseAccounts/listConnectionStrings/action", "Microsoft.DocumentDB/databaseAccounts/readonlykeys/action", "Microsoft.DocumentDB/databaseAccounts/write", "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules/write", "Microsoft.DBforMySQL/flexibleServers/firewallRules/write") | project TimeGenerated, Caller, CallerIpAddress, OperationNameValue, _ResourceId
AzureDiagnostics, category SQLSecurityAuditEvents
Rows read per client and principal. Needs server or database auditing with a Log Analytics target. The default policy audits BATCH_COMPLETED_GROUP and both authentication groups: AzureDiagnostics | where Category == "SQLSecurityAuditEvents" | summarize Batches=count(), Rows=sum(response_rows_d) by client_ip_s, server_principal_name_s, application_name_s, database_name_s | order by Rows desc
Server firewall rules now
Wide ranges, and AllowAllWindowsAzureIps, which admits resources in other customers' Azure subscriptions: az sql server firewall-rule list --resource-group <rg> --server <server>
Database firewall rules now
Rules that exist only inside each database, which only T-SQL shows. Run in each database: SELECT * FROM sys.database_firewall_rules;
CDBDataPlaneRequests
Requests and bytes per client and key type. Needs the DataPlaneRequests diagnostic category: CDBDataPlaneRequests | summarize Requests=count(), Bytes=sum(ResponseLength) by ClientIpAddress, AuthTokenType, KeyType, AadPrincipalId, DatabaseName, CollectionName | order by Bytes desc
AzureDiagnostics, MySqlAuditLogs and PostgreSQLLogs
Connections to flexible servers. MySQL audit logging is off until audit_log_enabled is ON, and PostgreSQL connections appear in PostgreSQLLogs only when the server's logging parameters record them. Query MySQL connections: AzureDiagnostics | where Category == "MySqlAuditLogs" and event_subclass_s == "CONNECT" | project TimeGenerated, Resource, user_s, ip_s, status_d
SecurityAlert
Defender for SQL alerts SQL.DB_SuspiciousIpAnomaly, SQL.DB_BruteForce, SQL.DB_GeoAnomaly and SQL.DB_PrincipalAnomaly, open-source database alerts SQL.PostgreSQL_BruteForce and SQL.MySQL_SuspiciousIpAnomaly, and Cosmos DB alerts CosmosDB_DataExfiltrationAnomaly and AzureCosmosDB_SuspiciousListKeys.SuspiciousPrincipal
Contain
#
Item
1
Save the server settings as evidence, with the firewall rule list and sys.database_firewall_rules from each database: az sql server show --name <server> --resource-group <rg> -o json
Delete the attacker's server firewall rule destructive: az sql server firewall-rule delete --resource-group <rg> --server <server> --name <rule>
4
Delete the attacker's database firewall rules destructive with T-SQL in each database: EXECUTE sp_delete_database_firewall_rule @name = N'<rule>';
5
Clear the cached firewall rules in each database: DBCC FLUSHAUTHCACHE;
6
Close public access where clients use private endpoints: az sql server update --name <server> --resource-group <rg> --set publicNetworkAccess="Disabled"
7
Reset the SQL admin password: az sql server update --name <server> --resource-group <rg> --admin-password <new>
8
Block SQL logins after the app owners agree, so only Microsoft Entra authentication works: az sql server ad-only-auth enable --name <server> --resource-group <rg>
9
Rotate Cosmos DB keys one at a time. Run the command for primary, then secondary, primaryReadonly and secondaryReadonly: az cosmosdb keys regenerate --name <account> --resource-group <rg> --key-kind primary
10
Close the Cosmos DB account to public networks. To allow named ranges, use --ip-range-filter <cidrs> in place of the network flag: az cosmosdb update --name <account> --resource-group <rg> --public-network-access DISABLED
11
Delete the attacker's rule on a PostgreSQL flexible server destructive: az postgres flexible-server firewall-rule delete --resource-group <rg> --server-name <server> --name <rule> --yes
12
Delete the attacker's rule on a MySQL flexible server destructive. This command names the server with --name and the rule with --rule-name: az mysql flexible-server firewall-rule delete --resource-group <rg> --name <server> --rule-name <rule> --yes
Eradicate and recover
#
Item
1
Find BACPAC files written to your storage accounts in the window. An export to an account outside your tenant leaves only the export/action entry: StorageBlobLogs | where OperationName in ("PutBlob", "PutBlockList") and Uri has ".bacpac"
2
Turn on server auditing to the workspace: az sql server audit-policy update --resource-group <rg> --name <server> --state Enabled --lats Enabled --lawri <workspace-id>
3
Turn on MySQL auditing, and add the MySqlAuditLogs diagnostic category: az mysql flexible-server parameter set --resource-group <rg> --server-name <server> --name audit_log_enabled --value ON
4
Move applications to Microsoft Entra authentication, then set --disable-local-auth true on Cosmos DB accounts
5
Enable the Defender for SQL, open-source relational database and Cosmos DB plans: az security pricing create -n <plan> --tier standard
6
Sum response_rows_d and ResponseLength per caller, and give the tables and databases read to the Legal advisor for notification deadlines
Watch out
Database-level firewall rules are set with T-SQL inside each database. They never appear in AzureActivity or in az sql server firewall-rule list.
Server firewall rules are cached in each database, and security setting changes take up to 5 minutes to apply. Run DBCC FLUSHAUTHCACHE after you delete a rule.
An export with SqlPackage from the attacker's machine runs as ordinary queries. It leaves no export/action entry, and only the BATCH_COMPLETED_GROUP audit rows show it.
With public network access set to Disabled, Azure SQL refuses every firewall rule change. Record and delete rules first.
Microsoft Learn: Azure SQL IP firewall rules, connectivity settings, export to a BACPAC file, resource provider operations for databases, CDBDataPlaneRequests table, Azure CLI reference for az sql, az cosmosdb, az postgres, az mysql and az security pricing. Checked October 2026. Defender for Cloud alerts for SQL Database, open-source relational databases and Cosmos DB: checked October 2026. Azure SQL auditing overview and setup, audit log format, Advanced Threat Protection, MySQL flexible server audit logs and PostgreSQL flexible server logging: checked September 2026.