-
Notifications
You must be signed in to change notification settings - Fork 0
/
EC-Disable-SecLog-Splunk.sh
executable file
·175 lines (131 loc) · 6.01 KB
/
EC-Disable-SecLog-Splunk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# --------------------------------------------------------
#
# Automates the following:
# - updates existing landing zone to remove push logs and alerts to C2 Splunk logs destinations
#
# Usage
#
# $ ./EC-Disable-SecLog-Splunk.sh --seclogprofile [Seclog Acc Profile]
#
#
#
#
#
# Version History
#
# v1.0.0 J Silva Initial Version
# --------------------------------------------------------
# --------------------
# Parameters
# --------------------
seclogprofile=${seclogprofile:-}
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
# echo $1 $2 // Optional to see the parameter:value result
fi
shift
done
# Script Spinner waiting for cloudformation completion
export i=1
export sp="/-\|"
AWS_REGION='eu-west-1'
ALL_REGIONS_EXCEPT_IRELAND='["ap-northeast-1","ap-northeast-2","ap-south-1","ap-southeast-1","ap-southeast-2","ca-central-1","eu-central-1","eu-west-2","eu-west-3","sa-east-1","us-east-1","us-east-2","us-west-1","us-west-2"]'
# parameters for scripts
CFN_LOG_TEMPLATE='CFN/EC-lz-config-cloudtrail-logging.yml'
CFN_GUARDDUTY_DETECTOR_TEMPLATE='CFN/EC-lz-guardDuty-detector.yml'
# ---------------------
# The command line help
# ---------------------
display_help() {
echo "Usage: $0 --seclogprofile [Seclog Acc Profile] --notificationemail [Notification Email]" >&2
echo
echo " Provide the account name of the central SecLog account as configured in your AWS profile,"
exit 1
}
update_seclog() {
# Getting SecLog Account Id
SECLOG_ACCOUNT_ID=`aws --profile $seclogprofile sts get-caller-identity --query 'Account' --output text`
echo ""
echo "- This script will configure a the SecLog account with following settings:"
echo " ----------------------------------------------------"
echo " SecLog Account to be configured: $seclogprofile"
echo " Security Notifications e-mail: $notificationemail"
echo " SecLog Account Id: $SECLOG_ACCOUNT_ID"
echo " in AWS Region: $AWS_REGION"
echo " ----------------------------------------------------"
echo ""
echo " If this is correct press enter to continue"
read -p " or CTRL-C to break"
# ------------------------------------
# Store notification-E-mail, OrgID, SecAccountID in SSM parameters
# ------------------------------------
echo ""
echo "- Storing SSM parameters for Seclog accunt and notification e-mail"
echo "--------------------------------------------------"
echo ""
echo " populating: "
echo " - /org/member/SecLogMasterAccountId"
echo " - /org/member/SecLog_notification-mail"
aws --profile $seclogprofile ssm put-parameter --name /org/member/SecLog_notification-mail --type String --value $notificationemail --overwrite
aws --profile $seclogprofile ssm put-parameter --name /org/member/SecLogMasterAccountId --type String --value $SECLOG_ACCOUNT_ID --overwrite
# ------------------------------------
# Creating config, cloudtrail, SNS notifications
# ------------------------------------
echo ""
echo "- Updating config, cloudtrail, SNS notifications"
echo "--------------------------------------------------"
echo ""
aws cloudformation update-stack \
--stack-name 'SECLZ-config-cloudtrail-SNS' \
--template-body file://$CFN_LOG_TEMPLATE \
--capabilities CAPABILITY_NAMED_IAM \
--profile $seclogprofile \
--parameters ParameterKey=EnableSecLogForCloudTrailParam,ParameterValue=false
StackName="SECLZ-config-cloudtrail-SNS"
aws --profile $seclogprofile cloudformation describe-stacks --query 'Stacks[*][StackName, StackStatus]' --output text | grep $StackName
while [ `aws --profile $seclogprofile cloudformation describe-stacks --query 'Stacks[*][StackName, StackStatus]' --output text | grep $StackName | awk '{print$2}'` == "UPDATE_IN_PROGRESS" ]; do printf "\b${sp:i++%${#sp}:1}"; sleep 1; done
aws --profile $seclogprofile cloudformation describe-stacks --query 'Stacks[*][StackName, StackStatus]' --output text | grep $StackName
sleep 5
# ------------------------------------
# Enable guardduty and securityhub in seclog master account
# ------------------------------------
echo ""
echo "- Enable guardduty in seclog master account"
echo "--------------------"
echo ""
aws cloudformation update-stack \
--stack-name 'SECLZ-Guardduty-detector' \
--template-body file://$CFN_GUARDDUTY_DETECTOR_TEMPLATE \
--capabilities CAPABILITY_IAM \
--profile $seclogprofile \
--parameters ParameterKey=EnableSecLogIntegrationFoGuardDutyParam,ParameterValue=false
sleep 5
# ------------------------------------
# Enable Cloudwatch Event Rules to Cloudwatch logs for Security Hub
# ------------------------------------
echo ""
echo "- Enable Cloudwatch Event Rules to Cloudwatch logs for Security Hub"
echo "---------------------------------------"
echo ""
aws cloudformation delete-stack \
--stack-name 'SECLZ-CloudwatchLogs-SecurityHub'
StackName="SECLZ-CloudwatchLogs-SecurityHub"
aws --profile $seclogprofile cloudformation describe-stacks --query 'Stacks[*][StackName, StackStatus]' --output text | grep $StackName
while [ `aws --profile $seclogprofile cloudformation describe-stacks --query 'Stacks[*][StackName, StackStatus]' --output text | grep $StackName | awk '{print$2}'` = "DELETE_IN_PROGRESS" ]; do printf "\b${sp:i++%${#sp}:1}"; sleep 1; done
aws --profile $seclogprofile cloudformation describe-stacks --query 'Stacks[*][StackName, StackStatus]' --output text | grep $StackName
sleep 5
}
# ---------------------------------------------
# Check if correct options are given
# on the commandline and start configurations
# ---------------------------------------------
# Simple check if two arguments are provided
if [ -z "$seclogprofile" ] || [ -z "$notificationemail" ]; then
display_help
exit 0
fi
#start account configuration
update_seclog