@@ -27,42 +27,44 @@ extra742(){
27
27
SECRETS_TEMP_FOLDER=" $PROWLER_DIR /secrets-$ACCOUNT_NUM "
28
28
if [[ ! -d $SECRETS_TEMP_FOLDER ]]; then
29
29
# this folder is deleted once this check is finished
30
- mkdir $ SECRETS_TEMP_FOLDER
30
+ mkdir " ${ SECRETS_TEMP_FOLDER} "
31
31
fi
32
32
33
33
for regx in $REGIONS ; do
34
- CFN_STACKS=$( $ AWSCLI cloudformation describe-stacks $PROFILE_OPT --region $ regx --output json 2>&1 )
35
- if [[ $( echo " $CFN_STACKS " | grep -E ' AccessDenied|UnauthorizedOperation|AuthorizationError' ) ]] ; then
34
+ CFN_STACKS=$( " ${ AWSCLI} " cloudformation describe-stacks $PROFILE_OPT --region " ${ regx} " --output json 2>&1 )
35
+ if grep -q - E ' AccessDenied|UnauthorizedOperation|AuthorizationError' <<< " $CFN_STACKS " ; then
36
36
textInfo " $regx : Access Denied trying to describe stacks" " $regx "
37
37
continue
38
- fi
39
- LIST_OF_CFN_STACKS=$( echo $CFN_STACKS | jq -r ' .Stacks[].StackName' )
38
+ fi
39
+ LIST_OF_CFN_STACKS=$( jq -r ' .Stacks[].StackName' <<< " ${CFN_STACKS} " )
40
40
if [[ $LIST_OF_CFN_STACKS ]]; then
41
- for stack in $LIST_OF_CFN_STACKS ; do
42
- CFN_OUTPUTS_FILE=" $SECRETS_TEMP_FOLDER /extra742-$stack -$regx -outputs.txt"
43
- echo $CFN_STACKS | jq --arg s " $stack " -r ' .Stacks[] | select( .StackName == $s ) | .Outputs[]? | "\(.OutputKey) \(.OutputValue)"' > $CFN_OUTPUTS_FILE
44
-
45
- if [ -s $CFN_OUTPUTS_FILE ]; then
46
- # This finds ftp or http URLs with credentials and common keywords
47
- # FINDINGS=$(egrep -i '[[:alpha:]]*://[[:alnum:]]*:[[:alnum:]]*@.*/|key|secret|token|pass' $CFN_OUTPUTS_FILE |wc -l|tr -d '\ ')
48
- # New implementation using https://github.com/Yelp/detect-secrets
49
- FINDINGS=$( secretsDetector file $CFN_OUTPUTS_FILE )
41
+ for stackName in $LIST_OF_CFN_STACKS ; do
42
+ CFN_OUTPUTS_FILE=" $SECRETS_TEMP_FOLDER /extra742-${stackName} -${regx} -outputs.txt"
43
+ # OutputKey and OutputValue are separated by a colon because secrets-detector needs a way to link both values
44
+ jq --arg stackName " $stackName " -r ' .Stacks[] | select( .StackName == $stackName ) | .Outputs[]? | "\(.OutputKey):\(.OutputValue)"' <<< " ${CFN_STACKS}" > " ${CFN_OUTPUTS_FILE} "
45
+ if [ -s " ${CFN_OUTPUTS_FILE} " ]; then
46
+ FINDINGS=$( secretsDetector file " ${CFN_OUTPUTS_FILE} " )
50
47
if [[ $FINDINGS -eq 0 ]]; then
51
- textPass " $regx : No secrets found in stack $stack Outputs" " $regx " " $stack "
52
- # delete file if nothing interesting is there
53
- rm -f $ CFN_OUTPUTS_FILE
48
+ textPass " $regx : No secrets found in stack ${stackName} Outputs" " $regx " " ${stackName} "
49
+ # Delete file if nothing interesting is there
50
+ rm -f " ${ CFN_OUTPUTS_FILE} "
54
51
else
55
- textFail " $regx : Potential secret found in stack $stack Outputs" " $regx " " $stack "
56
- # delete file to not leave trace, user must look at the CFN Stack
57
- rm -f $ CFN_OUTPUTS_FILE
52
+ textFail " $regx : Potential secret found in stack ${stackName} Outputs" " $regx " " ${stackName} "
53
+ # Delete file to not leave trace, user must look at the CFN Stack
54
+ rm -f " ${ CFN_OUTPUTS_FILE} "
58
55
fi
59
56
else
60
- textInfo " $regx : CloudFormation stack $stack has no Outputs" " $regx "
57
+ textInfo " $regx : CloudFormation stack ${stackName} has no Outputs" " $regx "
61
58
fi
62
59
done
63
60
else
64
61
textInfo " $regx : No CloudFormation stacks found" " $regx "
65
62
fi
66
63
done
67
- rm -rf $SECRETS_TEMP_FOLDER
64
+
65
+ # Cleanup temporary folder
66
+ if [[ -d $SECRETS_TEMP_FOLDER ]]
67
+ then
68
+ rm -rf " ${SECRETS_TEMP_FOLDER} "
69
+ fi
68
70
}
0 commit comments