-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fredski-github-master'
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_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" | ||
|
||
extra775(){ | ||
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/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) | ||
# 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 | ||
} |
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
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