Skip to content

Commit 9d8f150

Browse files
committed
Fixed domain categorization scripts + Elastic objects + various small fixes
Signed-off-by: fastlorenzo <[email protected]>
1 parent 796c26e commit 9d8f150

39 files changed

+741
-1076
lines changed

elkserver/docker/redelk-base/redelkinstalldata/42_redelk-base-docker-init.sh

+52-49
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ upcheck_elasticsearch() {
1515
while [ "$RECHECK" = true ]; do
1616
touch /tmp/esupcheck.txt
1717
#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
1919
if [ -n "$(grep 'name' /tmp/esupcheck.txt)" ]; then
2020
RECHECK=false
2121
else
2222
echo "[!] Elasticsearch not up, sleeping another few seconds." | tee -a $LOGFILE
2323
sleep 10
24-
COUNTER=$((COUNTER+1))
24+
COUNTER=$((COUNTER + 1))
2525
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
2727
RECHECK=false
2828
fi
2929
fi
@@ -37,15 +37,15 @@ upcheck_kibana() {
3737
while [ "$RECHECK" = true ]; do
3838
touch /tmp/kibanaupcheck.txt
3939
#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
4141
if [ -n "$(grep '200 OK' /tmp/kibanaupcheck.txt)" ]; then
4242
RECHECK=false
4343
else
4444
echo "[!] Kibana not up yet, sleeping another few seconds." | tee -a $LOGFILE
4545
sleep 10
46-
COUNTER=$((COUNTER+1))
46+
COUNTER=$((COUNTER + 1))
4747
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
4949
RECHECK=false
5050
fi
5151
fi
@@ -54,36 +54,36 @@ upcheck_kibana() {
5454
}
5555

5656
# 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
5858

5959
# Check if redelk user already exists, if not create
60-
grep redelk /etc/passwd >> /dev/null
60+
grep redelk /etc/passwd >>/dev/null
6161
EXISTS=$?
62-
if [ ! $(grep redelk /etc/passwd ) >> /dev/null ]; then
62+
if [ ! $(grep redelk /etc/passwd) ] >>/dev/null; then
6363
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
6565
else
6666
echo "[*] User redelk already exists, nothing to do" | tee -a $LOGFILE
6767
fi
68-
echo "" >> $LOGFILE
68+
echo "" >>$LOGFILE
6969

7070
# Set relevant permissions for redelk user
7171
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
7373
ERROR=$?
7474
if [ $ERROR -ne 0 ]; then
7575
echo "[X] Could not set dir permissions for redelk user (Error Code: $ERROR)."
7676
fi
77-
echo "" >> $LOGFILE
77+
echo "" >>$LOGFILE
7878

7979
# set ssh keys permissions
8080
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
8282
ERROR=$?
8383
if [ $ERROR -ne 0 ]; then
8484
echo "[X] Could not set ssh keypermissions for redelk user (Error Code: $ERROR)."
8585
fi
86-
echo "" >> $LOGFILE
86+
echo "" >>$LOGFILE
8787

8888
# First check if ES and Kibana are up before doing any followup step
8989
upcheck_elasticsearch
@@ -92,128 +92,131 @@ upcheck_kibana
9292
# Start with specifcs for elasticsearch
9393
echo "[*] Installing Elasticsearch ILM policy" | tee -a $LOGFILE
9494
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
9696
ERROR=$?
9797
if [ $ERROR -ne 0 ]; then
9898
echo "[X] Could not install Elasticsearch ILM policy (Error Code: $ERROR)."
9999
fi
100-
echo "" >> $LOGFILE
100+
echo "" >>$LOGFILE
101101

102102
echo "[*] Installing Elasticsearch index templates" | tee -a $LOGFILE
103103
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
105108
ERROR=$?
106109
if [ $ERROR -ne 0 ]; then
107110
echo "[X] Could not install Elasticsearch index templates (Error Code: $ERROR)."
108111
fi
109-
echo "" >> $LOGFILE
112+
echo "" >>$LOGFILE
110113

111114
# Now Kibana specifics
112115
echo "[*] Preparing the SIEM signals index" | tee -a $LOGFILE
113116
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
115118
ERROR=$?
116119
if [ $ERROR -ne 0 ]; then
117120
echo "[X] Could not prepare the SIEM signals index (Error Code: $ERROR)."
118121
fi
119-
echo "" >> $LOGFILE
122+
echo "" >>$LOGFILE
120123

121124
echo "[*] Installing Kibana index patterns" | tee -a $LOGFILE
122125
upcheck_kibana
123126
for i in ./root/redelkinstalldata/templates/redelk_kibana_index-pattern*.ndjson; do
124127
$CURL -X POST "https://redelk-kibana:5601/api/saved_objects/_import?overwrite=true" -H 'kbn-xsrf: true' -F file=@$i
125128
sleep 1
126-
done >> $LOGFILE 2>&1
129+
done >>$LOGFILE 2>&1
127130
ERROR=$?
128131
if [ $ERROR -ne 0 ]; then
129132
echo "[X] Could not install Kibana index patterns (Error Code: $ERROR)."
130133
fi
131-
echo "" >> $LOGFILE
134+
echo "" >>$LOGFILE
132135

133136
echo "[*] Installing Kibana searches" | tee -a $LOGFILE
134137
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
136139
ERROR=$?
137140
if [ $ERROR -ne 0 ]; then
138141
echo "[X] Could not install Kibana searches (Error Code: $ERROR)."
139142
fi
140-
echo "" >> $LOGFILE
143+
echo "" >>$LOGFILE
141144

142145
echo "[*] Installing Kibana visualizations" | tee -a $LOGFILE
143146
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
145148
ERROR=$?
146149
if [ $ERROR -ne 0 ]; then
147150
echo "[X] Could not install Kibana visualizations (Error Code: $ERROR)."
148151
fi
149-
echo "" >> $LOGFILE
152+
echo "" >>$LOGFILE
150153

151154
echo "[*] Installing Kibana maps" | tee -a $LOGFILE
152155
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
154157
ERROR=$?
155158
if [ $ERROR -ne 0 ]; then
156159
echo "[X] Could not install Kibana maps (Error Code: $ERROR)."
157160
fi
158-
echo "" >> $LOGFILE
161+
echo "" >>$LOGFILE
159162

160163
echo "[*] Installing Kibana dashboards" | tee -a $LOGFILE
161164
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
163166
ERROR=$?
164167
if [ $ERROR -ne 0 ]; then
165168
echo "[X] Could not install Kibana dashboards (Error Code: $ERROR)."
166169
fi
167-
echo "" >> $LOGFILE
170+
echo "" >>$LOGFILE
168171

169172
echo "[*] Installing Kibana advanced settings" | tee -a $LOGFILE
170173
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
172175
ERROR=$?
173176
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)."
175178
fi
176-
echo "" >> $LOGFILE
179+
echo "" >>$LOGFILE
177180

178181
echo "[*] Disabling telemetry" | tee -a $LOGFILE
179182
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
181184
ERROR=$?
182185
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)."
184187
fi
185-
echo "" >> $LOGFILE
188+
echo "" >>$LOGFILE
186189

187190
echo "[*] Installing Kibana SIEM detection rules (for MITRE ATT&CK mapping)" | tee -a $LOGFILE
188191
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
190193
ERROR=$?
191194
if [ $ERROR -ne 0 ]; then
192195
echo "[X] Could not install Kibana SIEM detection rules (Error Code: $ERROR)."
193196
fi
194-
echo "" >> $LOGFILE
197+
echo "" >>$LOGFILE
195198

196199
echo "[*] Inserting the superawesomesauce RedELK logo into Kibana" | tee -a $LOGFILE
197200
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
199202
ERROR=$?
200203
if [ $ERROR -ne 0 ]; then
201204
echo "[X] Could not adjust Kibana logo (Error Code: $ERROR)."
202205
fi
203-
echo "" >> $LOGFILE
206+
echo "" >>$LOGFILE
204207

205208
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
207210
ERROR=$?
208211
if [ $ERROR -ne 0 ]; then
209212
echo "[X] Could not fix cron file permissions (Error Code: $ERROR)."
210213
fi
211-
echo "" >> $LOGFILE
214+
echo "" >>$LOGFILE
212215

213216
# 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

Comments
 (0)