@@ -15,15 +15,15 @@ upcheck_elasticsearch() {
15
15
while [ " $RECHECK " = true ]; do
16
16
touch /tmp/esupcheck.txt
17
17
# TODO: add certificate check
18
- $CURL -XGET ' https://redelk-elasticsearch:9200/' -o /tmp/esupcheck.txt >> $LOGFILE 2>&1
18
+ $CURL -XGET ' https://redelk-elasticsearch:9200/' -o /tmp/esupcheck.txt >> $LOGFILE 2>&1
19
19
if [ -n " $( grep ' name' /tmp/esupcheck.txt) " ]; then
20
20
RECHECK=false
21
21
else
22
22
echo " [!] Elasticsearch not up, sleeping another few seconds." | tee -a $LOGFILE
23
23
sleep 10
24
- COUNTER=$(( COUNTER+ 1 ))
24
+ COUNTER=$(( COUNTER + 1 ))
25
25
if [ $COUNTER -eq " 30" ]; then
26
- echo " [!] Elasticsearch still not up, waited for way too long. Continuing and hoping for the best." | tee -a $LOGFILE
26
+ echo " [!] Elasticsearch still not up, waited for way too long. Continuing and hoping for the best." | tee -a $LOGFILE
27
27
RECHECK=false
28
28
fi
29
29
fi
@@ -37,15 +37,15 @@ upcheck_kibana() {
37
37
while [ " $RECHECK " = true ]; do
38
38
touch /tmp/kibanaupcheck.txt
39
39
# TODO: add certificate check
40
- $CURL -XGET ' https://redelk-kibana:5601/status' -I -o /tmp/kibanaupcheck.txt >> $LOGFILE 2>&1
40
+ $CURL -XGET ' https://redelk-kibana:5601/status' -I -o /tmp/kibanaupcheck.txt >> $LOGFILE 2>&1
41
41
if [ -n " $( grep ' 200 OK' /tmp/kibanaupcheck.txt) " ]; then
42
42
RECHECK=false
43
43
else
44
44
echo " [!] Kibana not up yet, sleeping another few seconds." | tee -a $LOGFILE
45
45
sleep 10
46
- COUNTER=$(( COUNTER+ 1 ))
46
+ COUNTER=$(( COUNTER + 1 ))
47
47
if [ $COUNTER -eq " 30" ]; then
48
- echo " [!] Kibana still not up, waited for way too long. Continuing and hoping for the best." | tee -a $LOGFILE
48
+ echo " [!] Kibana still not up, waited for way too long. Continuing and hoping for the best." | tee -a $LOGFILE
49
49
RECHECK=false
50
50
fi
51
51
fi
@@ -54,36 +54,36 @@ upcheck_kibana() {
54
54
}
55
55
56
56
# Start with echo to logfile
57
- echo " [*] ` date +' %b %e %R' ` Starting installer" | tee -a $LOGFILE
57
+ echo " [*] $( date +' %b %e %R' ) Starting installer" | tee -a $LOGFILE
58
58
59
59
# Check if redelk user already exists, if not create
60
- grep redelk /etc/passwd >> /dev/null
60
+ grep redelk /etc/passwd >> /dev/null
61
61
EXISTS=$?
62
- if [ ! $( grep redelk /etc/passwd ) >> /dev/null ] ; then
62
+ if [ ! $( grep redelk /etc/passwd) ] >> /dev/null; then
63
63
echo " [*] Adding redelk user" | tee -a $LOGFILE
64
- useradd -m -p $( openssl passwd -1 ` head /dev/urandom | tr -dc A-Za-z0-9 | head -c20` ) redelk && usermod -a -G www-data redelk >> $LOGFILE 2>&1
64
+ useradd -m -p $( openssl passwd -1 $( head /dev/urandom | tr -dc A-Za-z0-9 | head -c20) ) redelk && usermod -a -G www-data redelk >> $LOGFILE 2>&1
65
65
else
66
66
echo " [*] User redelk already exists, nothing to do" | tee -a $LOGFILE
67
67
fi
68
- echo " " >> $LOGFILE
68
+ echo " " >> $LOGFILE
69
69
70
70
# Set relevant permissions for redelk user
71
71
echo " [*] Setting dir permisisons for redelk user" | tee -a $LOGFILE
72
- chown -Rv redelk /var/log/redelk/ && chown -Rv redelk:www-data /var/www/html/c2logs && chown -Rv redelk /etc/redelk && chmod 2755 /var/www/html/c2logs >> $LOGFILE 2>&1
72
+ chown -Rv redelk /var/log/redelk/ && chown -Rv redelk:www-data /var/www/html/c2logs && chown -Rv redelk /etc/redelk && chmod 2755 /var/www/html/c2logs >> $LOGFILE 2>&1
73
73
ERROR=$?
74
74
if [ $ERROR -ne 0 ]; then
75
75
echo " [X] Could not set dir permissions for redelk user (Error Code: $ERROR )."
76
76
fi
77
- echo " " >> $LOGFILE
77
+ echo " " >> $LOGFILE
78
78
79
79
# set ssh keys permissions
80
80
echo " [*] Setting ssh key persmisisons for redelk user" | tee -a $LOGFILE
81
- chown -R redelk:redelk /home/redelk/.ssh && chmod 700 /home/redelk/.ssh && chmod 600 /home/redelk/.ssh/id* >> $LOGFILE 2>&1
81
+ chown -R redelk:redelk /home/redelk/.ssh && chmod 700 /home/redelk/.ssh && chmod 600 /home/redelk/.ssh/id* >> $LOGFILE 2>&1
82
82
ERROR=$?
83
83
if [ $ERROR -ne 0 ]; then
84
84
echo " [X] Could not set ssh keypermissions for redelk user (Error Code: $ERROR )."
85
85
fi
86
- echo " " >> $LOGFILE
86
+ echo " " >> $LOGFILE
87
87
88
88
# First check if ES and Kibana are up before doing any followup step
89
89
upcheck_elasticsearch
@@ -92,128 +92,131 @@ upcheck_kibana
92
92
# Start with specifcs for elasticsearch
93
93
echo " [*] Installing Elasticsearch ILM policy" | tee -a $LOGFILE
94
94
upcheck_elasticsearch
95
- $CURL -X PUT " https://redelk-elasticsearch:9200/_ilm/policy/redelk" -H " Content-Type: application/json" -d @./root/redelkinstalldata/templates/redelk_elasticsearch_ilm.json >> $LOGFILE 2>&1
95
+ $CURL -X PUT " https://redelk-elasticsearch:9200/_ilm/policy/redelk" -H " Content-Type: application/json" -d @./root/redelkinstalldata/templates/redelk_elasticsearch_ilm.json >> $LOGFILE 2>&1
96
96
ERROR=$?
97
97
if [ $ERROR -ne 0 ]; then
98
98
echo " [X] Could not install Elasticsearch ILM policy (Error Code: $ERROR )."
99
99
fi
100
- echo " " >> $LOGFILE
100
+ echo " " >> $LOGFILE
101
101
102
102
echo " [*] Installing Elasticsearch index templates" | tee -a $LOGFILE
103
103
upcheck_elasticsearch
104
- for i in implantsdb rtops redirtraffic redelk email bluecheck credentials; do $CURL -X POST " https://redelk-elasticsearch:9200/_template/$i " -H " Content-Type: application/json" -d @./root/redelkinstalldata/templates/redelk_elasticsearch_template_$i .json; done >> $LOGFILE 2>&1
104
+ for i in ./root/redelkinstalldata/templates/redelk_elasticsearch_template_* .json; do
105
+ name=$( basename $i .json | sed ' s/redelk_elasticsearch_template_//' )
106
+ $CURL -X POST " https://redelk-elasticsearch:9200/_template/$name " -H " Content-Type: application/json" -d @$i
107
+ done >> $LOGFILE 2>&1
105
108
ERROR=$?
106
109
if [ $ERROR -ne 0 ]; then
107
110
echo " [X] Could not install Elasticsearch index templates (Error Code: $ERROR )."
108
111
fi
109
- echo " " >> $LOGFILE
112
+ echo " " >> $LOGFILE
110
113
111
114
# Now Kibana specifics
112
115
echo " [*] Preparing the SIEM signals index" | tee -a $LOGFILE
113
116
upcheck_kibana
114
- $CURL -X POST " https://redelk-kibana:5601/api/detection_engine/index" -H ' kbn-xsrf: true' >> $LOGFILE 2>&1
117
+ $CURL -X POST " https://redelk-kibana:5601/api/detection_engine/index" -H ' kbn-xsrf: true' >> $LOGFILE 2>&1
115
118
ERROR=$?
116
119
if [ $ERROR -ne 0 ]; then
117
120
echo " [X] Could not prepare the SIEM signals index (Error Code: $ERROR )."
118
121
fi
119
- echo " " >> $LOGFILE
122
+ echo " " >> $LOGFILE
120
123
121
124
echo " [*] Installing Kibana index patterns" | tee -a $LOGFILE
122
125
upcheck_kibana
123
126
for i in ./root/redelkinstalldata/templates/redelk_kibana_index-pattern* .ndjson; do
124
127
$CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@$i
125
128
sleep 1
126
- done >> $LOGFILE 2>&1
129
+ done >> $LOGFILE 2>&1
127
130
ERROR=$?
128
131
if [ $ERROR -ne 0 ]; then
129
132
echo " [X] Could not install Kibana index patterns (Error Code: $ERROR )."
130
133
fi
131
- echo " " >> $LOGFILE
134
+ echo " " >> $LOGFILE
132
135
133
136
echo " [*] Installing Kibana searches" | tee -a $LOGFILE
134
137
upcheck_kibana
135
- $CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_kibana_search.ndjson >> $LOGFILE 2>&1
138
+ $CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_kibana_search.ndjson >> $LOGFILE 2>&1
136
139
ERROR=$?
137
140
if [ $ERROR -ne 0 ]; then
138
141
echo " [X] Could not install Kibana searches (Error Code: $ERROR )."
139
142
fi
140
- echo " " >> $LOGFILE
143
+ echo " " >> $LOGFILE
141
144
142
145
echo " [*] Installing Kibana visualizations" | tee -a $LOGFILE
143
146
upcheck_kibana
144
- $CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_kibana_visualization.ndjson >> $LOGFILE 2>&1
147
+ $CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_kibana_visualization.ndjson >> $LOGFILE 2>&1
145
148
ERROR=$?
146
149
if [ $ERROR -ne 0 ]; then
147
150
echo " [X] Could not install Kibana visualizations (Error Code: $ERROR )."
148
151
fi
149
- echo " " >> $LOGFILE
152
+ echo " " >> $LOGFILE
150
153
151
154
echo " [*] Installing Kibana maps" | tee -a $LOGFILE
152
155
upcheck_kibana
153
- $CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_kibana_map.ndjson >> $LOGFILE 2>&1
156
+ $CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_kibana_map.ndjson >> $LOGFILE 2>&1
154
157
ERROR=$?
155
158
if [ $ERROR -ne 0 ]; then
156
159
echo " [X] Could not install Kibana maps (Error Code: $ERROR )."
157
160
fi
158
- echo " " >> $LOGFILE
161
+ echo " " >> $LOGFILE
159
162
160
163
echo " [*] Installing Kibana dashboards" | tee -a $LOGFILE
161
164
upcheck_kibana
162
- $CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_kibana_dashboard.ndjson >> $LOGFILE 2>&1
165
+ $CURL -X POST " https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_kibana_dashboard.ndjson >> $LOGFILE 2>&1
163
166
ERROR=$?
164
167
if [ $ERROR -ne 0 ]; then
165
168
echo " [X] Could not install Kibana dashboards (Error Code: $ERROR )."
166
169
fi
167
- echo " " >> $LOGFILE
170
+ echo " " >> $LOGFILE
168
171
169
172
echo " [*] Installing Kibana advanced settings" | tee -a $LOGFILE
170
173
upcheck_kibana
171
- $CURL -X POST " https://redelk-kibana:5601/api/kibana/settings" -H ' kbn-xsrf: true' -H ' Content-Type: application/json' --data @./root/redelkinstalldata/templates/redelk_kibana_settings.json >> $LOGFILE 2>&1
174
+ $CURL -X POST " https://redelk-kibana:5601/api/kibana/settings" -H ' kbn-xsrf: true' -H ' Content-Type: application/json' --data @./root/redelkinstalldata/templates/redelk_kibana_settings.json >> $LOGFILE 2>&1
172
175
ERROR=$?
173
176
if [ $ERROR -ne 0 ]; then
174
- echo " [X] Could not install Kibana advanced settings (Error Code: $ERROR )."
177
+ echo " [X] Could not install Kibana advanced settings (Error Code: $ERROR )."
175
178
fi
176
- echo " " >> $LOGFILE
179
+ echo " " >> $LOGFILE
177
180
178
181
echo " [*] Disabling telemetry" | tee -a $LOGFILE
179
182
upcheck_kibana
180
- $CURL -X POST " https://redelk-kibana:5601/api/telemetry/v2/optIn" -H ' kbn-xsrf: true' -H ' Content-Type: application/json' --data ' {"enabled":false}' >> $LOGFILE 2>&1
183
+ $CURL -X POST " https://redelk-kibana:5601/api/telemetry/v2/optIn" -H ' kbn-xsrf: true' -H ' Content-Type: application/json' --data ' {"enabled":false}' >> $LOGFILE 2>&1
181
184
ERROR=$?
182
185
if [ $ERROR -ne 0 ]; then
183
- echo " [X] Could not disable Kibana telemetry (Error Code: $ERROR )."
186
+ echo " [X] Could not disable Kibana telemetry (Error Code: $ERROR )."
184
187
fi
185
- echo " " >> $LOGFILE
188
+ echo " " >> $LOGFILE
186
189
187
190
echo " [*] Installing Kibana SIEM detection rules (for MITRE ATT&CK mapping)" | tee -a $LOGFILE
188
191
upcheck_kibana
189
- $CURL -X POST " https://redelk-kibana:5601/api/detection_engine/rules/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_siem_detection_rules.ndjson >> $LOGFILE 2>&1
192
+ $CURL -X POST " https://redelk-kibana:5601/api/detection_engine/rules/_import?overwrite=true" -H ' kbn-xsrf: true' -F file=@./root/redelkinstalldata/templates/redelk_siem_detection_rules.ndjson >> $LOGFILE 2>&1
190
193
ERROR=$?
191
194
if [ $ERROR -ne 0 ]; then
192
195
echo " [X] Could not install Kibana SIEM detection rules (Error Code: $ERROR )."
193
196
fi
194
- echo " " >> $LOGFILE
197
+ echo " " >> $LOGFILE
195
198
196
199
echo " [*] Inserting the superawesomesauce RedELK logo into Kibana" | tee -a $LOGFILE
197
200
upcheck_kibana
198
- $CURL ' https://redelk-kibana:5601/api/spaces/space/default?overwrite=true' -H ' kbn-xsrf: true' -X PUT -H ' Content-Type: application/json' -d @./root/redelkinstalldata/kibana/redelklogo.json >> $LOGFILE 2>&1
201
+ $CURL ' https://redelk-kibana:5601/api/spaces/space/default?overwrite=true' -H ' kbn-xsrf: true' -X PUT -H ' Content-Type: application/json' -d @./root/redelkinstalldata/kibana/redelklogo.json >> $LOGFILE 2>&1
199
202
ERROR=$?
200
203
if [ $ERROR -ne 0 ]; then
201
204
echo " [X] Could not adjust Kibana logo (Error Code: $ERROR )."
202
205
fi
203
- echo " " >> $LOGFILE
206
+ echo " " >> $LOGFILE
204
207
205
208
echo " [*] Fixing cron file permissions" | tee -a $LOGFILE
206
- chown root:root /etc/cron.d/redelk >> $LOGFILE 2>&1
209
+ chown root:root /etc/cron.d/redelk >> $LOGFILE 2>&1
207
210
ERROR=$?
208
211
if [ $ERROR -ne 0 ]; then
209
212
echo " [X] Could not fix cron file permissions (Error Code: $ERROR )."
210
213
fi
211
- echo " " >> $LOGFILE
214
+ echo " " >> $LOGFILE
212
215
213
216
# End with echo to logfile and some white lines
214
- echo " [*] ` date +' %b %e %R' ` Installer finished" | tee -a $LOGFILE
215
- echo " " >> $LOGFILE
216
- echo " " >> $LOGFILE
217
- echo " " >> $LOGFILE
218
- echo " " >> $LOGFILE
219
- echo " " >> $LOGFILE
217
+ echo " [*] $( date +' %b %e %R' ) Installer finished" | tee -a $LOGFILE
218
+ echo " " >> $LOGFILE
219
+ echo " " >> $LOGFILE
220
+ echo " " >> $LOGFILE
221
+ echo " " >> $LOGFILE
222
+ echo " " >> $LOGFILE
0 commit comments