mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 23:05:05 +00:00
- Move Security Hub related code to a dedicated include/securityhub_integration file - Check that Security Hub is enabled in the target region before beginning checks when -S is specified - Add error handling to the batch-import-findings call - Add CHECK_ASFF_TYPE variables to all CIS checks to override the default - Add support for CHECK_ASFF_RESOURCE_TYPE variables which override the default 'AwsAccount' value for the resource a finding relates to. - Add CHECK_ASFF_RESOURCE_TYPE variables to all checks where there is a suitable value in the schema - Remove json-asff output for info messages as they are not appropriate for possible submission to Security Hub - Update the README to cover Security Hub integration - Add an IAM policy JSON document that provides the necessary BatchImportFindings permission for Security Hub - Remove trailing whitespace and periods in pass/fail messages to be consistent with the majority of messages, to prevent future tidy-up from changing the finding IDs
70 lines
3.4 KiB
Bash
70 lines
3.4 KiB
Bash
#!/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_extra741="7.41"
|
|
CHECK_TITLE_extra741="[extra741] Find secrets in EC2 User Data (Not Scored) (Not part of CIS benchmark)"
|
|
CHECK_SCORED_extra741="NOT_SCORED"
|
|
CHECK_TYPE_extra741="EXTRA"
|
|
CHECK_ASFF_RESOURCE_TYPE_extra741="AwsEc2Instance"
|
|
CHECK_ALTERNATE_check741="extra741"
|
|
|
|
extra741(){
|
|
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 User Data in instances across all regions... (max 100 instances per region use -m to increase it) "
|
|
for regx in $REGIONS; do
|
|
LIST_OF_EC2_INSTANCES=$($AWSCLI ec2 describe-instances $PROFILE_OPT --region $regx --query Reservations[*].Instances[*].InstanceId --output text --max-items $MAXITEMS | grep -v None)
|
|
if [[ $LIST_OF_EC2_INSTANCES ]];then
|
|
for instance in $LIST_OF_EC2_INSTANCES; do
|
|
EC2_USERDATA_FILE="$SECRETS_TEMP_FOLDER/extra741-$instance-userData.decoded"
|
|
EC2_USERDATA=$($AWSCLI ec2 describe-instance-attribute --attribute userData $PROFILE_OPT --region $regx --instance-id $instance --query UserData.Value --output text| grep -v ^None | decode_report > $EC2_USERDATA_FILE)
|
|
if [ -s $EC2_USERDATA_FILE ];then
|
|
FILE_FORMAT_ASCII=$(file -b $EC2_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_USERDATA_FILE |wc -l|tr -d '\ ')
|
|
# New implementation using https://github.com/Yelp/detect-secrets
|
|
if [[ $FILE_FORMAT_ASCII ]]; then
|
|
FINDINGS=$(secretsDetector file $EC2_USERDATA_FILE)
|
|
if [[ $FINDINGS -eq 0 ]]; then
|
|
textPass "$regx: No secrets found in $instance" "$regx"
|
|
# delete file if nothing interesting is there
|
|
rm -f $EC2_USERDATA_FILE
|
|
else
|
|
textFail "$regx: Potential secret found in $instance" "$regx"
|
|
# delete file to not leave trace, user must look at the instance User Data
|
|
rm -f $EC2_USERDATA_FILE
|
|
fi
|
|
else
|
|
mv $EC2_USERDATA_FILE $EC2_USERDATA_FILE.gz ; gunzip $EC2_USERDATA_FILE.gz
|
|
FINDINGS=$(secretsDetector file $EC2_USERDATA_FILE)
|
|
if [[ $FINDINGS -eq 0 ]]; then
|
|
textPass "$regx: No secrets found in $instance User Data" "$regx"
|
|
rm -f $EC2_USERDATA_FILE
|
|
else
|
|
textFail "$regx: Potential secret found in $instance" "$regx"
|
|
fi
|
|
fi
|
|
else
|
|
textPass "$regx: No secrets found in $instance User Data or it is empty" "$regx"
|
|
fi
|
|
done
|
|
else
|
|
textInfo "$regx: No EC2 instances found" "$regx"
|
|
fi
|
|
done
|
|
rm -rf $SECRETS_TEMP_FOLDER
|
|
}
|