Network Security Group With Unrestricted Access To RDP
- Query id: 59cb3da7-f206-4ae6-b827-7abf0a9cab9d
- Query name: Network Security Group With Unrestricted Access To RDP
- Platform: AzureResourceManager
- Severity: High
- Category: Networking and Firewall
- CWE: 284
- URL: Github
Description¶
Port 3389 (Remote Desktop) is exposed to the Internet
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Positive test num. 1 - bicep file
resource security_group 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
name: 'security group'
location: 'location1'
tags: {}
properties: {
securityRules: [
{
id: 'id'
properties: {
description: 'access to RDP'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '3389'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 301
direction: 'Inbound'
}
name: 'security rule'
}
{
id: 'id2'
properties: {
description: 'access to SSH'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '22'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Deny'
priority: 301
direction: 'Inbound'
}
name: 'security rule2'
}
]
}
}
Positive test num. 2 - json file
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "security group",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "location1",
"tags": {},
"properties": {
"securityRules": [
{
"id": "id",
"properties": {
"description": "access to RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 301,
"direction": "Inbound"
},
"name": "security rule"
},
{
"id": "id2",
"properties": {
"description": "access to SSH",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "22",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Deny",
"priority": 301,
"direction": "Inbound"
},
"name": "security rule2"
}
]
},
"resources": []
}
],
"outputs": {}
}
Positive test num. 3 - bicep file
resource sample_securitygroup 'Microsoft.Network/networkSecurityGroups/securityRules@2020-11-01' = {
name: 'sample/securitygroup'
properties: {
description: 'access to RDP'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: ['3333-3389']
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
}
Positive test num. 4 - json file
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "sample/securitygroup",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"apiVersion": "2020-11-01",
"properties": {
"description": "access to RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRanges": [
"3333-3389"
],
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
}
],
"outputs": {}
}
Positive test num. 5 - bicep file
resource securitygroup 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
name: 'securitygroup'
location: 'location1'
tags: {}
properties: {}
}
resource securitygroup_sr 'Microsoft.Network/networkSecurityGroups/securityRules@2020-11-01' = {
parent: securitygroup
properties: {
description: 'access to RDP'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: ['3333-3389']
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
name: 'sr'
}
Positive test num. 6 - json file
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "securitygroup",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "location1",
"tags": {},
"properties": {},
"resources": [
{
"type": "securityRules",
"apiVersion": "2020-11-01",
"properties": {
"description": "access to RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRanges": [
"3333-3389"
],
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
},
"name": "sr"
}
]
}
],
"outputs": {}
}
Positive test num. 7 - bicep file
resource security_group 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
name: 'security group'
location: 'location1'
tags: {}
properties: {
securityRules: [
{
id: 'id'
properties: {
description: 'access to RDP'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '3389'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 301
direction: 'Inbound'
}
name: 'security rule'
}
]
}
}
Positive test num. 8 - json file
{
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "security group",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "location1",
"tags": {},
"properties": {
"securityRules": [
{
"id": "id",
"properties": {
"description": "access to RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 301,
"direction": "Inbound"
},
"name": "security rule"
}
]
},
"resources": []
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}
Positive test num. 9 - bicep file
resource sample_securitygroup 'Microsoft.Network/networkSecurityGroups/securityRules@2020-11-01' = {
name: 'sample/securitygroup'
properties: {
description: 'access to RDP'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: ['3333-3389']
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
}
Positive test num. 10 - json file
{
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "sample/securitygroup",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"apiVersion": "2020-11-01",
"properties": {
"description": "access to RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRanges": [
"3333-3389"
],
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}
Positive test num. 11 - bicep file
resource securitygroup 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
name: 'securitygroup'
location: 'location1'
tags: {}
properties: {}
}
resource securitygroup_sr 'Microsoft.Network/networkSecurityGroups/securityRules@2020-11-01' = {
parent: securitygroup
properties: {
description: 'access to RDP'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: ['3333-3389']
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
name: 'sr'
}
Positive test num. 12 - json file
{
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "securitygroup",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "location1",
"tags": {},
"properties": {},
"resources": [
{
"type": "securityRules",
"apiVersion": "2020-11-01",
"properties": {
"description": "access to RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRanges": [
"3333-3389"
],
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
},
"name": "sr"
}
]
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}
Code samples without security vulnerabilities¶
Negative test num. 1 - bicep file
resource security_group 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
name: 'security group'
location: 'location1'
tags: {}
properties: {
securityRules: [
{
id: 'id'
properties: {
description: 'access to RDP'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '3389'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Deny'
priority: 301
direction: 'Inbound'
}
name: 'security rule'
}
]
}
}
Negative test num. 2 - json file
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "security group",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "location1",
"tags": {},
"properties": {
"securityRules": [
{
"id": "id",
"properties": {
"description": "access to RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Deny",
"priority": 301,
"direction": "Inbound"
},
"name": "security rule"
}
]
},
"resources": []
}
],
"outputs": {}
}
Negative test num. 3 - bicep file
resource sample_securitygroup 'Microsoft.Network/networkSecurityGroups/securityRules@2020-11-01' = {
name: 'sample/securitygroup'
properties: {
description: 'access'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: ['4030-5100']
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
}
Negative test num. 4 - json file
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "sample/securitygroup",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"apiVersion": "2020-11-01",
"properties": {
"description": "access",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRanges": [
"4030-5100"
],
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
}
],
"outputs": {}
}
Negative test num. 5 - bicep file
resource securitygroup 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
name: 'securitygroup'
location: 'location1'
tags: {}
properties: {}
}
resource securitygroup_sr 'Microsoft.Network/networkSecurityGroups/securityRules@2020-11-01' = {
parent: securitygroup
properties: {
description: 'access'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: ['6634']
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
name: 'sr'
}
Negative test num. 6 - json file
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "securitygroup",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "location1",
"tags": {},
"properties": {},
"resources": [
{
"type": "securityRules",
"apiVersion": "2020-11-01",
"properties": {
"description": "access",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRanges": [
"6634"
],
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
},
"name": "sr"
}
]
}
],
"outputs": {}
}
Negative test num. 7 - bicep file
resource security_group 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
name: 'security group'
location: 'location1'
tags: {}
properties: {
securityRules: [
{
id: 'id'
properties: {
description: 'access to RDP'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: '3389'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Deny'
priority: 301
direction: 'Inbound'
}
name: 'security rule'
}
]
}
}
Negative test num. 8 - json file
{
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "security group",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "location1",
"tags": {},
"properties": {
"securityRules": [
{
"id": "id",
"properties": {
"description": "access to RDP",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Deny",
"priority": 301,
"direction": "Inbound"
},
"name": "security rule"
}
]
},
"resources": []
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}
Negative test num. 9 - bicep file
resource sample_securitygroup 'Microsoft.Network/networkSecurityGroups/securityRules@2020-11-01' = {
name: 'sample/securitygroup'
properties: {
description: 'access'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: ['4030-5100']
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
}
Negative test num. 10 - json file
{
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "sample/securitygroup",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"apiVersion": "2020-11-01",
"properties": {
"description": "access",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRanges": [
"4030-5100"
],
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
}
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}
Negative test num. 11 - bicep file
resource securitygroup 'Microsoft.Network/networkSecurityGroups@2020-11-01' = {
name: 'securitygroup'
location: 'location1'
tags: {}
properties: {}
}
resource securitygroup_sr 'Microsoft.Network/networkSecurityGroups/securityRules@2020-11-01' = {
parent: securitygroup
properties: {
description: 'access'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRanges: ['6634']
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
access: 'Allow'
priority: 100
direction: 'Inbound'
}
name: 'sr'
}
Negative test num. 12 - json file
{
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "2.0.0.0",
"apiProfile": "2019-03-01-hybrid",
"parameters": {},
"variables": {},
"functions": [],
"resources": [
{
"name": "securitygroup",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-11-01",
"location": "location1",
"tags": {},
"properties": {},
"resources": [
{
"type": "securityRules",
"apiVersion": "2020-11-01",
"properties": {
"description": "access",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRanges": [
"6634"
],
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": 100,
"direction": "Inbound"
},
"name": "sr"
}
]
}
],
"outputs": {}
},
"parameters": {}
},
"kind": "template",
"type": "Microsoft.Blueprint/blueprints/artifacts",
"name": "myTemplate"
}