From bde94829287d9134382700184087ca14eb6f97c3 Mon Sep 17 00:00:00 2001 From: Toni de la Fuente Date: Tue, 12 Mar 2019 22:40:40 -0400 Subject: [PATCH] Added check extra742 to find keys in CloudFormation Outputs --- checks/check_extra742 | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 checks/check_extra742 diff --git a/checks/check_extra742 b/checks/check_extra742 new file mode 100644 index 00000000..b0ba818b --- /dev/null +++ b/checks/check_extra742 @@ -0,0 +1,47 @@ +#!/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. +CHECK_ID_extra742="7.42" +CHECK_TITLE_extra742="[extra742] Find keys in CloudFormation outputs (Not Scored) (Not part of CIS benchmark)" +CHECK_SCORED_extra742="NOT_SCORED" +CHECK_TYPE_extra742="EXTRA" +CHECK_ALTERNATE_check742="extra742" + +extra742(){ + textInfo "Looking for keys 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) + if [[ $LIST_OF_CFN_STACKS ]];then + for stack in $LIST_OF_CFN_STACKS; do + OUTPUTS_FILE=$stack-$regx-output.txt + OUTPUTS=$($AWSCLI $PROFILE_OPT --region $regx cloudformation describe-stacks --query "Stacks[?StackName==\`$stack\`].Outputs[*].[OutputKey,OutputValue]" --output text > $OUTPUTS_FILE) + if [ -s $OUTPUTS ];then + #FINDINGS=$(grep '[A-Za-z0-9]\{20,40\}' $USERDATA_FILE | grep -i -e key -e secret -e token -e pass - |wc -l|tr -d '\ ') + #FINDINGS=$(grep -i -e key -e secret -e token -e pass $USERDATA_FILE |wc -l|tr -d '\ ') + # This finds ftp or http URLs with credentials and common keywords + FINDINGS=$(egrep -i '[[:alpha:]]*://[[:alnum:]]*:[[:alnum:]]*@.*/|key|secret|token|pass' $OUTPUTS_FILE |wc -l|tr -d '\ ') + if [[ $FINDINGS -eq 0 ]]; then + textPass "$regx: No keys found in Stack $stack" "$regx" + # delete file if nothing interesting is there + rm -f $OUTPUTS_FILE + else + textFail "$regx: Found $FINDINGS keys in $stack! Check file $OUTPUTS_FILE" "$regx" + fi + else + textPass "$regx: Stack $stack has not Outputs" "$regx" + fi + done + else + textInfo "$regx: No CloudFormation stacks found" "$regx" + fi + done +}