forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): added "RDP Access Is Not Restricted" for Google Deployme…
…nt Manager (Checkmarx#4730) Signed-off-by: JoaoDanielRufino <[email protected]>
- Loading branch information
1 parent
4556e8e
commit 96a8762
Showing
13 changed files
with
175 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 21 additions & 17 deletions
38
assets/queries/ansible/gcp/rdp_access_is_not_restricted/test/positive.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 10 additions & 10 deletions
20
assets/queries/ansible/gcp/rdp_access_is_not_restricted/test/positive_expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[ | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 6 | ||
}, | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 25 | ||
} | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 8 | ||
}, | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 29 | ||
} | ||
] |
11 changes: 11 additions & 0 deletions
11
assets/queries/googleDeploymentManager/rdp_access_is_not_restricted/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "50cb6c3b-c878-4b88-b50e-d1421bada9e8", | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"category": "Networking and Firewall", | ||
"descriptionText": "Check if the Google compute firewall allows unrestricted RDP access. Allowed ports should not contain RDP port 3389", | ||
"descriptionUrl": "https://cloud.google.com/compute/docs/reference/rest/v1/firewalls", | ||
"platform": "GoogleDeploymentManager", | ||
"descriptionID": "cae2eeea", | ||
"cloudProvider": "gcp" | ||
} |
45 changes: 45 additions & 0 deletions
45
assets/queries/googleDeploymentManager/rdp_access_is_not_restricted/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
|
||
CxPolicy[result] { | ||
resource := input.document[i].resources[idx] | ||
resource.type == "compute.v1.firewall" | ||
properties := resource.properties | ||
|
||
common_lib.is_ingress(properties) | ||
common_lib.is_unrestricted(properties.sourceRanges[_]) | ||
isRDPport(properties.allowed[a]) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("resources.name={{%s}}.properties.allowed", [resource.name]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "'allowed.ports' to not include RDP port 3389", | ||
"keyActualValue": "'allowed.ports' includes RDP port 3389", | ||
"searchLine": common_lib.build_search_line(["resources", idx, "properties", "allowed", a], []), | ||
} | ||
} | ||
|
||
isRDPport(allow) { | ||
isTCPorUDP(allow.IPProtocol) | ||
contains(allow.ports[j], "-") | ||
port_bounds := split(allow.ports[j], "-") | ||
low_bound := to_number(port_bounds[0]) | ||
high_bound := to_number(port_bounds[1]) | ||
isInBounds(low_bound, high_bound) | ||
} else { | ||
isTCPorUDP(allow.IPProtocol) | ||
contains(allow.ports[j], "-") == false | ||
to_number(allow.ports[j]) == 3389 | ||
} | ||
|
||
isInBounds(low, high) { | ||
low <= 3389 | ||
high >= 3389 | ||
} | ||
|
||
isTCPorUDP(protocol) { | ||
protocols := {"tcp", "udp"} | ||
lower(protocol) == protocols[_] | ||
} |
11 changes: 11 additions & 0 deletions
11
assets/queries/googleDeploymentManager/rdp_access_is_not_restricted/test/negative1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
resources: | ||
- name: firewall | ||
type: compute.v1.firewall | ||
properties: | ||
name: my-firewall | ||
allowed: | ||
- IPProtocol: icmp | ||
ports: | ||
- "80" | ||
- "8080" | ||
- "1000-2000" |
19 changes: 19 additions & 0 deletions
19
assets/queries/googleDeploymentManager/rdp_access_is_not_restricted/test/positive1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
resources: | ||
- name: firewall | ||
type: compute.v1.firewall | ||
properties: | ||
name: my-firewall | ||
sourceRanges: | ||
- "0.0.0.0/0" | ||
allowed: | ||
- IPProtocol: icmp | ||
ports: | ||
- "80" | ||
- "8080" | ||
- "1000-2000" | ||
- IPProtocol: tcp | ||
ports: | ||
- "80" | ||
- "8080" | ||
- "1000-2000" | ||
- "3389" |
19 changes: 19 additions & 0 deletions
19
assets/queries/googleDeploymentManager/rdp_access_is_not_restricted/test/positive2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
resources: | ||
- name: firewall | ||
type: compute.v1.firewall | ||
properties: | ||
name: my-firewall | ||
sourceRanges: | ||
- "::/0" | ||
allowed: | ||
- IPProtocol: icmp | ||
ports: | ||
- "80" | ||
- "8080" | ||
- "1000-2000" | ||
- IPProtocol: udp | ||
ports: | ||
- "80" | ||
- "8080" | ||
- "1000-2000" | ||
- "21-3389" |
14 changes: 14 additions & 0 deletions
14
...s/googleDeploymentManager/rdp_access_is_not_restricted/test/positive_expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 14, | ||
"filename": "positive1.yaml" | ||
}, | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 14, | ||
"filename": "positive2.yaml" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 10 additions & 10 deletions
20
assets/queries/terraform/gcp/rdp_access_is_not_restricted/test/positive_expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[ | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 12 | ||
}, | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 24 | ||
} | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 12 | ||
}, | ||
{ | ||
"queryName": "RDP Access Is Not Restricted", | ||
"severity": "MEDIUM", | ||
"line": 25 | ||
} | ||
] |