More Info:
Check your Microsoft Azure network security groups (NSGs) for inbound rules that allow unrestricted access (i.e. 0.0.0.0/0) on TCP port 22 and restrain access to only those IP addresses that require it in order to implement the principle of least privilege and reduce the possibility of a breach. TCP port 22 is used for secure remote login by connecting an SSH client application with an SSH server.Risk Level
CriticalAddress
SecurityCompliance Standards
- APRA CPS 234 (Australia)
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS AZURE
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- Cloudanix Best Practice
- DPDPA
- Digital Operational Resilience Act (EU)
- Essential 8
- FedRAMP
- GDPR
- HIPAA
- HITRUST CSF
- ISO 27001
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST CSF
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- PCI
- Reserve Bank of India (RBI) Cyber Security Framework
- Reserve Bank of India (RBI) Master Direction – Information Technology Framework
- SOC2
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
To remediate unrestricted SSH access in Azure, you can follow these steps:
- Log in to the Azure portal (https://portal.azure.com/).
- Navigate to the virtual machine that has unrestricted SSH access.
- Click on the “Networking” tab in the left-hand menu.
- Under “Inbound port rules,” click on “Add inbound port rule.”
- In the “Add inbound security rule” window, enter a name for the rule (e.g., “SSH access restricted”).
- Under “Destination port ranges,” enter “22” (or the port number that SSH is using).
- Under “Source,” select “IP Addresses.”
- Under “Source IP addresses,” enter the IP address or range that should have access to SSH (e.g., your own IP address or a specific subnet).
- Under “Action,” select “Allow.”
- Click “Add” to create the rule.
- Repeat steps 4-10 for any other virtual machines that have unrestricted SSH access.
Using CLI
Using CLI
The following are the steps to remediate unrestricted SSH access in AZURE using AZURE CLI:
-
Login to your Azure account using the Azure CLI command:
az login -
Once you are logged in, select the subscription that contains the virtual machine you want to remediate by using the command:
az account set --subscription <subscription-id> -
Get the name of the virtual machine you want to remediate by using the command:
az vm list --query "[].{name:name}" -o table -
Once you have identified the virtual machine, get the resource group name by using the command:
az vm show --name <vm-name> --query "resourceGroup" -o tsv -
Next, get the network security group associated with the virtual machine by using the command:
az vm show --name <vm-name> --resource-group <resource-group-name> --query "networkProfile.networkInterfaces[].id" -o tsv | xargs az network nic show --ids --query "networkSecurityGroup.id" -o tsv -
Get the name of the network security group by using the command:
az network nsg list --query "[].{name:name}" -o table -
Once you have identified the network security group, get the name of the security rule that allows unrestricted SSH access by using the command:
az network nsg rule list --nsg-name <nsg-name> --query "[?access=='Allow' && protocol=='Tcp' && destinationPortRange=='22' && destinationAddressPrefix=='*'].name" -o tsv -
Finally, delete the security rule that allows unrestricted SSH access by using the command:
az network nsg rule delete --name <rule-name> --nsg-name <nsg-name>Note: Replace<subscription-id>,<vm-name>,<resource-group-name>,<nsg-name>, and<rule-name>with the actual values from your Azure environment.
Using Python
Using Python
To remediate unrestricted SSH access in Azure using Python, you can follow these steps:This will remediate unrestricted SSH access in Azure by creating a new NSG rule that allows SSH access only from a specific IP range and deleting the old NSG rule that allows unrestricted SSH access.
- Import the necessary libraries:
- Authenticate to Azure using the DefaultAzureCredential:
- Get the network security group (NSG) that needs to be remediated:
- Get the NSG rules and find the rule that allows unrestricted SSH access:
- Create a new NSG rule that allows SSH access only from a specific IP range:
- Delete the old NSG rule that allows unrestricted SSH access:
- Verify that the new NSG rule has been created and the old rule has been deleted:
Using Terraform
Using Terraform
TRUSTED_ADMIN_IP_CIDR_1/TRUSTED_ADMIN_IP_CIDR_2with the specific admin/public IP CIDR blocks that require SSH.
terraform plan should show the source_address_prefix changing from "0.0.0.0/0" (or a wide range) to your specified source_address_prefixes list on the NSG security rule for TCP port 22.
