atomicshop 2.15.13__py3-none-any.whl → 2.16.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of atomicshop might be problematic. Click here for more details.
- atomicshop/__init__.py +1 -1
- atomicshop/a_installs/ubuntu/pycharm.py +7 -0
- atomicshop/a_installs/win/pycharm.py +2 -2
- atomicshop/{addons/mains/install_wsl_ubuntu_lts_admin.py → a_installs/win/wsl_ubuntu_lts.py} +1 -0
- atomicshop/{addons/mains → a_mains}/FACT/update_extract.py +3 -2
- atomicshop/a_mains/dns_gateway_setting.py +11 -0
- atomicshop/basics/booleans.py +14 -5
- atomicshop/dns.py +104 -0
- atomicshop/file_io/docxs.py +8 -0
- atomicshop/file_io/tomls.py +133 -0
- atomicshop/filesystem.py +5 -4
- atomicshop/get_process_list.py +3 -3
- atomicshop/mitm/config_static.py +195 -0
- atomicshop/mitm/config_toml_editor.py +55 -0
- atomicshop/mitm/connection_thread_worker.py +54 -90
- atomicshop/mitm/import_config.py +148 -139
- atomicshop/mitm/initialize_engines.py +7 -2
- atomicshop/mitm/initialize_mitm_server.py +162 -107
- atomicshop/mitm/shared_functions.py +0 -1
- atomicshop/mitm/statistic_analyzer.py +13 -1
- atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +54 -14
- atomicshop/permissions/__init__.py +0 -0
- atomicshop/permissions/permissions.py +22 -0
- atomicshop/{permissions.py → permissions/ubuntu_permissions.py} +4 -54
- atomicshop/permissions/win_permissions.py +33 -0
- atomicshop/script_as_string_processor.py +5 -1
- atomicshop/wrappers/cryptographyw.py +3 -3
- atomicshop/wrappers/dockerw/install_docker.py +6 -5
- atomicshop/wrappers/elasticsearchw/install_elastic.py +2 -1
- atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py +5 -4
- atomicshop/wrappers/mongodbw/install_mongodb.py +2 -1
- atomicshop/wrappers/msiw.py +2 -3
- atomicshop/wrappers/psutilw/networks.py +25 -1
- atomicshop/wrappers/pycharmw/__init__.py +0 -0
- atomicshop/wrappers/pycharmw/ubuntu.py +38 -0
- atomicshop/wrappers/{pycharmw.py → pycharmw/win.py} +2 -2
- atomicshop/wrappers/pywin32w/wmis/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/wmis/helpers.py +127 -0
- atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +167 -0
- atomicshop/wrappers/socketw/accepter.py +8 -8
- atomicshop/wrappers/socketw/base.py +13 -0
- atomicshop/wrappers/socketw/certificator.py +202 -149
- atomicshop/wrappers/socketw/creator.py +15 -35
- atomicshop/wrappers/socketw/dns_server.py +155 -102
- atomicshop/wrappers/socketw/exception_wrapper.py +8 -27
- atomicshop/wrappers/socketw/get_process.py +115 -95
- atomicshop/wrappers/socketw/sni.py +298 -164
- atomicshop/wrappers/socketw/socket_client.py +5 -12
- atomicshop/wrappers/socketw/socket_server_tester.py +1 -1
- atomicshop/wrappers/socketw/socket_wrapper.py +328 -72
- atomicshop/wrappers/socketw/statistics_csv.py +94 -16
- atomicshop/wrappers/ubuntu_terminal.py +6 -6
- atomicshop/wrappers/wslw.py +1 -0
- {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/METADATA +1 -1
- {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/RECORD +63 -54
- atomicshop/addons/mains/__pycache__/install_fibratus_windows.cpython-312.pyc +0 -0
- atomicshop/addons/mains/__pycache__/msi_unpacker.cpython-312.pyc +0 -0
- atomicshop/mitm/config_editor.py +0 -37
- /atomicshop/{addons/mains/install_docker_rootless_ubuntu.py → a_installs/ubuntu/docker_rootless.py} +0 -0
- /atomicshop/{addons/mains/install_docker_ubuntu_main_sudo.py → a_installs/ubuntu/docker_sudo.py} +0 -0
- /atomicshop/{addons/mains/install_elastic_search_and_kibana_ubuntu.py → a_installs/ubuntu/elastic_search_and_kibana.py} +0 -0
- /atomicshop/{addons/mains → a_mains}/FACT/factw_fact_extractor_docker_image_main_sudo.py +0 -0
- /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
- {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/LICENSE.txt +0 -0
- {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/WHEEL +0 -0
- {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/top_level.txt +0 -0
|
@@ -1,86 +1,45 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
|
|
3
|
-
from .
|
|
4
|
-
from .initialize_engines import assign_class_by_domain
|
|
5
|
-
from ..wrappers.socketw.receiver import Receiver
|
|
6
|
-
from ..wrappers.socketw.sender import Sender
|
|
7
|
-
from ..wrappers.socketw.socket_client import SocketClient
|
|
3
|
+
from ..wrappers.socketw import receiver, sender, socket_client, base
|
|
8
4
|
from ..http_parse import HTTPRequestParse, HTTPResponseParse
|
|
9
5
|
from ..basics.threads import current_thread_id
|
|
10
6
|
from ..print_api import print_api
|
|
11
7
|
|
|
8
|
+
from .message import ClientMessage
|
|
9
|
+
from .initialize_engines import assign_class_by_domain
|
|
10
|
+
from . import config_static
|
|
11
|
+
|
|
12
12
|
|
|
13
13
|
# Thread function on client connect.
|
|
14
14
|
def thread_worker_main(
|
|
15
15
|
function_client_socket_object,
|
|
16
16
|
process_commandline: str,
|
|
17
17
|
is_tls: bool,
|
|
18
|
+
tls_type: str,
|
|
19
|
+
tls_version: str,
|
|
18
20
|
domain_from_dns,
|
|
19
21
|
network_logger,
|
|
20
|
-
|
|
22
|
+
statistics_writer,
|
|
21
23
|
engines_list,
|
|
22
|
-
reference_module
|
|
23
|
-
|
|
24
|
+
reference_module
|
|
25
|
+
):
|
|
24
26
|
def output_statistics_csv_row():
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
except Exception:
|
|
42
|
-
pass
|
|
43
|
-
try:
|
|
44
|
-
statistics_dict['request_size_bytes'] = len(client_message.request_raw_bytes)
|
|
45
|
-
except Exception:
|
|
46
|
-
pass
|
|
47
|
-
try:
|
|
48
|
-
statistics_dict['response_size_bytes'] = \
|
|
49
|
-
','.join([str(len(x)) for x in client_message.response_list_of_raw_bytes])
|
|
50
|
-
except Exception:
|
|
51
|
-
pass
|
|
52
|
-
# try:
|
|
53
|
-
# statistics_dict['request_hex'] = client_message.request_raw_hex
|
|
54
|
-
# except Exception:
|
|
55
|
-
# pass
|
|
56
|
-
# try:
|
|
57
|
-
# statistics_dict['response_hex'] = \
|
|
58
|
-
# f'"' + ','.join([x for x in client_message.response_list_of_raw_hex]) + '"'
|
|
59
|
-
# except Exception:
|
|
60
|
-
# pass
|
|
61
|
-
try:
|
|
62
|
-
statistics_dict['file_path'] = recorded_file
|
|
63
|
-
except Exception:
|
|
64
|
-
pass
|
|
65
|
-
try:
|
|
66
|
-
statistics_dict['process_cmd'] = process_commandline
|
|
67
|
-
except Exception:
|
|
68
|
-
pass
|
|
69
|
-
statistics_dict['error'] = str()
|
|
70
|
-
|
|
71
|
-
statistics_logger.info(f"{statistics_dict['request_time_sent']},"
|
|
72
|
-
f"{statistics_dict['host']},"
|
|
73
|
-
f"\"{statistics_dict['path']}\","
|
|
74
|
-
f"{statistics_dict['command']},"
|
|
75
|
-
f"{statistics_dict['status_code']},"
|
|
76
|
-
f"{statistics_dict['request_size_bytes']},"
|
|
77
|
-
f"{statistics_dict['response_size_bytes']},"
|
|
78
|
-
# f"{statistics_dict['request_hex']},"
|
|
79
|
-
# f"{statistics_dict['response_hex']},"
|
|
80
|
-
f"\"{statistics_dict['file_path']}\","
|
|
81
|
-
f"\"{statistics_dict['process_cmd']}\","
|
|
82
|
-
f"{statistics_dict['error']}"
|
|
83
|
-
)
|
|
27
|
+
status_code = ','.join([str(x.code) for x in client_message.response_list_of_raw_decoded])
|
|
28
|
+
response_size_bytes = ','.join([str(len(x)) for x in client_message.response_list_of_raw_bytes])
|
|
29
|
+
|
|
30
|
+
statistics_writer.write_row(
|
|
31
|
+
host=client_message.server_name,
|
|
32
|
+
tls_type=tls_type,
|
|
33
|
+
tls_version=tls_version,
|
|
34
|
+
path=client_message.request_raw_decoded.path,
|
|
35
|
+
status_code=status_code,
|
|
36
|
+
command=client_message.request_raw_decoded.command,
|
|
37
|
+
request_time_sent=client_message.request_time_received,
|
|
38
|
+
request_size_bytes=len(client_message.request_raw_bytes),
|
|
39
|
+
response_size_bytes=response_size_bytes,
|
|
40
|
+
recorded_file_path=recorded_file,
|
|
41
|
+
process_cmd=process_commandline,
|
|
42
|
+
error=str())
|
|
84
43
|
|
|
85
44
|
try:
|
|
86
45
|
# Defining variables before assignment
|
|
@@ -113,8 +72,12 @@ def thread_worker_main(
|
|
|
113
72
|
# Loading parser by domain, if there is no parser for current domain - general reference parser is loaded.
|
|
114
73
|
# These should be outside any loop and initialized only once entering the thread.
|
|
115
74
|
parser, responder, recorder = assign_class_by_domain(
|
|
116
|
-
|
|
117
|
-
|
|
75
|
+
engines_usage=config_static.TCPServer.engines_usage,
|
|
76
|
+
engines_list=engines_list,
|
|
77
|
+
message_domain_name=client_message.server_name,
|
|
78
|
+
reference_module=reference_module,
|
|
79
|
+
logger=network_logger
|
|
80
|
+
)
|
|
118
81
|
|
|
119
82
|
# Defining client connection boolean variable to enter the loop
|
|
120
83
|
client_connection_boolean: bool = True
|
|
@@ -128,22 +91,22 @@ def thread_worker_main(
|
|
|
128
91
|
client_message.reinitialize()
|
|
129
92
|
|
|
130
93
|
# Initialize statistics_dict for the same reason as 'client_message.reinitialize()'.
|
|
131
|
-
statistics_dict: dict = dict()
|
|
132
|
-
statistics_dict['host'] = client_message.server_name
|
|
133
|
-
statistics_dict['path'] = str()
|
|
134
|
-
statistics_dict['status_code'] = str()
|
|
135
|
-
statistics_dict['command'] = str()
|
|
136
|
-
statistics_dict['request_time_sent'] = str()
|
|
137
|
-
statistics_dict['request_size_bytes'] = str()
|
|
138
|
-
# statistics_dict['response_time_sent'] = str()
|
|
139
|
-
statistics_dict['response_size_bytes'] = str()
|
|
140
|
-
statistics_dict['file_path'] = str()
|
|
141
|
-
statistics_dict['process_cmd'] = str()
|
|
142
|
-
statistics_dict['error'] = str()
|
|
94
|
+
# statistics_dict: dict = dict()
|
|
95
|
+
# statistics_dict['host'] = client_message.server_name
|
|
96
|
+
# statistics_dict['path'] = str()
|
|
97
|
+
# statistics_dict['status_code'] = str()
|
|
98
|
+
# statistics_dict['command'] = str()
|
|
99
|
+
# statistics_dict['request_time_sent'] = str()
|
|
100
|
+
# statistics_dict['request_size_bytes'] = str()
|
|
101
|
+
# # statistics_dict['response_time_sent'] = str()
|
|
102
|
+
# statistics_dict['response_size_bytes'] = str()
|
|
103
|
+
# statistics_dict['file_path'] = str()
|
|
104
|
+
# statistics_dict['process_cmd'] = str()
|
|
105
|
+
# statistics_dict['error'] = str()
|
|
143
106
|
|
|
144
107
|
network_logger.info("Initializing Receiver")
|
|
145
108
|
# Getting message from the client over the socket using specific class.
|
|
146
|
-
client_received_raw_data = Receiver(function_client_socket_object).receive()
|
|
109
|
+
client_received_raw_data = receiver.Receiver(function_client_socket_object).receive()
|
|
147
110
|
|
|
148
111
|
# If the message is empty, then the connection was closed already by the other side,
|
|
149
112
|
# so we can close the socket as well.
|
|
@@ -214,7 +177,7 @@ def thread_worker_main(
|
|
|
214
177
|
pass
|
|
215
178
|
|
|
216
179
|
# If we're in response mode, execute responder.
|
|
217
|
-
if
|
|
180
|
+
if config_static.TCPServer.server_response_mode:
|
|
218
181
|
# Since we're in response mode, we'll record the request anyway, after the responder did its job.
|
|
219
182
|
client_message.info = "In Server Response Mode"
|
|
220
183
|
|
|
@@ -251,14 +214,15 @@ def thread_worker_main(
|
|
|
251
214
|
if not service_client:
|
|
252
215
|
# If we're on localhost, then use external services list in order to resolve the domain:
|
|
253
216
|
# config['tcp']['forwarding_dns_service_ipv4_list___only_for_localhost']
|
|
254
|
-
if client_message.client_ip
|
|
255
|
-
service_client = SocketClient(
|
|
217
|
+
if client_message.client_ip in base.THIS_DEVICE_IP_LIST:
|
|
218
|
+
service_client = socket_client.SocketClient(
|
|
256
219
|
service_name=client_message.server_name, service_port=client_message.destination_port,
|
|
257
220
|
tls=is_tls,
|
|
258
|
-
dns_servers_list=
|
|
221
|
+
dns_servers_list=
|
|
222
|
+
config_static.TCPServer.forwarding_dns_service_ipv4_list___only_for_localhost)
|
|
259
223
|
# If we're not on localhost, then connect to domain directly.
|
|
260
224
|
else:
|
|
261
|
-
service_client = SocketClient(
|
|
225
|
+
service_client = socket_client.SocketClient(
|
|
262
226
|
service_name=client_message.server_name, service_port=client_message.destination_port,
|
|
263
227
|
tls=is_tls)
|
|
264
228
|
|
|
@@ -289,7 +253,7 @@ def thread_worker_main(
|
|
|
289
253
|
# Recording the message, doesn't matter what type of mode this is.
|
|
290
254
|
try:
|
|
291
255
|
recorded_file = recorder(class_client_message=client_message,
|
|
292
|
-
record_path=
|
|
256
|
+
record_path=config_static.Recorder.recordings_path).record()
|
|
293
257
|
except Exception:
|
|
294
258
|
message = "Exception in Recorder"
|
|
295
259
|
print_api(
|
|
@@ -315,7 +279,7 @@ def thread_worker_main(
|
|
|
315
279
|
|
|
316
280
|
# Iterate through the list of byte responses.
|
|
317
281
|
for response_raw_bytes in client_message.response_list_of_raw_bytes:
|
|
318
|
-
function_data_sent = Sender(function_client_socket_object, response_raw_bytes).send()
|
|
282
|
+
function_data_sent = sender.Sender(function_client_socket_object, response_raw_bytes).send()
|
|
319
283
|
|
|
320
284
|
# If there was problem with sending data, we'll break current loop.
|
|
321
285
|
if not function_data_sent:
|
|
@@ -348,7 +312,7 @@ def thread_worker_main(
|
|
|
348
312
|
if not function_recorded:
|
|
349
313
|
try:
|
|
350
314
|
recorded_file = recorder(
|
|
351
|
-
class_client_message=client_message, record_path=
|
|
315
|
+
class_client_message=client_message, record_path=config_static.Recorder.recordings_path).record()
|
|
352
316
|
except Exception:
|
|
353
317
|
message = "Exception in Recorder"
|
|
354
318
|
print_api(
|
atomicshop/mitm/import_config.py
CHANGED
|
@@ -1,145 +1,154 @@
|
|
|
1
|
-
import
|
|
1
|
+
from pathlib import Path
|
|
2
2
|
|
|
3
|
-
from ..
|
|
4
|
-
from .. import filesystem
|
|
5
|
-
from ..permissions import
|
|
6
|
-
from ..
|
|
3
|
+
from ..print_api import print_api
|
|
4
|
+
from .. import config_init, filesystem, dns
|
|
5
|
+
from ..permissions import permissions
|
|
6
|
+
from ..wrappers.socketw import base
|
|
7
|
+
from ..basics import booleans
|
|
7
8
|
|
|
9
|
+
from . import config_static
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
|
|
12
|
+
def assign_bool(dict_instance: dict, section: str, key: str):
|
|
13
|
+
# If the value is already boolean, don't do anything.
|
|
14
|
+
if dict_instance[section][key] is True or dict_instance[section][key] is False:
|
|
15
|
+
return
|
|
16
|
+
elif dict_instance[section][key] == 1:
|
|
17
|
+
dict_instance[section][key] = True
|
|
18
|
+
elif dict_instance[section][key] == 0:
|
|
19
|
+
dict_instance[section][key] = False
|
|
20
|
+
else:
|
|
21
|
+
print_api(f"Error: {section}.{key} must be 0 or 1.", color='red')
|
|
22
|
+
return 1
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def import_config_file(
|
|
26
|
+
config_file_path: str
|
|
27
|
+
):
|
|
28
|
+
"""
|
|
29
|
+
Import the configuration file 'config.toml' and write all the values to 'config_static' dataclasses module.
|
|
30
|
+
:param config_file_path:
|
|
31
|
+
:return:
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
config_toml: dict = config_init.get_config(
|
|
35
|
+
script_directory=str(Path(config_file_path).parent), config_file_name=Path(config_file_path).name)
|
|
36
|
+
|
|
37
|
+
# Assign boolean values to the toml dict module.
|
|
38
|
+
for boolean_tuple in config_static.LIST_OF_BOOLEANS:
|
|
39
|
+
assign_bool(config_toml, boolean_tuple[0], boolean_tuple[1])
|
|
40
|
+
|
|
41
|
+
# Assign the configuration file content to the 'config_static' dataclasses module.
|
|
42
|
+
for category, category_settings in config_toml.items():
|
|
43
|
+
for setting_name, value in category_settings.items():
|
|
44
|
+
# Get the dynamic class or dataclass from the 'config_static' module.
|
|
45
|
+
dynamic_class = getattr(config_static, config_static.TOML_TO_STATIC_CATEGORIES[category])
|
|
46
|
+
# Set the value to the dynamic class setting.
|
|
47
|
+
setattr(dynamic_class, setting_name, value)
|
|
48
|
+
|
|
49
|
+
manipulations_after_import()
|
|
50
|
+
|
|
51
|
+
result = check_configurations()
|
|
52
|
+
return result
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def check_configurations() -> int:
|
|
10
56
|
"""
|
|
11
|
-
|
|
57
|
+
Check the configurations from the 'config.toml' file.
|
|
58
|
+
If there are any errors, print them and return 1.
|
|
59
|
+
:return: int, status code.
|
|
12
60
|
"""
|
|
13
61
|
|
|
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
|
-
if self.config['dns']['target_tcp_server_ipv4'] == "127.0.0.1" and self.config['ssh']['get_process_name']:
|
|
108
|
-
self.admin_rights = is_admin()
|
|
109
|
-
|
|
110
|
-
# If we're not running with admin rights, prompt to the user and make him decide what to do.
|
|
111
|
-
# If he wants to continue running with 'psutil' exceptions or close the script and rerun with admin rights.
|
|
112
|
-
if not self.admin_rights:
|
|
113
|
-
print("=============================================================")
|
|
114
|
-
error_on_admin: str = \
|
|
115
|
-
"[!!!] You're running the script in LOCALHOST mode without Administrative Privileges.\n" \
|
|
116
|
-
"[!!!] 'psutil' needs them to read Command Lines of system Processes.\n" \
|
|
117
|
-
"[!!!] Press [ENTER] to CONTINUE running with errors " \
|
|
118
|
-
"on Process Command Line harvesting or rerun the script with Administrative Rights..."
|
|
119
|
-
print(error_on_admin)
|
|
120
|
-
# Stopping execution and waiting for user's [ENTER] key.
|
|
121
|
-
input()
|
|
122
|
-
print("=============================================================")
|
|
123
|
-
|
|
124
|
-
def manipulations_after_import(self):
|
|
125
|
-
# If 'custom_certificate_usage' was set to 'True'.
|
|
126
|
-
if self.config['certificates']['custom_server_certificate_usage']:
|
|
127
|
-
# Check file existence.
|
|
128
|
-
if not filesystem.is_file_exists(file_path=self.config['certificates']['custom_server_certificate_path']):
|
|
129
|
-
raise FileNotFoundError
|
|
130
|
-
|
|
131
|
-
# And if 'custom_private_key_path' field was populated in [advanced] section, we'll check its existence.
|
|
132
|
-
if self.config['certificates']['custom_private_key_path']:
|
|
133
|
-
# Check private key file existence.
|
|
134
|
-
if not filesystem.is_file_exists(file_path=self.config['certificates']['custom_private_key_path']):
|
|
135
|
-
raise FileNotFoundError
|
|
136
|
-
|
|
137
|
-
skip_extensions: list = list()
|
|
138
|
-
if self.config['skip_extensions']['tls_web_client_authentication']:
|
|
139
|
-
skip_extensions.append('1.3.6.1.5.5.7.3.2')
|
|
140
|
-
if self.config['skip_extensions']['crl_distribution_points']:
|
|
141
|
-
skip_extensions.append('2.5.29.31')
|
|
142
|
-
if self.config['skip_extensions']['authority_information_access']:
|
|
143
|
-
skip_extensions.append('1.3.6.1.5.5.7.1.1')
|
|
144
|
-
|
|
145
|
-
self.config['skip_extensions'] = skip_extensions
|
|
62
|
+
is_admin = permissions.is_admin()
|
|
63
|
+
|
|
64
|
+
# Check if both DNS and TCP servers are disabled. ==============================================================
|
|
65
|
+
if not config_static.DNSServer.enable and not config_static.TCPServer.enable:
|
|
66
|
+
print_api("Both DNS and TCP servers in config ini file, nothing to run. Exiting...", color='red')
|
|
67
|
+
return 1
|
|
68
|
+
|
|
69
|
+
# Check [tcp_server] boolean configurations. ===================================================================
|
|
70
|
+
if not config_static.TCPServer.engines_usage and config_static.TCPServer.server_response_mode:
|
|
71
|
+
message = "You can't set [server_response_mode = True], while setting\n" \
|
|
72
|
+
"[engines_usage = False].\n" \
|
|
73
|
+
"No engine modules will be loaded - so nothing to respond to.\n" \
|
|
74
|
+
"Exiting..."
|
|
75
|
+
print_api(message, color='red')
|
|
76
|
+
return 1
|
|
77
|
+
|
|
78
|
+
# Check admin right if on localhost ============================================================================
|
|
79
|
+
# If the 'config.dns['target_tcp_server_ipv4']' IP address is localhost, then we need to check if the script
|
|
80
|
+
# is executed with admin rights. There are some processes that 'psutil' can't get their command line if not
|
|
81
|
+
# executed with administrative privileges.
|
|
82
|
+
# Also, check Admin privileges only if 'config.tcp['get_process_name']' was set to 'True' in 'config.ini' of
|
|
83
|
+
# the script.
|
|
84
|
+
if (config_static.DNSServer.target_tcp_server_ipv4 in base.THIS_DEVICE_IP_LIST and
|
|
85
|
+
config_static.ProcessName.get_process_name):
|
|
86
|
+
# If we're not running with admin rights, prompt to the user and make him decide what to do.
|
|
87
|
+
# If he wants to continue running with 'psutil' exceptions or close the script and rerun with admin rights.
|
|
88
|
+
if not is_admin:
|
|
89
|
+
message: str = \
|
|
90
|
+
("Need to run the script with administrative rights to get the process name while TCP running "
|
|
91
|
+
"on the same computer.\nExiting...")
|
|
92
|
+
print_api(message, color='red')
|
|
93
|
+
return 1
|
|
94
|
+
|
|
95
|
+
if config_static.DNSServer.set_default_dns_gateway or \
|
|
96
|
+
config_static.DNSServer.set_default_dns_gateway_to_localhost or \
|
|
97
|
+
config_static.DNSServer.set_default_dns_gateway_to_default_interface_ipv4:
|
|
98
|
+
try:
|
|
99
|
+
booleans.check_3_booleans_when_only_1_can_be_true(
|
|
100
|
+
(config_static.DNSServer.set_default_dns_gateway, '[dns][set_default_dns_gateway]'),
|
|
101
|
+
(config_static.DNSServer.set_default_dns_gateway_to_localhost,
|
|
102
|
+
'[dns][set_default_dns_gateway_to_localhost]'),
|
|
103
|
+
(config_static.DNSServer.set_default_dns_gateway_to_default_interface_ipv4,
|
|
104
|
+
'[dns][set_default_dns_gateway_to_default_interface_ipv4]'))
|
|
105
|
+
except ValueError as e:
|
|
106
|
+
print_api(str(e), color='red')
|
|
107
|
+
return 1
|
|
108
|
+
|
|
109
|
+
if (config_static.DNSServer.set_default_dns_gateway or
|
|
110
|
+
config_static.DNSServer.set_default_dns_gateway_to_localhost or
|
|
111
|
+
config_static.DNSServer.set_default_dns_gateway_to_default_interface_ipv4):
|
|
112
|
+
is_dns_dynamic, current_dns_gateway = dns.get_default_dns_gateway()
|
|
113
|
+
if is_dns_dynamic and not is_admin:
|
|
114
|
+
message: str = \
|
|
115
|
+
"Need to run the script with administrative rights to set the default DNS gateway.\nExiting..."
|
|
116
|
+
print_api(message, color='red')
|
|
117
|
+
return 1
|
|
118
|
+
|
|
119
|
+
return 0
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def manipulations_after_import():
|
|
123
|
+
# Convert extensions to skip to a list of extension IDs.
|
|
124
|
+
skip_extensions: list = list()
|
|
125
|
+
if config_static.SkipExtensions.tls_web_client_authentication:
|
|
126
|
+
skip_extensions.append('1.3.6.1.5.5.7.3.2')
|
|
127
|
+
if config_static.SkipExtensions.crl_distribution_points:
|
|
128
|
+
skip_extensions.append('2.5.29.31')
|
|
129
|
+
if config_static.SkipExtensions.authority_information_access:
|
|
130
|
+
skip_extensions.append('1.3.6.1.5.5.7.1.1')
|
|
131
|
+
config_static.SkipExtensions.SKIP_EXTENSION_ID_LIST = skip_extensions
|
|
132
|
+
|
|
133
|
+
# If the paths are relative, convert them to absolute paths.
|
|
134
|
+
config_static.Log.logs_path = filesystem.check_absolute_path___add_full(
|
|
135
|
+
config_static.Log.logs_path, config_static.MainConfig.SCRIPT_DIRECTORY)
|
|
136
|
+
config_static.Recorder.recordings_path = filesystem.check_absolute_path___add_full(
|
|
137
|
+
config_static.Recorder.recordings_path, config_static.MainConfig.SCRIPT_DIRECTORY)
|
|
138
|
+
config_static.Certificates.custom_server_certificate_path = filesystem.check_absolute_path___add_full(
|
|
139
|
+
config_static.Certificates.custom_server_certificate_path, config_static.MainConfig.SCRIPT_DIRECTORY)
|
|
140
|
+
|
|
141
|
+
# At this point the user that sets the config can set it to null or empty string ''. We will make sure
|
|
142
|
+
# that the path is None if it's empty.
|
|
143
|
+
if config_static.Certificates.custom_private_key_path:
|
|
144
|
+
config_static.Certificates.custom_private_key_path = filesystem.check_absolute_path___add_full(
|
|
145
|
+
config_static.Certificates.custom_private_key_path, config_static.MainConfig.SCRIPT_DIRECTORY)
|
|
146
|
+
else:
|
|
147
|
+
config_static.Certificates.custom_private_key_path = None
|
|
148
|
+
|
|
149
|
+
config_static.Certificates.sni_server_certificates_cache_directory = filesystem.check_absolute_path___add_full(
|
|
150
|
+
config_static.Certificates.sni_server_certificates_cache_directory, config_static.MainConfig.SCRIPT_DIRECTORY)
|
|
151
|
+
config_static.Certificates.sni_server_certificate_from_server_socket_download_directory = \
|
|
152
|
+
filesystem.check_absolute_path___add_full(
|
|
153
|
+
config_static.Certificates.sni_server_certificate_from_server_socket_download_directory,
|
|
154
|
+
config_static.MainConfig.SCRIPT_DIRECTORY)
|
|
@@ -96,7 +96,12 @@ class ModuleCategory:
|
|
|
96
96
|
# Assigning external class object by message domain received from client. If the domain is not in the list,
|
|
97
97
|
# the reference general module will be assigned.
|
|
98
98
|
def assign_class_by_domain(
|
|
99
|
-
|
|
99
|
+
engines_usage: bool,
|
|
100
|
+
engines_list: list,
|
|
101
|
+
message_domain_name: str,
|
|
102
|
+
reference_module,
|
|
103
|
+
logger=None
|
|
104
|
+
):
|
|
100
105
|
# Defining return variables:
|
|
101
106
|
function_parser = None
|
|
102
107
|
function_responder = None
|
|
@@ -106,7 +111,7 @@ def assign_class_by_domain(
|
|
|
106
111
|
if message_domain_name:
|
|
107
112
|
# If the engines_usage is set to True in the config file, then we'll iterate through the list of engines
|
|
108
113
|
# to find the domain in the list of domains of the engine.
|
|
109
|
-
if
|
|
114
|
+
if engines_usage:
|
|
110
115
|
# Checking if current domain is in engines' domain list to activate domain specific engine
|
|
111
116
|
for function_module in engines_list:
|
|
112
117
|
# The list: matches_list = ["domain1.com", "domain2.com", "domain3.com"]
|