-
Notifications
You must be signed in to change notification settings - Fork 23
/
run.sh
executable file
·201 lines (177 loc) · 6.07 KB
/
run.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/bash
START_TIME=$(date +%s)
# Define the lock file path
LOCKFILE="/tmp/ransomwarelive.lock"
RL_HOME_DIR="/var/www/ransomware-ng"
LOGFILE="/var/log/ransomwarelive.log"
# Log the execution time to run.log
EXECUTION_DATE=$(date '+%Y-%m-%d %H:%M:%S')
# Function to remove the lock file on exit
remove_lock() {
rm -f "$LOCKFILE"
}
# Check if the lock file exists
if [ -e "$LOCKFILE" ]; then
# Get the current time and the file creation time
CURRENT_TIME=$(date +%s)
FILE_CREATION_TIME=$(stat -c %Y "$LOCKFILE")
# Calculate the time difference in seconds
TIME_DIFF=$((CURRENT_TIME - FILE_CREATION_TIME))
# Convert 2 hours to seconds (2 * 60 * 60)
THREE_HOURS_IN_SECONDS=7200
# Check if the time difference is greater than 3 hours
if [ "$TIME_DIFF" -gt "$THREE_HOURS_IN_SECONDS" ]; then
echo "Lock file is older than 2 hours. Please investigate."
# Check if PUSH_USER is set
if [ -z "$PUSH_USER" ]; then
echo "PUSH_USER is not set. Cannot send notification. Exiting."
exit 1
fi
curl -s \
--form-string "token=${PUSH_API}" \
--form-string "user=${PUSH_USER}" \
--form-string "message=ERROR: lock file older than 2 hours !!!" \
https://api.pushover.net/1/messages.json > /dev/null
exit 1
else
echo "Script is already running. Exiting."
exit 1
fi
else
# Create a lock file
echo "Creating lock file : $LOCKFILE"
touch "$LOCKFILE"
# Ensure the lock file is removed when the script exits
trap remove_lock EXIT
fi
service tor reload
## Go to directory
cd ${RL_HOME_DIR}
## Delete older files
find ./source/ -maxdepth 1 -type f -mtime +1 -exec rm {} \;
## Load all env. variable
source .env
### Go
## Update ransom_notes
cd ${RL_HOME_DIR}/docs/ransomware_notes
git fetch
# Check for any ransomware notes update
if git diff --quiet HEAD origin/main; then
echo "No update."
else
if [ -z "$PUSH_USER" ]; then
echo "PUSH_USER is not set. Cannot send notification. Exiting."
else
echo "Update available. Execute git pull..."
git pull
curl -s \
--form-string "token=${PUSH_API}" \
--form-string "user=${PUSH_USER}" \
--form-string "message=New Ransom notes has been added" \
https://api.pushover.net/1/messages.json > /dev/null
fi
fi
cd ${RL_HOME_DIR}
## Update ransom_notes
cd ${RL_HOME_DIR}/import/Malware
git fetch
# Check for any ransomware notes update
if git diff --quiet HEAD origin/main; then
echo "No update."
else
echo "Update available. Execute git pull..."
git pull
curl -s \
--form-string "token=${PUSH_API}" \
--form-string "user=${PUSH_USER}" \
--form-string "message=New Ransom notes has been added" \
https://api.pushover.net/1/messages.json > /dev/null
fi
cd ${RL_HOME_DIR}
## Download carto pdf
curl https://raw.githubusercontent.com/cert-orangecyberdefense/ransomware_map/main/OCD_WorldWatch_Ransomware-ecosystem-map.pdf -o ${RL_HOME_DIR}/docs/OCD_WorldWatch_Ransomware-ecosystem-map.pdf
cd ${RL_HOME_DIR}/import/Ransomchats
git fetch
# Vérifier s'il y a des mises à jour
if git diff --quiet HEAD origin/main; then
echo "Aucune mise à jour disponible."
else
echo "Mise à jour détectée. Exécution de git pull..."
git pull
# Exécuter le script Python s'il y a eu une mise à jour
if [ $? -eq 0 ]; then
echo "Exécution de la mise à jour ..."
cd ..
if [ -z "$PUSH_USER" ]; then
curl -s \
--form-string "token=${PUSH_API}" \
--form-string "user=${PUSH_USER}" \
--form-string "message=New Ransoms chats have been added" \
https://api.pushover.net/1/messages.json > /dev/null
fi
else
echo "Erreur lors de la mise à jour du référentiel."
fi
fi
cd ${RL_HOME_DIR}/import/Ransomware-Tool-Matrix
git fetch
# Vérifier s'il y a des mises à jour
if git diff --quiet HEAD origin/main; then
echo "Aucune mise à jour disponible."
else
echo "Mise à jour détectée. Exécution de git pull..."
git pull
# Exécuter le script Python s'il y a eu une mise à jour
if [ $? -eq 0 ]; then
echo "Exécution de la mise à jour ..."
cd ..
if [ -z "$PUSH_USER" ]; then
curl -s \
--form-string "token=${PUSH_API}" \
--form-string "user=${PUSH_USER}" \
--form-string "message=New Ransomware Intel have been added" \
https://api.pushover.net/1/messages.json > /dev/null
fi
else
echo "Erreur lors de la mise à jour du référentiel."
fi
fi
cd ${RL_HOME_DIR}
SCRAPE_BEGIN_TIME=$(date +%s)
python3 ransomcmd.py scrape
SCRAPE_END_TIME=$(date +%s)
SCRAPE_EXECUTION_TIME=$((SCRAPE_END_TIME - SCRAPE_BEGIN_TIME))
PARSE_BEGIN_TIME=$(date +%s)
python3 ransomcmd.py parse
PARSE_END_TIME=$(date +%s)
PARSE_EXECUTION_TIME=$((PARSE_END_TIME - PARSE_BEGIN_TIME))
MARKDOWN_BEGIN_TIME=$(date +%s)
# TODO: Need to be include in ransomwarelive library --> generatesite
python3 get-cyberattacks-info.py
python3 cyberattacks.py
python3 ransomcmd.py generate
MARKDOWN_END_TIME=$(date +%s)
MARKDOWN_EXECUTION_TIME=$((MARKDOWN_END_TIME - MARKDOWN_BEGIN_TIME))
python3 check_PR_DeepDarkCTI.py
END_TIME=$(date +%s)
EXECUTION_TIME=$((END_TIME - START_TIME))
# Log the execution time to run.log
{
echo "$EXECUTION_DATE,$SCRAPE_EXECUTION_TIME,$PARSE_EXECUTION_TIME,$MARKDOWN_EXECUTION_TIME,$EXECUTION_TIME"
} >> "$LOGFILE"
# Calculate minutes and seconds
MINUTES=$((EXECUTION_TIME / 60))
SECONDS=$((EXECUTION_TIME % 60))
echo "Execution time: $MINUTES minutes and $SECONDS seconds"
# Check if the execution time exceeds 90 minutes
if (( MINUTES > 90 )); then
if [ -z "$PUSH_USER" ]; then
echo "PUSH_USER is not set. Cannot send notification."
exit 1
fi
curl -s \
--form-string "token=${PUSH_API}" \
--form-string "user=${PUSH_USER}" \
--form-string "message=WARNING: execution script longer than expected : ${MINUTES} minutes !!!" \
https://api.pushover.net/1/messages.json > /dev/null
fi