-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDatabaseClasses.py
More file actions
179 lines (128 loc) · 5.34 KB
/
Copy pathDatabaseClasses.py
File metadata and controls
179 lines (128 loc) · 5.34 KB
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
from backend.subnet_calculations import nth_machine_ip
class ChallengeTemplate:
def __init__(self, challenge_template_id):
self.id = challenge_template_id
self.machine_templates = {}
self.network_templates = {}
self.connection_templates = {}
self.domain_templates = {}
self.challenge_subnet = None
self.flags = []
def add_machine_template(self, machine_template):
self.machine_templates[machine_template.id] = machine_template
def add_network_template(self, network_template):
self.network_templates[network_template.id] = network_template
def add_connection_template(self, connection_template):
self.connection_templates[(connection_template.machine_template.id, connection_template.network_template.id)] \
= connection_template
def add_domain_template(self, domain_template):
self.domain_templates[(domain_template.machine_template.id, domain_template.domain)] = domain_template
def set_challenge_subnet(self, challenge_subnet):
self.challenge_subnet = challenge_subnet
class MachineTemplate:
def __init__(self, machine_template_id, challenge_template):
self.id = machine_template_id
self.challenge_template = challenge_template
self.connected_networks = {}
self.domain_templates = {}
self.child = None
self.disk_file_path = None
self.cores = 1
self.ram = 1024
def add_connected_network(self, network):
self.connected_networks[network.id] = network
def set_child(self, child):
self.child = child
def add_domain_template(self, domain_template):
self.domain_templates[(domain_template.machine_template.id, domain_template.domain)] = domain_template
def set_disk_file_path(self, disk_file_path):
self.disk_file_path = disk_file_path
def set_cores(self, cores):
self.cores = cores
def set_ram(self, ram):
self.ram = ram
class NetworkTemplate:
def __init__(self, network_template_id, accessible):
self.id = network_template_id
self.accessible = accessible
self.connected_machines = {}
self.is_dmz = False
def add_connected_machine(self, machine):
self.connected_machines[machine.id] = machine
def set_is_dmz(self, is_dmz):
self.is_dmz = is_dmz
class ConnectionTemplate:
def __init__(self, machine_template, network_template):
self.machine_template = machine_template
self.network_template = network_template
def set_machine_template(self, machine_template):
self.machine_template = machine_template
def set_network_template(self, network_template):
self.network_template = network_template
class DomainTemplate:
def __init__(self, machine_template, domain):
self.machine_template = machine_template
self.domain = domain
class Challenge:
def __init__(self, challenge_id, template, subnet):
self.id = challenge_id
self.template = template
self.subnet = subnet
self.subnet_ip = subnet[:-3]
self.subnet_mask = subnet[-2:]
self.machines = {}
self.networks = {}
self.connections = {}
self.domains = {}
self.challenge_subnet = None
def add_machine(self, machine):
self.machines[machine.id] = machine
def add_network(self, network):
self.networks[network.id] = network
def add_connection(self, connection):
self.connections[(connection.machine.id, connection.network.id)] = connection
def add_domain(self, domain):
self.domains[(domain.machine.id, domain.domain)] = domain
def set_challenge_subnet(self, challenge_subnet):
self.challenge_subnet = challenge_subnet
class Machine:
def __init__(self, machine_id, template, challenge):
self.id = machine_id
self.template = template
self.challenge = challenge
self.connections = {}
self.domains = []
def add_connection(self, connection):
self.connections[(connection.machine.id, connection.network.id)] = connection
def add_domain(self, domain):
self.domains.append(domain.domain)
class Network:
def __init__(self, network_id, template, subnet, host_device, accessible):
self.id = network_id
self.template = template
self.subnet = subnet
self.host_device = host_device
self.accessible = accessible
self.subnet_ip, self.subnet_mask = self.subnet.split("/")
self.connections = {}
self.router_ip = nth_machine_ip(self.subnet_ip, 1, True)
self.available_start_ip = nth_machine_ip(self.subnet_ip, 2)
self.available_end_ip = nth_machine_ip(self.subnet_ip, 2**4 - 2)
self.is_dmz = False
def add_connection(self, connection):
self.connections[(connection.machine.id, connection.network.id)] = connection
def set_is_dmz(self, is_dmz):
self.is_dmz = is_dmz
class Connection:
def __init__(self, machine, network, client_mac, client_ip):
self.machine = machine
self.network = network
self.client_mac = client_mac
self.client_ip = client_ip
class Domain:
def __init__(self, machine, domain):
self.machine = machine
self.domain = domain
class ChallengeSubnet:
def __init__(self, subnet):
self.subnet = subnet