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.
Merge branch 'master' of https://github.com/Checkmarx/kics into master
- Loading branch information
Showing
263 changed files
with
6,747 additions
and
58 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
assets/queries/ansible/aws/allUsers_gets_read_access/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,8 @@ | ||
{ | ||
"id": "ansible_allUsers_group_gets_read_access", | ||
"queryName": "All Users Group Gets Read Access", | ||
"severity": "HIGH", | ||
"category": "Identity and Access Management", | ||
"descriptionText": "It's not recommended to allow read access for all user groups.", | ||
"descriptionUrl": "https://docs.ansible.com/ansible/latest/collections/amazon/aws/aws_s3_module.html#parameter-permission" | ||
} |
31 changes: 31 additions & 0 deletions
31
assets/queries/ansible/aws/allUsers_gets_read_access/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,31 @@ | ||
package Cx | ||
|
||
CxPolicy [ result ] { | ||
document := input.document[i] | ||
tasks := getTasks(document) | ||
task := tasks[t] | ||
s3 := task["amazon.aws.aws_s3"] | ||
s3Name := task.name | ||
|
||
hasPublicReadPermission(s3.permission) | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("name={{%s}}.{{amazon.aws.aws_s3}}.permission", [s3Name]), | ||
"issueType": "WrongValue", | ||
"keyExpectedValue": "amazon.aws.aws_s3 should not have read access for all user groups", | ||
"keyActualValue": "amazon.aws.aws_s3 has read access for all user groups" | ||
} | ||
} | ||
|
||
hasPublicReadPermission(value){ | ||
startswith(value, "public-read") | ||
} | ||
|
||
getTasks(document) = result { | ||
result := [body | playbook := document.playbooks[0]; body := playbook.tasks] | ||
count(result) != 0 | ||
} else = result { | ||
result := [body | playbook := document.playbooks[_]; body := playbook ] | ||
count(result) != 0 | ||
} |
10 changes: 10 additions & 0 deletions
10
assets/queries/ansible/aws/allUsers_gets_read_access/test/negative.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,10 @@ | ||
--- | ||
- name: Create an empty bucket | ||
amazon.aws.aws_s3: | ||
bucket: mybucket | ||
mode: create | ||
permission: private | ||
- name: Create an empty bucket2 | ||
amazon.aws.aws_s3: | ||
bucket: mybucket | ||
mode: create |
11 changes: 11 additions & 0 deletions
11
assets/queries/ansible/aws/allUsers_gets_read_access/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Create an empty bucket | ||
amazon.aws.aws_s3: | ||
bucket: mybucket | ||
mode: create | ||
permission: public-read | ||
- name: Create an empty bucket2 | ||
amazon.aws.aws_s3: | ||
bucket: mybucket | ||
mode: create | ||
permission: public-read-write |
12 changes: 12 additions & 0 deletions
12
assets/queries/ansible/aws/allUsers_gets_read_access/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,12 @@ | ||
[ | ||
{ | ||
"queryName": "All Users Group Gets Read Access", | ||
"severity": "HIGH", | ||
"line": 6 | ||
}, | ||
{ | ||
"queryName": "All Users Group Gets Read Access", | ||
"severity": "HIGH", | ||
"line": 11 | ||
} | ||
] |
8 changes: 8 additions & 0 deletions
8
assets/queries/ansible/aws/all_Auth_Users_get_read_access/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,8 @@ | ||
{ | ||
"id": "ansible_all_Auth_Users_get_read_access", | ||
"queryName": "All Auth Users Get Read Access", | ||
"severity": "HIGH", | ||
"category": "Identity and Access Management", | ||
"descriptionText": "Misconfigured S3 buckets can leak private information to the entire internet or allow unauthorized data tampering / deletion", | ||
"descriptionUrl": "https://docs.ansible.com/ansible/latest/collections/amazon/aws/aws_s3_module.html#parameter-permission" | ||
} |
27 changes: 27 additions & 0 deletions
27
assets/queries/ansible/aws/all_Auth_Users_get_read_access/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,27 @@ | ||
package Cx | ||
|
||
CxPolicy [ result ] { | ||
document := input.document[i] | ||
tasks := getTasks(document) | ||
task := tasks[t] | ||
s3 := task["amazon.aws.aws_s3"] | ||
s3Name := task.name | ||
|
||
s3.permission == "authenticated-read" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("name={{%s}}.{{amazon.aws.aws_s3}}.permission", [s3Name]), | ||
"issueType": "WrongValue", | ||
"keyExpectedValue": "amazon.aws.aws_s3 should not have read access for all authenticated users", | ||
"keyActualValue": "amazon.aws.aws_s3 has read access for all authenticated users" | ||
} | ||
} | ||
|
||
getTasks(document) = result { | ||
result := [body | playbook := document.playbooks[0]; body := playbook.tasks] | ||
count(result) != 0 | ||
} else = result { | ||
result := [body | playbook := document.playbooks[_]; body := playbook ] | ||
count(result) != 0 | ||
} |
10 changes: 10 additions & 0 deletions
10
assets/queries/ansible/aws/all_Auth_Users_get_read_access/test/negative.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,10 @@ | ||
--- | ||
- name: Create an empty bucket | ||
amazon.aws.aws_s3: | ||
bucket: mybucket | ||
mode: create | ||
- name: Create an empty bucket2 | ||
amazon.aws.aws_s3: | ||
bucket: mybucket | ||
mode: create | ||
permission: private |
6 changes: 6 additions & 0 deletions
6
assets/queries/ansible/aws/all_Auth_Users_get_read_access/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: Create an empty bucket2 | ||
amazon.aws.aws_s3: | ||
bucket: mybucket | ||
mode: create | ||
permission: authenticated-read |
7 changes: 7 additions & 0 deletions
7
assets/queries/ansible/aws/all_Auth_Users_get_read_access/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,7 @@ | ||
[ | ||
{ | ||
"queryName": "All Auth Users Get Read Access", | ||
"severity": "HIGH", | ||
"line": 6 | ||
} | ||
] |
8 changes: 8 additions & 0 deletions
8
...ts/queries/ansible/aws/default_security_group_does_not_restrict_all_traffic/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,8 @@ | ||
{ | ||
"id": "ansible_default_security_group_does_not_restrict_all_traffic", | ||
"queryName": "Default Security Group Does Not Restrict All Traffic", | ||
"severity": "HIGH", | ||
"category": "Network Ports Security", | ||
"descriptionText": "Check if default security group does not restrict all inbound and outbound traffic.", | ||
"descriptionUrl": "https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_group_module.html" | ||
} |
59 changes: 59 additions & 0 deletions
59
assets/queries/ansible/aws/default_security_group_does_not_restrict_all_traffic/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,59 @@ | ||
package Cx | ||
|
||
CxPolicy [ result ] { | ||
document := input.document[i] | ||
tasks := getTasks(document) | ||
task := tasks[t] | ||
group := task["amazon.aws.ec2_group"] | ||
groupName := task.name | ||
searchKey := getCidrBlock(group) | ||
|
||
splitted := regex.split("{{|}}", searchKey) | ||
errorPath := substring(splitted[0], 0, count(splitted[0])-1) | ||
errorValue := splitted[1] | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("name={{%s}}.{{amazon.aws.ec2_group}}.%s", [groupName, searchKey]), | ||
"issueType": "WrongValue", | ||
"keyExpectedValue": sprintf("amazon.aws.ec2_group.%s should not contain the value '%s'", [errorPath, errorValue]), | ||
"keyActualValue": sprintf("amazon.aws.ec2_group.%s contains value '%s'", [errorPath, errorValue]) | ||
} | ||
} | ||
|
||
getTasks(document) = result { | ||
result := [body | playbook := document.playbooks[0]; body := playbook.tasks] | ||
count(result) != 0 | ||
} else = result { | ||
result := [body | playbook := document.playbooks[_]; body := playbook ] | ||
count(result) != 0 | ||
} | ||
|
||
getCidrBlock(sg) = path { | ||
isUnsafeIp(sg.rules[r].cidr_ip) | ||
path:="rules.cidr_ip={{0.0.0.0/0}}" | ||
} else = path { | ||
isUnsafeIp(sg.rules[r].cidr_ip[c]) | ||
path:="rules.cidr_ip.{{0.0.0.0/0}}" | ||
} else = path { | ||
isUnsafeIp(sg.rules_egress[r].cidr_ip) | ||
path:="rules_egress.cidr_ip={{0.0.0.0/0}}" | ||
} else = path { | ||
isUnsafeIp(sg.rules_egress[r].cidr_ip[c]) | ||
path:="rules_egress.cidr_ip.{{0.0.0.0/0}}" | ||
} else = path { | ||
isUnsafeIpv6(sg.rules[r].cidr_ipv6) | ||
path:="rules.cidr_ipv6={{::/0}}" | ||
} else = path { | ||
isUnsafeIpv6(sg.rules[r].cidr_ipv6[c]) | ||
path:="rules.cidr_ipv6.{{::/0}}" | ||
} else = path { | ||
isUnsafeIpv6(sg.rules_egress[r].cidr_ipv6) | ||
path:="rules_egress.cidr_ipv6={{::/0}}" | ||
} else = path { | ||
isUnsafeIpv6(sg.rules_egress[r].cidr_ipv6[c]) | ||
path:="rules_egress.cidr_ipv6.{{::/0}}" | ||
} | ||
|
||
isUnsafeIp("0.0.0.0/0") | ||
isUnsafeIpv6("::/0") |
27 changes: 27 additions & 0 deletions
27
...eries/ansible/aws/default_security_group_does_not_restrict_all_traffic/test/negative.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,27 @@ | ||
|
||
--- | ||
- name: example ec2 group | ||
amazon.aws.ec2_group: | ||
name: example | ||
description: an example EC2 group | ||
vpc_id: 12345 | ||
region: eu-west-1 | ||
aws_secret_key: SECRET | ||
aws_access_key: ACCESS | ||
rules: | ||
- proto: all | ||
# in the 'proto' attribute, if you specify -1, all, or a protocol number other than tcp, udp, icmp, or 58 (ICMPv6), | ||
# traffic on all ports is allowed, regardless of any ports you specify | ||
from_port: 10050 # this value is ignored | ||
to_port: 10050 # this value is ignored | ||
cidr_ip: 10.1.0.0/16 | ||
cidr_ipv6: 64:ff9b::/96 | ||
rules_egress: | ||
- proto: tcp | ||
from_port: 80 | ||
to_port: 80 | ||
cidr_ip: 10.1.0.0/16 | ||
cidr_ipv6: 64:ff9b::/96 | ||
group_name: example-other | ||
# description to use if example-other needs to be created | ||
group_desc: other example EC2 group |
86 changes: 86 additions & 0 deletions
86
...eries/ansible/aws/default_security_group_does_not_restrict_all_traffic/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
- name: example ec2 group | ||
amazon.aws.ec2_group: | ||
name: example | ||
description: an example EC2 group | ||
vpc_id: 12345 | ||
region: eu-west-1 | ||
aws_secret_key: SECRET | ||
aws_access_key: ACCESS | ||
rules: | ||
- proto: all | ||
# in the 'proto' attribute, if you specify -1, all, or a protocol number other than tcp, udp, icmp, or 58 (ICMPv6), | ||
# traffic on all ports is allowed, regardless of any ports you specify | ||
from_port: 10050 # this value is ignored | ||
to_port: 10050 # this value is ignored | ||
cidr_ip: | ||
- 0.0.0.0/0 | ||
- name: example2 ec2 group | ||
amazon.aws.ec2_group: | ||
name: example | ||
description: an example EC2 group | ||
vpc_id: 12345 | ||
region: eu-west-1 | ||
aws_secret_key: SECRET | ||
aws_access_key: ACCESS | ||
rules_egress: | ||
- proto: tcp | ||
from_port: 80 | ||
to_port: 80 | ||
cidr_ip: 0.0.0.0/0 | ||
group_name: example-other | ||
# description to use if example-other needs to be created | ||
group_desc: other example EC2 group | ||
- name: example3 ec2 group | ||
amazon.aws.ec2_group: | ||
name: example | ||
description: an example EC2 group | ||
vpc_id: 12345 | ||
region: eu-west-1 | ||
aws_secret_key: SECRET | ||
aws_access_key: ACCESS | ||
rules: | ||
- proto: all | ||
# in the 'proto' attribute, if you specify -1, all, or a protocol number other than tcp, udp, icmp, or 58 (ICMPv6), | ||
# traffic on all ports is allowed, regardless of any ports you specify | ||
from_port: 10050 # this value is ignored | ||
to_port: 10050 # this value is ignored | ||
cidr_ipv6: ::/0 | ||
- name: example4 ec2 group | ||
amazon.aws.ec2_group: | ||
name: example | ||
description: an example EC2 group | ||
vpc_id: 12345 | ||
region: eu-west-1 | ||
aws_secret_key: SECRET | ||
aws_access_key: ACCESS | ||
rules_egress: | ||
- proto: tcp | ||
from_port: 80 | ||
to_port: 80 | ||
cidr_ipv6: ::/0 | ||
group_name: example-other | ||
# description to use if example-other needs to be created | ||
group_desc: other example EC2 group | ||
- name: example5 ec2 group | ||
amazon.aws.ec2_group: | ||
name: example | ||
description: an example EC2 group | ||
vpc_id: 12345 | ||
region: eu-west-1 | ||
aws_secret_key: SECRET | ||
aws_access_key: ACCESS | ||
rules: | ||
# 'ports' rule keyword was introduced in version 2.4. It accepts a single port value or a list of values including ranges (from_port-to_port). | ||
- proto: tcp | ||
ports: 22 | ||
group_name: example-vpn | ||
rules_egress: | ||
- proto: tcp | ||
from_port: 80 | ||
to_port: 80 | ||
cidr_ipv6: | ||
- ::/0 | ||
group_name: example-other | ||
# description to use if example-other needs to be created | ||
group_desc: other example EC2 group |
27 changes: 27 additions & 0 deletions
27
...s/default_security_group_does_not_restrict_all_traffic/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,27 @@ | ||
[ | ||
{ | ||
"queryName": "Default Security Group Does Not Restrict All Traffic", | ||
"severity": "HIGH", | ||
"line": 17 | ||
}, | ||
{ | ||
"queryName": "Default Security Group Does Not Restrict All Traffic", | ||
"severity": "HIGH", | ||
"line": 30 | ||
}, | ||
{ | ||
"queryName": "Default Security Group Does Not Restrict All Traffic", | ||
"severity": "HIGH", | ||
"line": 48 | ||
}, | ||
{ | ||
"queryName": "Default Security Group Does Not Restrict All Traffic", | ||
"severity": "HIGH", | ||
"line": 61 | ||
}, | ||
{ | ||
"queryName": "Default Security Group Does Not Restrict All Traffic", | ||
"severity": "HIGH", | ||
"line": 83 | ||
} | ||
] |
8 changes: 8 additions & 0 deletions
8
assets/queries/ansible/aws/elasticsearch_encryption_at_rest_enabled/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,8 @@ | ||
{ | ||
"id": "ElasticSearch_Not_Encrypted_At_Rest", | ||
"queryName": "ElasticSearch Not Encrypted At Rest", | ||
"severity": "MEDIUM", | ||
"category": "Encryption and Key Management", | ||
"descriptionText": "Check if ElasticSearch encryption is disabled at Rest", | ||
"descriptionUrl": "https://galaxy.ansible.com/fiunchinho/aws-elasticsearch-module" | ||
} |
Oops, something went wrong.