From 4a1d4060eca2f3a117f825935b6a112577800404 Mon Sep 17 00:00:00 2001 From: Christopher Morrow Date: Thu, 20 Feb 2020 15:11:13 -0800 Subject: [PATCH 01/13] Check Extra 774 - Fixed bug - was checking account creation time instead of last logon date. --- checks/check_extra774 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/checks/check_extra774 b/checks/check_extra774 index baae7869a9..6902415d9b 100644 --- a/checks/check_extra774 +++ b/checks/check_extra774 @@ -21,8 +21,8 @@ extra774(){ LIST_USERS_WITH_PASSWORD_ENABLED=$(cat $TEMP_REPORT_FILE|awk -F, '{ print $1,$4,$5 }' |grep true | awk '{ print $1 }') for i in $LIST_USERS_WITH_PASSWORD_ENABLED; do - user=$(cat $TEMP_REPORT_FILE|awk -F, '{ print $1,$3 }' |grep "^$i " |awk '{ print $1 }') - last_login_date=$(cat $TEMP_REPORT_FILE|awk -F, '{ print $1,$3 }' |grep "^$i " |awk '{ print $2 }') + user=$(cat $TEMP_REPORT_FILE|awk -F, '{ print $1,$5 }' |grep "^$i " |awk '{ print $1 }') + last_login_date=$(cat $TEMP_REPORT_FILE|awk -F, '{ print $1,$5 }' |grep "^$i " |awk '{ print $2 }') days_not_in_use=$(how_many_days_from_today ${last_login_date%T*}) if [ "$days_not_in_use" -lt "$MAX_DAYS" ];then From a1d26b44c338058b72bcc98da0789fa49c724c06 Mon Sep 17 00:00:00 2001 From: Kasprzykowski Date: Fri, 21 Feb 2020 09:05:33 -0500 Subject: [PATCH 02/13] check_extra999 added and group7_extras updated --- .DS_Store | Bin 0 -> 6148 bytes checks/check_extra999 | 68 ++++++++++++++++++++++++++++++++++++++++++ groups/group7_extras | 2 +- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 checks/check_extra999 diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..72e2ac53daa48dade914cb862f55591f4abcbff7 GIT binary patch literal 6148 zcmeHK%Sr=55Ukb^0$y_TIKSW@3?Y7jKOiQeU|_|N`=0V$ewx(}khppYcnQ_eT{FF1 zGi)8Uw*lDdu)PD802Xvd96e0UpSw@&sxpoiXS`v*-EVeJ!?2rF|DJH}92>minehjI zju(7jzya^y2lFPG6p#W^Knh3!DR8y|)kzmOXP+RV6p#X!s(^nV8r`uMj*0QzE~o%@f34I3_Yfv!oJ}YBge5(wT2n*9*tQq{HH7o>MnlO(+((GvA^d))N(_ zfD|}Y;5xTU@BjDoKj!~al6F!+3S5)|Hd{ZeSA3=Ft&^AYUfbx8bg%iOyKx;9hG@sc jXvf@mJHCygtZTmJ^IkY62A%n!6ZJFTy2zx!e=G0>-Vz&v literal 0 HcmV?d00001 diff --git a/checks/check_extra999 b/checks/check_extra999 new file mode 100644 index 0000000000..2b7cf285ed --- /dev/null +++ b/checks/check_extra999 @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +# Prowler - the handy cloud security tool (copyright 2019) 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. +CHECK_ID_extra999="0.00" +CHECK_TITLE_extra999="[extra999] Find secrets in EC2 Auto Scaling Launch Configuration (Not Scored) (Not part of CIS benchmark)" +CHECK_SCORED_extra999="NOT_SCORED" +CHECK_TYPE_extra999="EXTRA" +CHECK_ALTERNATE_check000="extra999" + +extra999(){ + SECRETS_TEMP_FOLDER="$PROWLER_DIR/secrets-$ACCOUNT_NUM" + if [[ ! -d $SECRETS_TEMP_FOLDER ]]; then + # this folder is deleted once this check is finished + mkdir $SECRETS_TEMP_FOLDER + fi + + textInfo "Looking for secrets in EC2 Auto Scaling Launch Configuration across all regions... (max 100 autoscaling_configurations per region use -m to increase it) " + for regx in $REGIONS; do + LIST_OF_EC2_AUTOSCALING=$($AWSCLI autoscaling describe-launch-configurations $PROFILE_OPT --region $regx --query LaunchConfigurations[*].LaunchConfigurationName --output text --max-items $MAXITEMS | grep -v None) + if [[ $LIST_OF_EC2_AUTOSCALING ]];then + for autoscaling_configuration in $LIST_OF_EC2_AUTOSCALING; do + EC2_AUTOSCALING_USERDATA_FILE="$SECRETS_TEMP_FOLDER/extra999-$autoscaling_configuration-userData.decoded" + EC2_AUTOSCALING_USERDATA=$($AWSCLI autoscaling describe-launch-configurations $PROFILE_OPT --launch-configuration-names $autoscaling_configuration --region $regx --query LaunchConfigurations[*].UserData --output text| grep -v ^None | decode_report > $EC2_AUTOSCALING_USERDATA_FILE) + if [ -s $EC2_AUTOSCALING_USERDATA_FILE ];then + FILE_FORMAT_ASCII=$(file -b $EC2_AUTOSCALING_USERDATA_FILE | grep ASCII) + # This finds ftp or http URLs with credentials and common keywords + # FINDINGS=$(egrep -i '[[:alpha:]]*://[[:alnum:]]*:[[:alnum:]]*@.*/|key|secret|token|pass' $EC2_AUTOSCALING_USERDATA_FILE |wc -l|tr -d '\ ') + # New implementation using https://github.com/Yelp/detect-secrets + if [[ $FILE_FORMAT_ASCII ]]; then + FINDINGS=$(secretsDetector file $EC2_AUTOSCALING_USERDATA_FILE) + if [[ $FINDINGS -eq 0 ]]; then + textPass "$regx: No secrets found in $autoscaling_configuration" "$regx" + # delete file if nothing interesting is there + rm -f $EC2_AUTOSCALING_USERDATA_FILE + else + textFail "$regx: Potential secret found in $autoscaling_configuration" "$regx" + # delete file to not leave trace, user must look at the autoscaling_configuration User Data + rm -f $EC2_AUTOSCALING_USERDATA_FILE + fi + else + mv $EC2_AUTOSCALING_USERDATA_FILE $EC2_AUTOSCALING_USERDATA_FILE.gz ; gunzip $EC2_AUTOSCALING_USERDATA_FILE.gz + FINDINGS=$(secretsDetector file $EC2_AUTOSCALING_USERDATA_FILE) + if [[ $FINDINGS -eq 0 ]]; then + textPass "$regx: No secrets found in $autoscaling_configuration User Data" "$regx" + rm -f $EC2_AUTOSCALING_USERDATA_FILE + else + textFail "$regx: Potential secret found in $autoscaling_configuration" "$regx" + fi + fi + else + textPass "$regx: No secrets found in $autoscaling_configuration User Data or it is empty" "$regx" + fi + done + else + textInfo "$regx: No EC2 autoscaling_configurations found" "$regx" + fi + done + rm -rf $SECRETS_TEMP_FOLDER +} diff --git a/groups/group7_extras b/groups/group7_extras index 84280f8e21..5e928c3a7e 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' +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,extra999' # Extras 759 and 760 (lambda variables and code secrets finder are not included) # to run detect-secrets use `./prowler -g secrets` From 11e5d44d9bcf306be8da5a4143f42e0c7623149a Mon Sep 17 00:00:00 2001 From: Toni de la Fuente Date: Fri, 21 Feb 2020 15:06:13 +0100 Subject: [PATCH 03/13] version 2.2.0 --- prowler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prowler b/prowler index 7a2c80b3d5..a3a8db27ce 100755 --- a/prowler +++ b/prowler @@ -32,7 +32,7 @@ OPTRED="" OPTNORMAL="" # Set the defaults variables -PROWLER_VERSION=2.1.0 +PROWLER_VERSION=2.2.0 PROWLER_DIR=$(dirname "$0") REGION="" From 40985212ab84454766141152d42bf610c08440fd Mon Sep 17 00:00:00 2001 From: Kasprzykowski Date: Fri, 21 Feb 2020 09:24:13 -0500 Subject: [PATCH 04/13] check_extra775 added | group7_extras and group11_secrets updated --- checks/{check_extra999 => check_extra775} | 14 +++++++------- groups/group11_secrets | 2 +- groups/group7_extras | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) rename checks/{check_extra999 => check_extra775} (93%) diff --git a/checks/check_extra999 b/checks/check_extra775 similarity index 93% rename from checks/check_extra999 rename to checks/check_extra775 index 2b7cf285ed..20da28497a 100644 --- a/checks/check_extra999 +++ b/checks/check_extra775 @@ -10,13 +10,13 @@ # 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. -CHECK_ID_extra999="0.00" -CHECK_TITLE_extra999="[extra999] Find secrets in EC2 Auto Scaling Launch Configuration (Not Scored) (Not part of CIS benchmark)" -CHECK_SCORED_extra999="NOT_SCORED" -CHECK_TYPE_extra999="EXTRA" -CHECK_ALTERNATE_check000="extra999" +CHECK_ID_extra775="0.00" +CHECK_TITLE_extra775="[extra775] Find secrets in EC2 Auto Scaling Launch Configuration (Not Scored) (Not part of CIS benchmark)" +CHECK_SCORED_extra775="NOT_SCORED" +CHECK_TYPE_extra775="EXTRA" +CHECK_ALTERNATE_check000="extra775" -extra999(){ +extra775(){ SECRETS_TEMP_FOLDER="$PROWLER_DIR/secrets-$ACCOUNT_NUM" if [[ ! -d $SECRETS_TEMP_FOLDER ]]; then # this folder is deleted once this check is finished @@ -28,7 +28,7 @@ extra999(){ LIST_OF_EC2_AUTOSCALING=$($AWSCLI autoscaling describe-launch-configurations $PROFILE_OPT --region $regx --query LaunchConfigurations[*].LaunchConfigurationName --output text --max-items $MAXITEMS | grep -v None) if [[ $LIST_OF_EC2_AUTOSCALING ]];then for autoscaling_configuration in $LIST_OF_EC2_AUTOSCALING; do - EC2_AUTOSCALING_USERDATA_FILE="$SECRETS_TEMP_FOLDER/extra999-$autoscaling_configuration-userData.decoded" + EC2_AUTOSCALING_USERDATA_FILE="$SECRETS_TEMP_FOLDER/extra775-$autoscaling_configuration-userData.decoded" EC2_AUTOSCALING_USERDATA=$($AWSCLI autoscaling describe-launch-configurations $PROFILE_OPT --launch-configuration-names $autoscaling_configuration --region $regx --query LaunchConfigurations[*].UserData --output text| grep -v ^None | decode_report > $EC2_AUTOSCALING_USERDATA_FILE) if [ -s $EC2_AUTOSCALING_USERDATA_FILE ];then FILE_FORMAT_ASCII=$(file -b $EC2_AUTOSCALING_USERDATA_FILE | grep ASCII) diff --git a/groups/group11_secrets b/groups/group11_secrets index b66a6f883c..24ceda0cff 100644 --- a/groups/group11_secrets +++ b/groups/group11_secrets @@ -15,7 +15,7 @@ GROUP_ID[11]='secrets' GROUP_NUMBER[11]='11.0' GROUP_TITLE[11]='Look for keys secrets or passwords around resources - [secrets] **' GROUP_RUN_BY_DEFAULT[11]='N' # but it runs when execute_all is called (default) -GROUP_CHECKS[11]='extra741,extra742,extra759,extra760,extra768' +GROUP_CHECKS[11]='extra741,extra742,extra759,extra760,extra768,extra775' # requires https://github.com/Yelp/detect-secrets # `pip install detect-secrets` diff --git a/groups/group7_extras b/groups/group7_extras index 5e928c3a7e..37aa1d0420 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,extra999' +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' # Extras 759 and 760 (lambda variables and code secrets finder are not included) # to run detect-secrets use `./prowler -g secrets` From 020374b6f9ba6041b05fa45635862c7832ea4e22 Mon Sep 17 00:00:00 2001 From: Faraz Angabini Date: Sat, 22 Feb 2020 22:10:52 -0800 Subject: [PATCH 05/13] deleted .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 72e2ac53daa48dade914cb862f55591f4abcbff7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%Sr=55Ukb^0$y_TIKSW@3?Y7jKOiQeU|_|N`=0V$ewx(}khppYcnQ_eT{FF1 zGi)8Uw*lDdu)PD802Xvd96e0UpSw@&sxpoiXS`v*-EVeJ!?2rF|DJH}92>minehjI zju(7jzya^y2lFPG6p#W^Knh3!DR8y|)kzmOXP+RV6p#X!s(^nV8r`uMj*0QzE~o%@f34I3_Yfv!oJ}YBge5(wT2n*9*tQq{HH7o>MnlO(+((GvA^d))N(_ zfD|}Y;5xTU@BjDoKj!~al6F!+3S5)|Hd{ZeSA3=Ft&^AYUfbx8bg%iOyKx;9hG@sc jXvf@mJHCygtZTmJ^IkY62A%n!6ZJFTy2zx!e=G0>-Vz&v From 7358e9cd7560f528625c36870d75318668647531 Mon Sep 17 00:00:00 2001 From: Faraz Angabini Date: Sat, 22 Feb 2020 22:12:44 -0800 Subject: [PATCH 06/13] added .gitignore for .DS_Store --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3dc461ab8e..c80f14d61e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ Sessionx.vim tags # Persistent undo [._]*.un~ + +# MacOs DS_Store +*.DS_Store \ No newline at end of file From 232165550306290cd95b57ef2f42c3995237e925 Mon Sep 17 00:00:00 2001 From: Faraz Angabini Date: Sat, 22 Feb 2020 22:16:59 -0800 Subject: [PATCH 07/13] fixed check numbers for 774,775 --- checks/check_extra774 | 2 +- checks/check_extra775 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/checks/check_extra774 b/checks/check_extra774 index 6902415d9b..83e2aa6fc3 100644 --- a/checks/check_extra774 +++ b/checks/check_extra774 @@ -10,7 +10,7 @@ # 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. -CHECK_ID_extra774="1.23" +CHECK_ID_extra774="7.74" CHECK_TITLE_extra774="[extra774] Check if user have unused console login" CHECK_SCORED_extra774="NOT_SCORED" CHECK_TYPE_extra774="EXTRA" diff --git a/checks/check_extra775 b/checks/check_extra775 index 20da28497a..319cdfe282 100644 --- a/checks/check_extra775 +++ b/checks/check_extra775 @@ -10,11 +10,11 @@ # 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. -CHECK_ID_extra775="0.00" +CHECK_ID_extra775="7.75" CHECK_TITLE_extra775="[extra775] Find secrets in EC2 Auto Scaling Launch Configuration (Not Scored) (Not part of CIS benchmark)" CHECK_SCORED_extra775="NOT_SCORED" CHECK_TYPE_extra775="EXTRA" -CHECK_ALTERNATE_check000="extra775" +CHECK_ALTERNATE_check775="extra775" extra775(){ SECRETS_TEMP_FOLDER="$PROWLER_DIR/secrets-$ACCOUNT_NUM" From c9508c28b39c62b85bbf23544cc0f60a88f84a6e Mon Sep 17 00:00:00 2001 From: Marcel Beck Date: Tue, 25 Feb 2020 09:23:55 +0100 Subject: [PATCH 08/13] fix: check119 needs to ignore terminated instances Terminated does not seem to have an instance profile. And its not possible to start a terminated instance again. --- checks/check119 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/checks/check119 b/checks/check119 index 015836e392..4dbc7fd0e0 100644 --- a/checks/check119 +++ b/checks/check119 @@ -16,16 +16,19 @@ CHECK_ALTERNATE_check119="check119" check119(){ for regx in $REGIONS; do - EC2_DATA=$($AWSCLI ec2 describe-instances $PROFILE_OPT --region $regx --query 'Reservations[].Instances[].[InstanceId, IamInstanceProfile.Arn]') - EC2_DATA=$(echo $EC2_DATA | jq '.[]|{InstanceId: .[0], ProfileArn: .[1]}') + EC2_DATA=$($AWSCLI ec2 describe-instances $PROFILE_OPT --region $regx --query 'Reservations[].Instances[].[InstanceId, IamInstanceProfile.Arn, State.Name]') + EC2_DATA=$(echo $EC2_DATA | jq '.[]|{InstanceId: .[0], ProfileArn: .[1], StateName: .[2]}') INSTANCE_LIST=$(echo $EC2_DATA | jq -r '.InstanceId') if [[ $INSTANCE_LIST ]]; then for instance in $INSTANCE_LIST; do - PROFILEARN=$(echo $EC2_DATA | jq -r --arg i "$instance" 'select(.InstanceId==$i)|.ProfileArn') - if [[ $PROFILEARN == "null" ]]; then - textFail "$regx: Instance $instance not associated with an instance role." $regx - else - textPass "$regx: Instance $instance associated with role ${PROFILEARN##*/}." $regx + STATE_NAME=$(echo $EC2_DATA | jq -r --arg i "$instance" 'select(.InstanceId==$i)|.StateName') + if [[ $STATE_NAME != "terminated" ]]; then + PROFILEARN=$(echo $EC2_DATA | jq -r --arg i "$instance" 'select(.InstanceId==$i)|.ProfileArn') + if [[ $PROFILEARN == "null" ]]; then + textFail "$regx: Instance $instance not associated with an instance role." $regx + else + textPass "$regx: Instance $instance associated with role ${PROFILEARN##*/}." $regx + fi fi done else From 5257ce6c0bfe13cdf218458ad015917052690ad9 Mon Sep 17 00:00:00 2001 From: Marcel Beck Date: Fri, 28 Feb 2020 17:58:10 +0100 Subject: [PATCH 09/13] 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 9cbb0930fd..1c4bb6899a 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 10/13] 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 0000000000..cea4b84c0e --- /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 11/13] 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 cea4b84c0e..369d6c54d2 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 12/13] 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 37aa1d0420..a1f88799db 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 13/13] 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 277eb43568..8d78ab228d 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 '\ ')