-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExerciseAdmin.py
210 lines (159 loc) · 6.49 KB
/
ExerciseAdmin.py
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
202
203
204
205
206
207
208
209
210
from time import sleep
import json
import sys
import requests
# Load classes and functions from helper files
from Classes import Task, Scenario, Incident, Role
from ApiHelper import createRole, createScenario, getRolesForPlan, getScenariosForPlan, getRolesForIncident, createTask, createIncident, addTaskToScenario, getTaskStatus
# Flags to control whether to create with api or not
CREATE_SCENARIOS = True
CREATE_ROLES = True
mitre_tactics_file = "mitre_tactics.json"
def show_banner():
lines = [
" _____ _ _ _____ _ ______ _ ",
"/ __ \ (_) (_) / __ \ | | ___ \ | |",
"| / \/_ __ _ ___ _ ___ | / \/ |__ ___ ___ ___ | |_/ / ___ __ _ _ __ __| |",
"| | | '__| / __| / __| | | | '_ \ / _ \/ __/ __| | ___ \/ _ \ / _` | '__/ _` |",
"| \__/\ | | \__ \ \__ \ | \__/\ | | | __/\__ \__ \ | |_/ / (_) | (_| | | | (_| |",
" \____/_| |_|___/_|___/ \____/_| |_|\___||___/___/ \____/ \___/ \__,_|_| \__,_|",
"----------------------------------------------------------------------------------",
""
]
for line in lines:
print(line)
sleep(0.05)
def loadFromJsonFile(file):
with open(file, 'r') as file:
return json.load(file)
def get_role_object(role_list, role_name):
"""
:param: role_list: list of Role objects
:param: role_name: name of role to find
:return: Role object with name containg role_name
"""
for i in role_list:
if role_name in i.name:
return i
return None
def get_scenario_object(scenario_list, scenario_name):
"""
:param: scenario_list: list of Scenario objects
:param: scenario_name: name of scenario to find
:return: Scenario object with name containg scenario_name
"""
for i in scenario_list:
if scenario_name in i.name:
return i
return None
def print_task(task):
"""
:param: task: Task in JSON format
Prints task in a nice format
"""
print()
print("-" * 80)
print("| Desc: " + task["Description"][:70].ljust(70) + " | ")
print("| Role: " + task["Responsible"].ljust(70) + " | ")
print("| Prio: " + str(task["Priority"]).ljust(70) + " | ")
print("-" * 80)
def task_creation_successful(status_code, task_id):
"""
:param: status_code: status code from API (200 = OK)
:param: task_id: task id from API
:return: True if task was successfully created, False otherwise
"""
return status_code == 200 and task_id != "0"
def create_tasks_incaseit(task_list, role_list, current_scenario):
"""
:param: task_list: list of tasks in JSON format
:return: list of task_ids that were successfully created
"""
tasks_created = []
for task in task_list:
print_task(task)
responsible_role = get_role_object(role_list, task["Responsible"])
if responsible_role:
print(f"=> Role object found {responsible_role.name}")
else:
print("=> FAILED to find role object. Skipping task...")
continue
sleep(0.2)
stat_code, task_id = createTask(task["Priority"], responsible_role, task["Description"], task["Content"], task["Time"])
print("stat_code, task_id", stat_code, task_id)
if task_creation_successful(stat_code, task_id):
print(f"=> Task successfully created [id: {task_id}]")
scenario_response, content = addTaskToScenario(task_id, current_scenario)
if scenario_response == 200:
print(f"=> Task added to scenario [{scenario_response}]")
tasks_created.append(task_id)
else:
print(f"=> FAILED to add task to scenario [{scenario_response}]")
else:
print("=> FAILED to create task")
return tasks_created
# --- Main ---
if __name__ == "__main__":
show_banner()
# print("Press any key to continue...")
# n = input()
# Lists for storing tasks for each stage:
first = []
second = []
third = []
final = []
file_dir = "./EXERCISE/"
phase1_tasks = loadFromJsonFile(file_dir + "01_first.json")
phase2_tasks = loadFromJsonFile(file_dir + "02_second.json")
phase3_tasks = loadFromJsonFile(file_dir + "03_third.json")
phase4_tasks = loadFromJsonFile(file_dir + "04_final.json")
print("==============================")
print(" SCENARIOS ")
print("==============================")
scen_response = getScenariosForPlan()
all_scenarios = []
print("Scenario: Ransomware")
for i in json.loads(scen_response):
all_scenarios.append(Scenario(i))
curr_scen = get_scenario_object(all_scenarios, "Ransomware")
scen_name = curr_scen.name
print(f"Scenario Object: {curr_scen.name} - {curr_scen}")
# Ask user for Incident ID
inc_id = input("Enter Incident ID: ") # 32887
if not inc_id:
print("No Incident ID entered. Exiting...")
exit(1)
print()
print("==============================")
print(" INCIDENT ")
print("==============================")
incident_name = f"Incident: Ransomware Incident detected"
incident_description = f"Security Operations Center has detected a ransomware incident."
print("[!] Incident Selected: " + incident_name)
# ----- GET ROLES -----
roles_incident = getRolesForIncident(inc_id)
roles_object_list = []
for i in roles_incident:
roles_object_list.append(Role(i))
# List to keep track of tasks that are not completed
remaining_tasks = []
print("Select phase to create tasks for:")
print("[1] First phase")
print("[2] Second phase")
print("[3] Third phase")
print("[4] Final phase")
phase = input("Enter phase: ")
if phase not in ["1", "2", "3", "4"]:
phase = input("Enter phase: ")
if phase == "1":
task_list = phase1_tasks
elif phase == "2":
task_list = phase2_tasks
elif phase == "3":
task_list = phase3_tasks
elif phase == "4":
task_list = phase4_tasks
# Create tasks in IncaseIT
remaining_tasks = create_tasks_incaseit(task_list, roles_object_list, curr_scen)
print(); print()
print("--- TASKS CREATION COMPLETED ---")