-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(queries): add new aws iam privilege escalation queries (#5423)
* feat(queries): add new aws iam privilege escalation queries * change to KICS query file structure * add functions get_group, get_role, get_user, unrecommended_permission_policy_scenarios, unrecommended_permission_policy to common library * Titling queryName * fix descriptionUrl * fix positive tests * fix positive tests expected result * change iam privilege escalation folders names * add resourceType and resourceName * fix rego import and role/user/group reference * Add links in description Co-authored-by: gafnit <agafnit@gmail.com>
- Loading branch information
1 parent
1216dc9
commit 4006b83
Showing
286 changed files
with
5,543 additions
and
0 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
11 changes: 11 additions & 0 deletions
11
...aform/aws/group_with_privilege_escalation_by_actions_glue_UpdateDevEndpoint/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": "8f3c16b3-354d-45db-8ad5-5066778a9485", | ||
"queryName": "Group With Privilege Escalation By Actions 'glue:UpdateDevEndpoint'", | ||
"severity": "MEDIUM", | ||
"category": "Access Control", | ||
"descriptionText": "Group with privilege escalation by actions 'glue:UpdateDevEndpoint' and Resource set to '*'. For more information see https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/.", | ||
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_group_policy#policy", | ||
"platform": "Terraform", | ||
"descriptionID": "10f17e18", | ||
"cloudProvider": "aws" | ||
} |
24 changes: 24 additions & 0 deletions
24
...erraform/aws/group_with_privilege_escalation_by_actions_glue_UpdateDevEndpoint/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,24 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
import data.generic.terraform as tf_lib | ||
|
||
CxPolicy[result] { | ||
|
||
# get a AWS IAM group | ||
group := input.document[i].resource.aws_iam_group[targetGroup] | ||
|
||
common_lib.group_unrecommended_permission_policy_scenarios(targetGroup, "glue:UpdateDevEndpoint") | ||
|
||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "aws_iam_group", | ||
"resourceName": tf_lib.get_resource_name(group, targetGroup), | ||
"searchKey": sprintf("aws_iam_group[%s]", [targetGroup]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": sprintf("group %s is not associated with a policy that has Action set to 'glue:UpdateDevEndpoint' and Resource set to '*'", [targetGroup]), | ||
"keyActualValue": sprintf("group %s is associated with a policy that has Action set to 'glue:UpdateDevEndpoint' and Resource set to '*'", [targetGroup]), | ||
"searchLine": common_lib.build_search_line(["resource", "aws_iam_group", targetGroup], []), | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...m/aws/group_with_privilege_escalation_by_actions_glue_UpdateDevEndpoint/test/negative1.tf
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,21 @@ | ||
resource "aws_iam_user" "cosmic2" { | ||
name = "cosmic2" | ||
} | ||
|
||
resource "aws_iam_user_policy" "inline_policy_run_instances2" { | ||
name = "inline_policy_run_instances" | ||
user = aws_iam_user.cosmic2.name | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"ec2:Describe*", | ||
] | ||
Effect = "Allow" | ||
Resource = "*" | ||
}, | ||
] | ||
}) | ||
} |
21 changes: 21 additions & 0 deletions
21
...m/aws/group_with_privilege_escalation_by_actions_glue_UpdateDevEndpoint/test/positive1.tf
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,21 @@ | ||
resource "aws_iam_group" "cosmic" { | ||
name = "cosmic" | ||
} | ||
|
||
resource "aws_iam_group_policy" "test_inline_policy" { | ||
name = "test_inline_policy" | ||
group = aws_iam_group.cosmic.name | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"glue:UpdateDevEndpoint", | ||
] | ||
Effect = "Allow" | ||
Resource = "*" | ||
}, | ||
] | ||
}) | ||
} |
8 changes: 8 additions & 0 deletions
8
...privilege_escalation_by_actions_glue_UpdateDevEndpoint/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,8 @@ | ||
[ | ||
{ | ||
"queryName": "Group With Privilege Escalation By Actions 'glue:UpdateDevEndpoint'", | ||
"severity": "MEDIUM", | ||
"line": 1, | ||
"fileName": "positive1.tf" | ||
} | ||
] |
11 changes: 11 additions & 0 deletions
11
...terraform/aws/group_with_privilege_escalation_by_actions_iam_AddUserToGroup/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": "970ed7a2-0aca-4425-acf1-0453c9ecbca1", | ||
"queryName": "Group With Privilege Escalation By Actions 'iam:AddUserToGroup'", | ||
"severity": "MEDIUM", | ||
"category": "Access Control", | ||
"descriptionText": "Group with privilege escalation by actions 'iam:AddUserToGroup' and Resource set to '*'. For more information see https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/.", | ||
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_group_policy#policy", | ||
"platform": "Terraform", | ||
"descriptionID": "576ba016", | ||
"cloudProvider": "aws" | ||
} |
24 changes: 24 additions & 0 deletions
24
...es/terraform/aws/group_with_privilege_escalation_by_actions_iam_AddUserToGroup/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,24 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
import data.generic.terraform as tf_lib | ||
|
||
CxPolicy[result] { | ||
|
||
# get a AWS IAM group | ||
group := input.document[i].resource.aws_iam_group[targetGroup] | ||
|
||
common_lib.group_unrecommended_permission_policy_scenarios(targetGroup, "iam:AddUserToGroup") | ||
|
||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "aws_iam_group", | ||
"resourceName": tf_lib.get_resource_name(group, targetGroup), | ||
"searchKey": sprintf("aws_iam_group[%s]", [targetGroup]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": sprintf("group %s is not associated with a policy that has Action set to 'iam:AddUserToGroup' and Resource set to '*'", [targetGroup]), | ||
"keyActualValue": sprintf("group %s is associated with a policy that has Action set to 'iam:AddUserToGroup' and Resource set to '*'", [targetGroup]), | ||
"searchLine": common_lib.build_search_line(["resource", "aws_iam_group", targetGroup], []), | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...aform/aws/group_with_privilege_escalation_by_actions_iam_AddUserToGroup/test/negative1.tf
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,21 @@ | ||
resource "aws_iam_user" "cosmic2" { | ||
name = "cosmic2" | ||
} | ||
|
||
resource "aws_iam_user_policy" "inline_policy_run_instances2" { | ||
name = "inline_policy_run_instances" | ||
user = aws_iam_user.cosmic2.name | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"ec2:Describe*", | ||
] | ||
Effect = "Allow" | ||
Resource = "*" | ||
}, | ||
] | ||
}) | ||
} |
21 changes: 21 additions & 0 deletions
21
...aform/aws/group_with_privilege_escalation_by_actions_iam_AddUserToGroup/test/positive1.tf
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,21 @@ | ||
resource "aws_iam_group" "cosmic" { | ||
name = "cosmic" | ||
} | ||
|
||
resource "aws_iam_group_policy" "test_inline_policy" { | ||
name = "test_inline_policy" | ||
group = aws_iam_group.cosmic.name | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"iam:AddUserToGroup", | ||
] | ||
Effect = "Allow" | ||
Resource = "*" | ||
}, | ||
] | ||
}) | ||
} |
8 changes: 8 additions & 0 deletions
8
...ith_privilege_escalation_by_actions_iam_AddUserToGroup/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,8 @@ | ||
[ | ||
{ | ||
"queryName": "Group With Privilege Escalation By Actions 'iam:AddUserToGroup'", | ||
"severity": "MEDIUM", | ||
"line": 1, | ||
"fileName": "positive1.tf" | ||
} | ||
] |
11 changes: 11 additions & 0 deletions
11
...raform/aws/group_with_privilege_escalation_by_actions_iam_AttachGroupPolicy/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": "70b42736-efee-4bce-80d5-50358ed94990", | ||
"queryName": "Group With Privilege Escalation By Actions 'iam:AttachGroupPolicy'", | ||
"severity": "MEDIUM", | ||
"category": "Access Control", | ||
"descriptionText": "Group with privilege escalation by actions 'iam:AttachGroupPolicy' and Resource set to '*'. For more information see https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/.", | ||
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_group_policy#policy", | ||
"platform": "Terraform", | ||
"descriptionID": "e42aec0c", | ||
"cloudProvider": "aws" | ||
} |
24 changes: 24 additions & 0 deletions
24
...terraform/aws/group_with_privilege_escalation_by_actions_iam_AttachGroupPolicy/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,24 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
import data.generic.terraform as tf_lib | ||
|
||
CxPolicy[result] { | ||
|
||
# get a AWS IAM group | ||
group := input.document[i].resource.aws_iam_group[targetGroup] | ||
|
||
common_lib.group_unrecommended_permission_policy_scenarios(targetGroup, "iam:AttachGroupPolicy") | ||
|
||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "aws_iam_group", | ||
"resourceName": tf_lib.get_resource_name(group, targetGroup), | ||
"searchKey": sprintf("aws_iam_group[%s]", [targetGroup]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": sprintf("group %s is not associated with a policy that has Action set to 'iam:AttachGroupPolicy' and Resource set to '*'", [targetGroup]), | ||
"keyActualValue": sprintf("group %s is associated with a policy that has Action set to 'iam:AttachGroupPolicy' and Resource set to '*'", [targetGroup]), | ||
"searchLine": common_lib.build_search_line(["resource", "aws_iam_group", targetGroup], []), | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...rm/aws/group_with_privilege_escalation_by_actions_iam_AttachGroupPolicy/test/negative1.tf
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,21 @@ | ||
resource "aws_iam_user" "cosmic2" { | ||
name = "cosmic2" | ||
} | ||
|
||
resource "aws_iam_user_policy" "inline_policy_run_instances2" { | ||
name = "inline_policy_run_instances" | ||
user = aws_iam_user.cosmic2.name | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"ec2:Describe*", | ||
] | ||
Effect = "Allow" | ||
Resource = "*" | ||
}, | ||
] | ||
}) | ||
} |
23 changes: 23 additions & 0 deletions
23
...rm/aws/group_with_privilege_escalation_by_actions_iam_AttachGroupPolicy/test/positive1.tf
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,23 @@ | ||
resource "aws_iam_group" "cosmic" { | ||
name = "cosmic" | ||
} | ||
|
||
resource "aws_iam_group_policy" "test_inline_policy" { | ||
name = "test_inline_policy" | ||
group = aws_iam_group.cosmic.name | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"iam:AttachGroupPolicy", | ||
] | ||
Effect = "Allow" | ||
Resource = "*" | ||
}, | ||
] | ||
}) | ||
} | ||
|
||
|
8 changes: 8 additions & 0 deletions
8
..._privilege_escalation_by_actions_iam_AttachGroupPolicy/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,8 @@ | ||
[ | ||
{ | ||
"queryName": "Group With Privilege Escalation By Actions 'iam:AttachGroupPolicy'", | ||
"severity": "MEDIUM", | ||
"line": 1, | ||
"fileName": "positive1.tf" | ||
} | ||
] |
Oops, something went wrong.