01 Run network nsg list command (Windows/macOS/Linux) using custom query filters to list the names of all network security groups (and the name of their associated resource groups) available in the current Azure subscription:
az network nsg list
--output table
--query '[*].{name:name, resourceGroup:resourceGroup}'
02 The command output should return a table with requested information:
Name ResourceGroup
------------------------ ------------------------------
cc-production-server-nsg cloud-shell-storage-westeurope
cc-staging-app-server-nsg cloud-shell-storage-westeurope
03 Run network nsg rule list command (Windows/macOS/Linux) using the name of the Azure network security group (NSG) that you want to examine and its associated resource group as identifier parameters. The below command includes an example query string to identify all the inbound access rules:
az network nsg rule list
--nsg-name cc-production-server-nsg
--resource-group cloud-shell-storage-westeurope
--query "[?direction=='Inbound' && access=='Allow' && (protocol=='TCP' || protocol=='*')]"
04 The command output should return the requested security group rule metadata or an empty array, i.e. [], if there are no inbound access rules:
[
{
"access": "Allow",
"description": null,
"destinationAddressPrefix": "*",
"destinationAddressPrefixes": [],
"destinationApplicationSecurityGroups": null,
"destinationPortRange": "443"
,
"destinationPortRanges": []
,
"direction": "Inbound",
"etag": "W/\"abcdabcd-abcd-abcd-abcd-abcdabcdabcd\"",
"id": "/subscriptions/abcd1234-abcd-1234-abcd-1234abcd1234/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.Network/networkSecurityGroups/cc-production-server-nsg/securityRules/selectedPort",
"name": "HTTPS",
"priority": 100,
"protocol": "TCP",
"provisioningState": "Succeeded",
"resourceGroup": "cloud-shell-storage-westeurope",
"sourceAddressPrefix": "*"
,
"sourceAddressPrefixes": []
,
"sourceApplicationSecurityGroups": null,
"sourcePortRange": "*",
"sourcePortRanges": [],
"type": "Microsoft.Network/networkSecurityGroups/securityRules"
}
]
If there are any rules with
"sourceAddressPrefix" or
"sourceAddressPrefixes" attributes set to or containing
"*",
"internet",
"0.0.0.0",
"0.0.0.0/0",
"::",
"0:0:0:0:0:0:0:0",
"0000:0000:0000:0000:0000:0000:0000:0000" or
"::/0", the selected network security group (NSG) allows unrestricted traffic on certain ports. To check for HTTPS access, check if any of the unrestricted inbound rules have
"destinationPortRange" or
"destinationPortRanges" set to or containing either
443 or some range that covers
443 (e.g.
1-1000 or
*). If any rules match this criteria, the security group rule is non-compliant.
05 Repeat step no. 3 and 4 for each Azure network security group created within the selected subscription.
06 Repeat steps no. 1 – 5 for each subscription available in your Microsoft Azure cloud account.