-
Notifications
You must be signed in to change notification settings - Fork 359
fix(query): fn for remote desktop port open to internet and other "security group" associated queries --terraform/aws--cloudformation/aws #7646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cx-andre-pereira
merged 98 commits into
master
from
AST-109541--FN-Remote_Desktop_Port_Open_To_Internet--terraform/aws
Sep 16, 2025
Merged
Changes from 85 commits
Commits
Show all changes
98 commits
Select commit
Hold shift + click to select a range
2359dd0
fix(query): fn for remote desktop port open to internet--terraform/aws
cx-andre-pereira ae196dc
fix expected results
cx-andre-pereira 7fc034b
typo cleanup
cx-andre-pereira f7dda09
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira ecb0826
initial changes
cx-andre-pereira 6d262f4
support for generic security group
cx-andre-pereira 06158e9
fix negative tests
cx-andre-pereira 3b75a22
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira 71f7571
some changes
cx-andre-pereira c34f4a7
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 260e0c3
'all' protocol support
cx-andre-pereira 78d8048
Merge branch 'AST-109541--FN-Remote_Desktop_Port_Open_To_Internet--te…
cx-andre-pereira a42b55a
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira f402647
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-artur-ribeiro 1e4ca51
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-artur-ribeiro be15c4f
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira dd52de9
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 879aeb1
Merge branch 'AST-109542--FN-Sensitive_Port_Is_Exposed_To_Entire_Netw…
cx-andre-pereira 8a9a479
Merge branch 'AST-109541--FN-Remote_Desktop_Port_Open_To_Internet--te…
cx-andre-pereira 2248c56
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-artur-ribeiro 9be511f
senstive port exposed positive tests and expected resuts
cx-andre-pereira 58867a2
sensitive port negative tests
cx-andre-pereira 6c429d5
Merge branch 'AST-109541--FN-Remote_Desktop_Port_Open_To_Internet--te…
cx-andre-pereira 63fc782
typo fix
cx-andre-pereira ce7124e
vpc ingress rules for unrestricted sec group index
cx-andre-pereira ebaa7b7
implemented vpc security ingress rule and generic rule on security gr…
cx-andre-pereira 3f51fee
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira e25d983
added security group rules and ingres rules to senistive port is expo…
cx-andre-pereira ee41905
fixed accidentale negative test change
cx-andre-pereira c8a9383
small test fix
cx-andre-pereira c60e93d
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 5aad693
tests for Ingress array on 'sensitive port exposed' queries and sensi…
cx-andre-pereira b871783
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira 75630c0
improved search line and key
cx-andre-pereira 952177d
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira f1e5b30
missing searchValue on sensitive port exposed to wide private network…
cx-andre-pereira 23becaf
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira fc6f282
added support for aws vpc securituy ingress and egress rules for secu…
cx-andre-pereira e95c89d
added sec group rules, ingress rules and inline ingress array support…
cx-andre-pereira f8fc5b1
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira e36a08b
better ingress array/ single ingress support and support for security…
cx-andre-pereira d835303
reducing CxPolicy ammount 1
cx-andre-pereira 32ef6a8
reducing CxPolicy amount 2
cx-andre-pereira 432b57a
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 1246d2a
fix array was treated as single element
cx-andre-pereira 36c7039
reducing CxPolicy amount 3
cx-andre-pereira 8b1d05d
reducing CxPolicy amount 4
cx-andre-pereira d858b4b
mend
cx-andre-pereira d2c9a8a
added serachValue back (removed accidently)
cx-andre-pereira f796880
better key values for unrestricted sec group ing and fix 2 for sensit…
cx-andre-pereira c5b1e97
refactor for unrestricted security group ingress for ingress array vs…
cx-andre-pereira ea217fd
newlines removed
cx-andre-pereira b884858
added support for aws_security_group modules to sensitive port expose…
cx-andre-pereira 0196de7
fix query name/severity in results
cx-andre-pereira 3ebf0f8
fixed all invalid 'modules' in security group with unrestricted acc t…
cx-andre-pereira 26afa30
added module support for http port open
cx-andre-pereira 1522b47
added module support for remote desktop port open to internet
cx-andre-pereira 7aef934
added 'security group' module support for sec group without descripti…
cx-andre-pereira d2dbfff
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira 513c0d1
module support for sql analysis services port 2383 is publicly access…
cx-andre-pereira e276ab4
module support for unknown port exposed to internet
cx-andre-pereira 2cebe85
improved module support for unrestricted security group ingress, now …
cx-andre-pereira 44d4ff9
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 102238f
standardized unrestricted security group ingress tests, fixed module …
cx-andre-pereira e20cbeb
new test on positive3 and newline cleanup
cx-andre-pereira ba12538
tests changes
cx-andre-pereira b07d3c4
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 5bb7027
ipv6 support for modules for http port open and new tests
cx-andre-pereira b790686
standardized testing for 'port x' open queries and added ipv6 module …
cx-andre-pereira 64990a9
fix tests
cx-andre-pereira 11e095f
added support for ipv6 cidr blocks in modules to security group rules…
cx-andre-pereira 69be694
ipv6 support for modules for unknown port exposed to internet and tests
cx-andre-pereira 25ce160
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 9c64c60
added module ipv6 support for sensitive_port_is_exposed_to_x queries
cx-andre-pereira 2731180
standardizing tests/ queries 1
cx-andre-pereira 07f3ee6
support for wide private ipv6 networks and small public ipv6 networks…
cx-andre-pereira a69c280
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira 4062117
x port publicly accessible/open to internet type queries tests standa…
cx-andre-pereira 7a44cdd
final adjustments for 'without description' queries
cx-andre-pereira 79e32ea
expected results fix and security_group_rules_without_description / u…
cx-andre-pereira 5227a45
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-artur-ribeiro 9b6bb96
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira bc3b8d4
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 14bf639
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira f209843
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira f0dff82
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira 0392384
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira 3971505
Merge branch 'AST-109541--FN-Remote_Desktop_Port_Open_To_Internet--te…
cx-andre-pereira 3ce95d2
requested changes
cx-andre-pereira a700be2
fix cidr_is_unmasked
cx-andre-pereira 0e251c4
removed unecessary variable declaration
cx-andre-pereira ca77f82
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-artur-ribeiro 5439e06
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira c66d914
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira 4b0b34a
fix attempt 1
cx-andre-pereira 24678a5
Merge branch 'AST-109541--FN-Remote_Desktop_Port_Open_To_Internet--te…
cx-andre-pereira a4e8e01
fix attempt 2
cx-andre-pereira 24f8cac
Merge branch 'master' into AST-109541--FN-Remote_Desktop_Port_Open_To…
cx-andre-pereira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,19 +1,89 @@ | ||
| package Cx | ||
|
|
||
| import data.generic.terraform as tf_lib | ||
| import data.generic.common as common_lib | ||
|
|
||
| CxPolicy[result] { | ||
| #Case of "aws_vpc_security_group_ingress_rule" or "aws_security_group_rule" | ||
| types := ["aws_vpc_security_group_ingress_rule","aws_security_group_rule"] | ||
| resource := input.document[i].resource[types[i2]][name] | ||
|
|
||
| tf_lib.is_security_group_ingress(types[i2],resource) | ||
| tf_lib.portOpenToInternet(resource, 80) | ||
|
|
||
| result := { | ||
| "documentId": input.document[i].id, | ||
| "resourceType": types[i2], | ||
| "resourceName": tf_lib.get_resource_name(resource, name), | ||
| "searchKey": sprintf("%s[%s]", [types[i2],name]), | ||
| "issueType": "IncorrectValue", | ||
| "keyExpectedValue": sprintf("%s[%s] should not open the HTTP port (80)", [types[i2],name]), | ||
| "keyActualValue": sprintf("%s[%s] opens the HTTP port (80)", [types[i2],name]), | ||
| "searchLine": common_lib.build_search_line(["resource", types[i2], name], []), | ||
| } | ||
| } | ||
|
|
||
| CxPolicy[result] { | ||
| #Case of "aws_security_group" | ||
| resource := input.document[i].resource.aws_security_group[name] | ||
|
|
||
| tf_lib.portOpenToInternet(resource.ingress, 80) | ||
| ingress_list := tf_lib.get_ingress_list(resource.ingress) | ||
| results := http_is_open(ingress_list.value[i2],ingress_list.is_unique_element,name,i2) | ||
| results != "" | ||
|
|
||
| result := { | ||
| "documentId": input.document[i].id, | ||
| "resourceType": "aws_security_group", | ||
| "resourceName": tf_lib.get_resource_name(resource, name), | ||
| "searchKey": sprintf("aws_security_group[%s]", [name]), | ||
| "searchKey": results.searchKey, | ||
| "issueType": "IncorrectValue", | ||
| "keyExpectedValue": results.keyExpectedValue, | ||
| "keyActualValue": results.keyActualValue, | ||
| "searchLine": results.searchLine, | ||
| } | ||
| } | ||
|
|
||
| CxPolicy[result] { | ||
| #Case of "security-group" Module | ||
| module := input.document[i].module[name] | ||
| types := ["ingress_with_cidr_blocks","ingress_with_ipv6_cidr_blocks"] | ||
| ingressKey := common_lib.get_module_equivalent_key("aws", module.source, "aws_security_group", types[t]) | ||
| common_lib.valid_key(module, ingressKey) | ||
|
|
||
| ingress := module[ingressKey][i2] | ||
|
|
||
| tf_lib.portOpenToInternet(ingress, 80) | ||
|
|
||
| result := { | ||
| "documentId": input.document[i].id, | ||
| "resourceType": "n/a", | ||
| "resourceName": "n/a", | ||
| "searchKey": sprintf("module[%s].%s.%d", [name, ingressKey,i2]), | ||
| "issueType": "IncorrectValue", | ||
| "keyExpectedValue": "aws_security_group.ingress shouldn't open the HTTP port (80)", | ||
| "keyActualValue": "aws_security_group.ingress opens the HTTP port (80)", | ||
| "keyExpectedValue": sprintf("module[%s].%s.%d should not open the HTTP port (80)",[name, ingressKey,i2]), | ||
| "keyActualValue": sprintf("module[%s].%s.%d opens the HTTP port (80)",[name, ingressKey,i2]), | ||
| "searchLine": common_lib.build_search_line(["module", name, ingressKey, i2], []), | ||
| } | ||
| } | ||
|
|
||
| http_is_open(ingress,is_unique_element,name,i2) = results { | ||
| is_unique_element | ||
| tf_lib.portOpenToInternet(ingress, 80) | ||
|
|
||
| results := { | ||
| "searchKey" : sprintf("aws_security_group[%s].ingress", [name]), | ||
| "keyExpectedValue" : sprintf("aws_security_group[%s].ingress should not open the HTTP port (80)",[name]), | ||
| "keyActualValue" : sprintf("aws_security_group[%s].ingress opens the HTTP port (80)",[name]), | ||
| "searchLine" : common_lib.build_search_line(["resource", "aws_security_group", name, "ingress"], []), | ||
| } | ||
| } else = results { | ||
| not is_unique_element | ||
| tf_lib.portOpenToInternet(ingress, 80) | ||
|
|
||
| results := { | ||
| "searchKey" : sprintf("aws_security_group[%s].ingress[%d]", [name,i2]), | ||
| "keyExpectedValue" : sprintf("aws_security_group[%s].ingress[%d] should not open the HTTP port (80)", [name,i2]), | ||
| "keyActualValue" : sprintf("aws_security_group[%s].ingress[%d] opens the HTTP port (80)", [name,i2]), | ||
| "searchLine" : common_lib.build_search_line(["resource", "aws_security_group", name, "ingress", i2], []), | ||
| } | ||
| } else = "" |
23 changes: 0 additions & 23 deletions
23
assets/queries/terraform/aws/http_port_open/test/negative.tf
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
assets/queries/terraform/aws/http_port_open/test/negative1.tf
This file contains hidden or 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,66 @@ | ||
| resource "aws_security_group" "negative1-1" { | ||
|
|
||
| ingress { | ||
| description = "Remote desktop open private" | ||
| from_port = 70 | ||
| to_port = 81 | ||
| protocol = "tcp" | ||
| } | ||
| } | ||
|
|
||
| resource "aws_security_group" "negative1-2" { | ||
|
|
||
| ingress { | ||
| description = "Remote desktop open private" | ||
| from_port = 79 | ||
| to_port = 100 | ||
| protocol = "tcp" | ||
| cidr_blocks = ["0.1.0.0/0"] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_security_group" "negative1-3" { | ||
|
|
||
| ingress { | ||
| description = "Remote desktop open private" | ||
| from_port = 3380 | ||
| to_port = 3450 | ||
| protocol = "tcp" | ||
| ipv6_cidr_blocks = ["2001:db8:abcd:0012::/64"] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_security_group" "negative1-4" { | ||
| name = "allow_tls" | ||
| description = "sample" | ||
|
|
||
| ingress { | ||
| description = "sample" | ||
| from_port = 100 | ||
| to_port = 200 | ||
| protocol = "tcp" | ||
| cidr_blocks = ["0.0.0.0/0"] | ||
| } | ||
|
|
||
| ingress { | ||
| description = "sample" | ||
| from_port = 100 | ||
| to_port = 200 | ||
| protocol = "tcp" | ||
| ipv6_cidr_blocks = ["fd00::/8", "::/0"] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_security_group" "negative1-5" { | ||
| name = "allow_tls" | ||
| description = "sample" | ||
|
|
||
| ingress { | ||
| description = "sample" | ||
| from_port = 80 | ||
| to_port = 80 | ||
| protocol = "tcp" | ||
| cidr_blocks = ["192.120.0.0/16"] | ||
| ipv6_cidr_blocks = ["fd00::/8"] | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
assets/queries/terraform/aws/http_port_open/test/negative2.tf
This file contains hidden or 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,31 @@ | ||
| resource "aws_security_group" "ec2" { | ||
| description = "ec2 sg" | ||
| name = "secgroup-ec2" | ||
| vpc_id = var.vpc_id | ||
| } | ||
|
|
||
| resource "aws_vpc_security_group_ingress_rule" "negative2-1" { | ||
| security_group_id = aws_security_group.negative.id | ||
| from_port = 80 | ||
| to_port = 80 | ||
| ip_protocol = "tcp" | ||
| description = "TLS from VPC" | ||
| } | ||
|
|
||
| resource "aws_vpc_security_group_ingress_rule" "negative2-2" { | ||
| security_group_id = aws_security_group.ec2.id | ||
| cidr_ipv4 = "0.0.1.0/0" | ||
| from_port = 80 | ||
| to_port = 80 | ||
| ip_protocol = "tcp" | ||
| description = "allows RDP from Internet" | ||
| } | ||
|
|
||
| resource "aws_vpc_security_group_ingress_rule" "negative2-3" { | ||
| security_group_id = aws_security_group.ec2.id | ||
| cidr_ipv6 = "2001:db8:abcd:0012::/64" | ||
| from_port = 80 | ||
| to_port = 80 | ||
| ip_protocol = "-1" | ||
| description = "allows RDP from Internet" | ||
| } |
34 changes: 34 additions & 0 deletions
34
assets/queries/terraform/aws/http_port_open/test/negative3.tf
This file contains hidden or 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,34 @@ | ||
| resource "aws_security_group" "ec2" { | ||
| description = "ec2 sg" | ||
| name = "secgroup-ec2" | ||
| vpc_id = var.vpc_id | ||
| } | ||
|
|
||
| resource "aws_security_group_rule" "negative3-1" { | ||
| type = "ingress" | ||
| from_port = 80 | ||
| to_port = 80 | ||
| protocol = "tcp" | ||
| security_group_id = aws_security_group.negative.id | ||
| description = "TLS from VPC" | ||
| } | ||
|
|
||
| resource "aws_security_group_rule" "negative3-2" { | ||
| type = "ingress" | ||
| from_port = 80 | ||
| to_port = 80 | ||
| protocol = "tcp" | ||
| cidr_blocks = ["0.0.1.0/0"] | ||
| security_group_id = aws_security_group.ec2.id | ||
| description = "allows RDP from Internet (IPv4)" | ||
| } | ||
|
|
||
| resource "aws_security_group_rule" "negative3-3" { | ||
| type = "ingress" | ||
| from_port = 79 | ||
| to_port = 100 | ||
| protocol = "-1" | ||
| ipv6_cidr_blocks = ["2001:db8:abcd:0012::/64"] | ||
| security_group_id = aws_security_group.ec2.id | ||
| description = "allows RDP from Internet (IPv6)" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.