More Info:
Ensure that Microsoft Azure network security groups (NSGs) do not allow unrestricted access on TCP ports 20 and 21 in order to protect against attackers that use brute force methods to gain access to Azure virtual machines associated with these NSGs. TCP ports 20 and 21 are used for data transfer and communication by the File Transfer Protocol (FTP) client-server applications.Risk Level
HighAddress
SecurityCompliance Standards
- APRA CPS 234 (Australia)
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- DPDPA
- Digital Operational Resilience Act (EU)
- FedRAMP
- GDPR
- 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
- 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 FTP access to Port 20 in Azure, follow these steps:
- Open the Azure portal and navigate to the Virtual Machine (VM) that has unrestricted FTP access to Port 20.
- Stop the VM by clicking on the “Stop” button at the top of the VM’s overview page.
- Once the VM is stopped, click on the “Networking” tab in the left-hand menu.
- Click on the “Add inbound port rule” button.
- In the “Add inbound security rule” dialog, configure the following settings:
- Name: A descriptive name for the new rule.
- Priority: A number that determines the order in which rules are evaluated (lower numbers are evaluated first).
- Source: The IP address range or subnet that should be allowed to access Port 20. If you want to restrict access to a specific IP address, enter that IP address in the “Source IP addresses/CIDR ranges” field.
- Destination port ranges: Enter “20” to restrict access to Port 20.
- Protocol: Select “TCP” from the dropdown menu.
- Action: Select “Allow” from the dropdown menu.
- Click on the “Add” button to create the new inbound security rule.
- Start the VM by clicking on the “Start” button at the top of the VM’s overview page.
Using CLI
Using CLI
To remediate the unrestricted FTP access to port 20 misconfiguration in Azure using Azure CLI, you can follow the following steps:
-
Open the Azure CLI and login to your Azure account using the command
az login. -
Once you are logged in, run the following command to get the list of all the virtual machines in your Azure subscription:
- Identify the virtual machine that has unrestricted FTP access to port 20 and note down its name and resource group.
-
Run the following command to open port 20 for FTP traffic on the identified virtual machine:
Note: Replace
<resource-group-name>and<vm-name>with the actual names of the resource group and virtual machine that you have identified. -
Verify that the port 20 is now open for FTP traffic on the virtual machine by running the following command:
This command should return the list of all the open ports on the virtual machine, including port 20 for FTP traffic.
- Repeat the above steps for all the virtual machines in your Azure subscription that have unrestricted FTP access to port 20.
Using Python
Using Python
To remediate the unrestricted FTP access to port 20 in Azure using Python, you can follow the below steps:This code creates a network security group that allows FTP access only from the specified IP address or range, and associates it with the virtual machine. You can customize the code to meet your specific requirements.
- Identify the Azure virtual machine(s) that have unrestricted FTP access to port 20.
- Use the Python SDK for Azure to create a network security group (NSG) for the virtual machine(s) that allows FTP access only from a specific IP address or range.
- Associate the NSG with the virtual machine(s) that have unrestricted FTP access to port 20.
- Verify that the NSG is working as expected by testing FTP access from a different IP address.
Using Terraform
Using Terraform
azurerm_network_security_rule from source_address_prefix = "*" (or 0.0.0.0/0) to a restricted CIDR typically updates that rule in place; if the name or direction/priority change, Terraform will replace only the rule resource, not the NSG itself.To verify, terraform plan should show either:- an
update in-place(or small-/+replacement) for the specific FTP rule, wheresource_address_prefixchanges from"*"/"0.0.0.0/0"to"ALLOWED_FTP_SOURCE_CIDR", or - a new rule being added and any old unrestricted FTP rule being removed.

