From 5257ce6c0bfe13cdf218458ad015917052690ad9 Mon Sep 17 00:00:00 2001 From: Marcel Beck Date: Fri, 28 Feb 2020 17:58:10 +0100 Subject: [PATCH 1/6] docs: Fix typo --- checks/check_extra765 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks/check_extra765 b/checks/check_extra765 index 9cbb0930..1c4bb689 100644 --- a/checks/check_extra765 +++ b/checks/check_extra765 @@ -44,7 +44,7 @@ extra765(){ textFail "$region: ECR repository $repo has scan on push disabled!" "$region" ;; "None") - textInfo "$region: ECR repository $repo hs no scanOnPush status, newer awscli needed" "$region" + textInfo "$region: ECR repository $repo has no scanOnPush status, newer awscli needed" "$region" ;; "*") textInfo "$region: ECR repository $repo has unknown scanOnPush status \"$SCAN_ENABLED\"" "$region" From db260da8b0495426d08158526edd76dfb424d545 Mon Sep 17 00:00:00 2001 From: Marcel Beck Date: Fri, 28 Feb 2020 17:58:38 +0100 Subject: [PATCH 2/6] feat: New check for ecr image scan findings This will check if there is any ecr image with findings. --- checks/check_extra776 | 97 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 checks/check_extra776 diff --git a/checks/check_extra776 b/checks/check_extra776 new file mode 100644 index 00000000..cea4b84c --- /dev/null +++ b/checks/check_extra776 @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# Prowler - the handy cloud security tool (copyright 2018) by Toni de la Fuente +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +# Remediation: +# +# https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning.html +# +# aws ecr put-image-scanning-configuration \ +# --region \ +# --repository-name \ +# --image-scanning-configuration scanOnPush=true +# +# aws ecr describe-image-scan-findings \ +# --region \ +# --repository-name +# --image-id imageTag= + +CHECK_ID_extra776="7.76" +CHECK_TITLE_extra776="[extra776] Check if ECR image scan found vulnerabilities in the newest image version)" +CHECK_SCORED_extra776="NOT_SCORED" +CHECK_TYPE_extra776="EXTRA" +CHECK_ALTERNATE_check776="extra776" + +extra776(){ + for region in $REGIONS; do + LIST_ECR_REPOS=$($AWSCLI ecr describe-repositories $PROFILE_OPT --region $region --query "repositories[*].[repositoryName]" --output text 2>&1) + if [[ $(echo "$LIST_ECR_REPOS" | grep AccessDenied) ]]; then + textFail "Access Denied Trying to describe ECR repositories" + continue + fi + if [[ ! -z "$LIST_ECR_REPOS" ]]; then + for repo in $LIST_ECR_REPOS; do + SCAN_ENABLED=$($AWSCLI ecr describe-repositories $PROFILE_OPT --region $region --query "repositories[?repositoryName==\`$repo\`].[imageScanningConfiguration.scanOnPush]" --output text 2>&1) + if [[ "$SCAN_ENABLED" == "True" ]]; then + IMAGE_DIGEST=$($AWSCLI ecr describe-images $PROFILE_OPT --region $region --repository-name "$repo" --query "sort_by(imageDetails,& imagePushedAt)[-1].imageDigest" --output text 2>&1) + IMAGE_TAG=$($AWSCLI ecr describe-images $PROFILE_OPT --region $region --repository-name "$repo" --query "sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]" --output text 2>&1) + if [[ ! -z "$LIST_ECR_REPOS" ]]; then + IMAGE_SCAN_STATUS=$($AWSCLI ecr describe-image-scan-findings $PROFILE_OPT --region $region --repository-name "$repo" --image-id imageDigest="$IMAGE_DIGEST" --query "imageScanStatus.status" 2>&1) + if [[ $IMAGE_SCAN_STATUS == *"ScanNotFoundException"* ]]; then + textFail "$region: ECR repository $repo has imageTag $IMAGE_TAG without a scan" "$region" + else + if [[ $IMAGE_SCAN_STATUS == *"FAILED"* ]]; then + textFail "$region: ECR repository $repo has imageTag $IMAGE_TAG with scan status $IMAGE_SCAN_STATUS" "$region" + else + FINDINGS_COUNT=$($AWSCLI ecr describe-image-scan-findings $PROFILE_OPT --region $region --repository-name "$repo" --image-id imageDigest="$IMAGE_DIGEST" --query "imageScanFindings.findingSeverityCounts" 2>&1) + if [[ ! -z "$FINDINGS_COUNT" ]]; then + SEVERITY_CRITICAL=$(echo "$FINDINGS_COUNT" | jq -r '.CRITICAL' ) + if [[ "$SEVERITY_CRITICAL" != "null" ]]; then + textFail "$region: ECR repository $repo has imageTag $IMAGE_TAG with CRITICAL ($SEVERITY_CRITICAL) findings" "$region" + fi + SEVERITY_HIGH=$(echo "$FINDINGS_COUNT" | jq -r '.HIGH' ) + if [[ "$SEVERITY_HIGH" != "null" ]]; then + textFail "$region: ECR repository $repo has imageTag $IMAGE_TAG with HIGH ($SEVERITY_HIGH) findings" "$region" + fi + SEVERITY_MEDIUM=$(echo "$FINDINGS_COUNT" | jq -r '.MEDIUM' ) + if [[ "$SEVERITY_MEDIUM" != "null" ]]; then + textFail "$region: ECR repository $repo has imageTag $IMAGE_TAG with MEDIUM ($SEVERITY_MEDIUM) findings" "$region" + fi + SEVERITY_LOW=$(echo "$FINDINGS_COUNT" | jq -r '.LOW' ) + if [[ "$SEVERITY_LOW" != "null" ]]; then + textInfo "$region: ECR repository $repo has imageTag $IMAGE_TAG with LOW ($SEVERITY_LOW) findings" "$region" + fi + SEVERITY_INFORMATIONAL=$(echo "$FINDINGS_COUNT" | jq -r '.INFORMATIONAL' ) + if [[ "$SEVERITY_INFORMATIONAL" != "null" ]]; then + textInfo "$region: ECR repository $repo has imageTag $IMAGE_TAG with INFORMATIONAL ($SEVERITY_INFORMATIONAL) findings" "$region" + fi + SEVERITY_UNDEFINED=$(echo "$FINDINGS_COUNT" | jq -r '.UNDEFINED' ) + if [[ "$SEVERITY_UNDEFINED" != "null" ]]; then + textInfo "$region: ECR repository $repo has imageTag $IMAGE_TAG with UNDEFINED ($SEVERITY_UNDEFINED) findings" "$region" + fi + else + textPass "$region: ECR repository $repo has imageTag $IMAGE_TAG without findings" "$region" + fi + fi + fi + else + textInfo "$region: ECR repository $repo has no images" "$region" + fi + else + textInfo "$region: ECR repository $repo has no scanOnPush not enabled" "$region" + fi + done + else + textInfo "$region: No ECR repositories found" "$region" + fi + done +} From 4646dbcd0b9e0ed5d45a4f44b4650035d259e232 Mon Sep 17 00:00:00 2001 From: Toni de la Fuente Date: Tue, 3 Mar 2020 23:04:09 +0100 Subject: [PATCH 3/6] Updated check_extra776 title --- checks/check_extra776 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks/check_extra776 b/checks/check_extra776 index cea4b84c..369d6c54 100644 --- a/checks/check_extra776 +++ b/checks/check_extra776 @@ -26,7 +26,7 @@ # --image-id imageTag= CHECK_ID_extra776="7.76" -CHECK_TITLE_extra776="[extra776] Check if ECR image scan found vulnerabilities in the newest image version)" +CHECK_TITLE_extra776="[extra776] Check if ECR image scan found vulnerabilities in the newest image version (Not Scored) (Not part of CIS benchmark)" CHECK_SCORED_extra776="NOT_SCORED" CHECK_TYPE_extra776="EXTRA" CHECK_ALTERNATE_check776="extra776" From 95cb26fb2bf0d2b75f995b2ad1560d4561a5f9b2 Mon Sep 17 00:00:00 2001 From: Marcel Beck Date: Wed, 4 Mar 2020 07:27:40 +0100 Subject: [PATCH 4/6] fix: Enable check extra776 in extra group --- groups/group7_extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/groups/group7_extras b/groups/group7_extras index 37aa1d04..a1f88799 100644 --- a/groups/group7_extras +++ b/groups/group7_extras @@ -15,7 +15,7 @@ GROUP_ID[7]='extras' GROUP_NUMBER[7]='7.0' GROUP_TITLE[7]='Extras - [extras] **********************************************' GROUP_RUN_BY_DEFAULT[7]='Y' # run it when execute_all is called -GROUP_CHECKS[7]='extra71,extra72,extra73,extra74,extra75,extra76,extra77,extra78,extra79,extra710,extra711,extra712,extra713,extra714,extra715,extra716,extra717,extra718,extra719,extra720,extra721,extra722,extra723,extra724,extra725,extra726,extra727,extra728,extra729,extra730,extra731,extra732,extra733,extra734,extra735,extra736,extra737,extra738,extra739,extra740,extra741,extra742,extra743,extra744,extra745,extra746,extra747,extra748,extra749,extra750,extra751,extra752,extra753,extra754,extra755,extra756,extra757,extra758,extra761,extra762,extra763,extra764,extra765,extra767,extra768,extra769,extra770,extra771,extra772,extra773,extra774,extra775' +GROUP_CHECKS[7]='extra71,extra72,extra73,extra74,extra75,extra76,extra77,extra78,extra79,extra710,extra711,extra712,extra713,extra714,extra715,extra716,extra717,extra718,extra719,extra720,extra721,extra722,extra723,extra724,extra725,extra726,extra727,extra728,extra729,extra730,extra731,extra732,extra733,extra734,extra735,extra736,extra737,extra738,extra739,extra740,extra741,extra742,extra743,extra744,extra745,extra746,extra747,extra748,extra749,extra750,extra751,extra752,extra753,extra754,extra755,extra756,extra757,extra758,extra761,extra762,extra763,extra764,extra765,extra767,extra768,extra769,extra770,extra771,extra772,extra773,extra774,extra775,extra776' # Extras 759 and 760 (lambda variables and code secrets finder are not included) # to run detect-secrets use `./prowler -g secrets` From 8173c20941e983335f778b11aeba965b0c50d727 Mon Sep 17 00:00:00 2001 From: jonjozwiak Date: Wed, 4 Mar 2020 16:46:28 +0200 Subject: [PATCH 5/6] Improve performance of check_extra742 by limiting to one AWS CLI call --- checks/check_extra742 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/checks/check_extra742 b/checks/check_extra742 index 277eb435..8d78ab22 100644 --- a/checks/check_extra742 +++ b/checks/check_extra742 @@ -25,11 +25,13 @@ extra742(){ textInfo "Looking for secrets in CloudFormation output across all regions... " for regx in $REGIONS; do - LIST_OF_CFN_STACKS=$($AWSCLI cloudformation describe-stacks $PROFILE_OPT --region $regx --query Stacks[*].[StackName] --output text) + CFN_STACKS=$($AWSCLI cloudformation describe-stacks $PROFILE_OPT --region $regx) + LIST_OF_CFN_STACKS=$(echo $CFN_STACKS | jq -r '.Stacks[].StackName') if [[ $LIST_OF_CFN_STACKS ]];then for stack in $LIST_OF_CFN_STACKS; do CFN_OUTPUTS_FILE="$SECRETS_TEMP_FOLDER/extra742-$stack-$regx-outputs.txt" - CFN_OUTPUTS=$($AWSCLI $PROFILE_OPT --region $regx cloudformation describe-stacks --query "Stacks[?StackName==\`$stack\`].Outputs[*].[OutputKey,OutputValue]" --output text > $CFN_OUTPUTS_FILE) + echo $CFN_STACKS | jq --arg s "$stack" -r '.Stacks[] | select( .StackName == $s ) | .Outputs[]? | "\(.OutputKey) \(.OutputValue)"' > $CFN_OUTPUTS_FILE + if [ -s $CFN_OUTPUTS_FILE ];then # This finds ftp or http URLs with credentials and common keywords # FINDINGS=$(egrep -i '[[:alpha:]]*://[[:alnum:]]*:[[:alnum:]]*@.*/|key|secret|token|pass' $CFN_OUTPUTS_FILE |wc -l|tr -d '\ ') From 30941c355c6efbcc3b980a7aa4186d7b2af7afbb Mon Sep 17 00:00:00 2001 From: Toni de la Fuente Date: Mon, 23 Mar 2020 14:39:23 +0100 Subject: [PATCH 6/6] Added extra777 - Security Groups with too many rules @renuez --- checks/check_extra777 | 58 +++++++++++++++++++++++++++++++++++++++++++ groups/group7_extras | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 checks/check_extra777 diff --git a/checks/check_extra777 b/checks/check_extra777 new file mode 100755 index 00000000..1ccf541f --- /dev/null +++ b/checks/check_extra777 @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +# Prowler - the handy cloud security tool (copyright 2020) by Toni de la Fuente +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +# Current VPC Limit is 120 rules (60 inbound and 60 outbound) +# Reference: https://docs.aws.amazon.com/vpc/latest/userguide/amazon-vpc-limits.html + +CHECK_ID_extra777="7.77" +CHECK_TITLE_extra777="[extra777] Find VPC security groups with many ingress or egress rules (Not Scored) (Not part of CIS benchmark)" +CHECK_SCORED_extra777="NOT_SCORED" +CHECK_TYPE_extra777="EXTRA" +CHECK_ALTERNATE_check777="extra777" + +extra777(){ + THRESHOLD=50 + textInfo "Looking for VPC security groups with more than ${THRESHOLD} rules across all regions... " + + for regx in ${REGIONS}; do + SECURITY_GROUP_IDS=$(${AWSCLI} ec2 describe-security-groups \ + ${PROFILE_OPT} \ + --region ${regx} \ + --query 'SecurityGroups[*].GroupId' \ + --output text | xargs + ) + + for SECURITY_GROUP in ${SECURITY_GROUP_IDS}; do + + INGRESS_TOTAL=$(${AWSCLI} ec2 describe-security-groups \ + ${PROFILE_OPT} \ + --filter "Name=group-id,Values=${SECURITY_GROUP}" \ + --query "SecurityGroups[*].IpPermissions[*].IpRanges" \ + --region ${regx} \ + --output text | wc -l | xargs + ) + + EGRESS_TOTAL=$(${AWSCLI} ec2 describe-security-groups \ + ${PROFILE_OPT} \ + --filter "Name=group-id,Values=${SECURITY_GROUP}" \ + --query "SecurityGroups[*].IpPermissionsEgress[*].IpRanges" \ + --region ${regx} \ + --output text | wc -l | xargs + ) + + if [[ (${INGRESS_TOTAL} -ge ${THRESHOLD}) || (${EGRESS_TOTAL} -ge ${THRESHOLD}) ]]; then + textFail "${regx}: ${SECURITY_GROUP} has ${INGRESS_TOTAL} inbound rules and ${EGRESS_TOTAL} outbound rules." "${regx}" + fi + done + done +} \ No newline at end of file diff --git a/groups/group7_extras b/groups/group7_extras index a1f88799..5af1d58b 100644 --- a/groups/group7_extras +++ b/groups/group7_extras @@ -15,7 +15,7 @@ GROUP_ID[7]='extras' GROUP_NUMBER[7]='7.0' GROUP_TITLE[7]='Extras - [extras] **********************************************' GROUP_RUN_BY_DEFAULT[7]='Y' # run it when execute_all is called -GROUP_CHECKS[7]='extra71,extra72,extra73,extra74,extra75,extra76,extra77,extra78,extra79,extra710,extra711,extra712,extra713,extra714,extra715,extra716,extra717,extra718,extra719,extra720,extra721,extra722,extra723,extra724,extra725,extra726,extra727,extra728,extra729,extra730,extra731,extra732,extra733,extra734,extra735,extra736,extra737,extra738,extra739,extra740,extra741,extra742,extra743,extra744,extra745,extra746,extra747,extra748,extra749,extra750,extra751,extra752,extra753,extra754,extra755,extra756,extra757,extra758,extra761,extra762,extra763,extra764,extra765,extra767,extra768,extra769,extra770,extra771,extra772,extra773,extra774,extra775,extra776' +GROUP_CHECKS[7]='extra71,extra72,extra73,extra74,extra75,extra76,extra77,extra78,extra79,extra710,extra711,extra712,extra713,extra714,extra715,extra716,extra717,extra718,extra719,extra720,extra721,extra722,extra723,extra724,extra725,extra726,extra727,extra728,extra729,extra730,extra731,extra732,extra733,extra734,extra735,extra736,extra737,extra738,extra739,extra740,extra741,extra742,extra743,extra744,extra745,extra746,extra747,extra748,extra749,extra750,extra751,extra752,extra753,extra754,extra755,extra756,extra757,extra758,extra761,extra762,extra763,extra764,extra765,extra767,extra768,extra769,extra770,extra771,extra772,extra773,extra774,extra775,extra776,extra777' # Extras 759 and 760 (lambda variables and code secrets finder are not included) # to run detect-secrets use `./prowler -g secrets`