atomicshop 2.21.0__py3-none-any.whl → 3.0.0__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/basics/multiprocesses.py +228 -30
- atomicshop/dns.py +2 -0
- atomicshop/mitm/config_static.py +2 -1
- atomicshop/mitm/connection_thread_worker.py +124 -157
- atomicshop/mitm/engines/__parent/responder___parent.py +43 -43
- atomicshop/mitm/engines/__reference_general/responder___reference_general.py +43 -43
- atomicshop/mitm/engines/create_module_template.py +2 -7
- atomicshop/mitm/import_config.py +30 -26
- atomicshop/mitm/initialize_engines.py +9 -24
- atomicshop/mitm/mitm_main.py +187 -59
- atomicshop/networks.py +448 -0
- atomicshop/wrappers/ctyping/setup_device.py +466 -0
- atomicshop/wrappers/dockerw/dockerw.py +17 -21
- atomicshop/wrappers/mongodbw/mongodbw.py +1 -0
- atomicshop/wrappers/psutilw/{networks.py → psutil_networks.py} +3 -1
- atomicshop/wrappers/pywin32w/wmis/msft_netipaddress.py +76 -0
- atomicshop/wrappers/pywin32w/wmis/win32_networkadapterconfiguration.py +262 -0
- atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +51 -82
- atomicshop/wrappers/pywin32w/wmis/wmi_helpers.py +235 -0
- atomicshop/wrappers/socketw/accepter.py +15 -1
- atomicshop/wrappers/socketw/creator.py +7 -1
- atomicshop/wrappers/socketw/dns_server.py +33 -39
- atomicshop/wrappers/socketw/exception_wrapper.py +20 -11
- atomicshop/wrappers/socketw/socket_wrapper.py +29 -78
- atomicshop/wrappers/winregw/winreg_network.py +20 -0
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/METADATA +2 -1
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/RECORD +31 -27
- atomicshop/wrappers/pywin32w/wmis/helpers.py +0 -131
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/LICENSE.txt +0 -0
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/WHEEL +0 -0
- {atomicshop-2.21.0.dist-info → atomicshop-3.0.0.dist-info}/top_level.txt +0 -0
atomicshop/mitm/import_config.py
CHANGED
|
@@ -151,37 +151,41 @@ def check_configurations() -> int:
|
|
|
151
151
|
print_api(error_message, color="red")
|
|
152
152
|
return 1
|
|
153
153
|
|
|
154
|
+
is_localhost: bool | None = None
|
|
154
155
|
for engine in config_static.ENGINES_LIST:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if engine.no_sni.serve_domain_on_address_enable:
|
|
169
|
-
# Check if the domains in no_sni are the same as in the engine. They should not be.
|
|
170
|
-
# Same goes for the address.
|
|
171
|
-
for domain, address_ip_port in engine.no_sni.serve_domain_on_address_dict.items():
|
|
172
|
-
if domain in engine.domain_list:
|
|
156
|
+
for domain_port in engine.domain_list:
|
|
157
|
+
# Check if the domains has port.
|
|
158
|
+
if ':' not in domain_port:
|
|
159
|
+
message = (
|
|
160
|
+
f"[*] Domain [{domain_port}] doesn't have a port.\n"
|
|
161
|
+
f"Please check your engine configuration file.")
|
|
162
|
+
print_api(message, color="red")
|
|
163
|
+
return 1
|
|
164
|
+
else:
|
|
165
|
+
# Split the domain and port.
|
|
166
|
+
domain, port = domain_port.split(':')
|
|
167
|
+
# Check if the port is a number.
|
|
168
|
+
if not port.isdigit():
|
|
173
169
|
message = (
|
|
174
|
-
f"[*]
|
|
175
|
-
f"
|
|
170
|
+
f"[*] Port [{port}] is not a number.\n"
|
|
171
|
+
f"Please check your engine configuration file.")
|
|
176
172
|
print_api(message, color="red")
|
|
177
173
|
return 1
|
|
178
174
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
175
|
+
# Check if 'localhost' is set in all the engines, or not.
|
|
176
|
+
# There can't be mixed engines where local host is set and not set.
|
|
177
|
+
# It can be all engines will be localhost or none of them.
|
|
178
|
+
if is_localhost is None:
|
|
179
|
+
is_localhost = engine.is_localhost
|
|
180
|
+
else:
|
|
181
|
+
if is_localhost != engine.is_localhost:
|
|
182
|
+
message = (
|
|
183
|
+
f"[*] Mixed [localhost] setting in the engines found.\n"
|
|
184
|
+
f"[*] Some engines are set to [localhost] and some are not.\n"
|
|
185
|
+
f"[*] This is not allowed. All engines must be set to [localhost = 1] or All engines must be set to [localhost = 0].\n"
|
|
186
|
+
f"Please check your engine configuration files.")
|
|
187
|
+
print_api(message, color="red")
|
|
188
|
+
return 1
|
|
185
189
|
|
|
186
190
|
# Check admin right if on localhost ============================================================================
|
|
187
191
|
# If any of the DNS IP target addresses is localhost loopback, then we need to check if the script
|
|
@@ -7,23 +7,15 @@ from .engines.__reference_general import parser___reference_general, responder__
|
|
|
7
7
|
recorder___reference_general
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class NoSNI:
|
|
11
|
-
def __init__(self):
|
|
12
|
-
self.get_from_dns: bool = False
|
|
13
|
-
self.serve_domain_on_address_enable: bool = False
|
|
14
|
-
self.serve_domain_on_address_dict: dict = dict()
|
|
15
|
-
|
|
16
|
-
|
|
17
10
|
class ModuleCategory:
|
|
18
11
|
def __init__(self, script_directory: str):
|
|
19
12
|
self.engine_name: str = str()
|
|
20
13
|
self.script_directory: str = script_directory
|
|
21
14
|
|
|
22
15
|
self.domain_list: list = list()
|
|
23
|
-
self.
|
|
24
|
-
self.
|
|
16
|
+
self.domain_target_dict: dict = dict()
|
|
17
|
+
self.is_localhost: bool = bool()
|
|
25
18
|
self.mtls: dict = dict()
|
|
26
|
-
self.no_sni: NoSNI = NoSNI()
|
|
27
19
|
|
|
28
20
|
self.parser_file_path: str = str()
|
|
29
21
|
self.responder_file_path: str = str()
|
|
@@ -51,24 +43,11 @@ class ModuleCategory:
|
|
|
51
43
|
|
|
52
44
|
# Getting the parameters from engine config file
|
|
53
45
|
self.domain_list = configuration_data['engine']['domains']
|
|
54
|
-
self.
|
|
55
|
-
self.tcp_listening_address_list = configuration_data['engine']['tcp_listening_address_list']
|
|
46
|
+
self.is_localhost = bool(configuration_data['engine']['localhost'])
|
|
56
47
|
|
|
57
48
|
if 'mtls' in configuration_data:
|
|
58
49
|
self.mtls = configuration_data['mtls']
|
|
59
50
|
|
|
60
|
-
self.no_sni.get_from_dns = bool(configuration_data['no_sni']['get_from_dns'])
|
|
61
|
-
|
|
62
|
-
for enable_bool, address_list in configuration_data['no_sni']['serve_domain_on_address'].items():
|
|
63
|
-
if enable_bool in ['0', '1']:
|
|
64
|
-
self.no_sni.serve_domain_on_address_enable = bool(int(enable_bool))
|
|
65
|
-
else:
|
|
66
|
-
raise ValueError(f"Error: no_sni -> serve_domain_on_address -> key must be 0 or 1.")
|
|
67
|
-
|
|
68
|
-
for address in address_list:
|
|
69
|
-
for domain, address_ip_port in address.items():
|
|
70
|
-
self.no_sni.serve_domain_on_address_dict = {domain: address_ip_port}
|
|
71
|
-
|
|
72
51
|
# If there's module configuration file, but no domains in it, there's no point to continue.
|
|
73
52
|
# Since, each engine is based on domains.
|
|
74
53
|
if not self.domain_list or self.domain_list[0] == '':
|
|
@@ -86,6 +65,12 @@ class ModuleCategory:
|
|
|
86
65
|
self.responder_file_path = f"{engine_directory_path}{os.sep}responder{file_name_suffix}.py"
|
|
87
66
|
self.recorder_file_path = f"{engine_directory_path}{os.sep}recorder{file_name_suffix}.py"
|
|
88
67
|
|
|
68
|
+
for domain_index, domain_port_string in enumerate(self.domain_list):
|
|
69
|
+
# Splitting the domain and port
|
|
70
|
+
domain, port = domain_port_string.split(':')
|
|
71
|
+
|
|
72
|
+
self.domain_target_dict[domain] = {'ip': None, 'port': port}
|
|
73
|
+
|
|
89
74
|
for subdomain, file_name in self.mtls.items():
|
|
90
75
|
self.mtls[subdomain] = f'{engine_directory_path}{os.sep}{file_name}'
|
|
91
76
|
|
atomicshop/mitm/mitm_main.py
CHANGED
|
@@ -6,21 +6,59 @@ import os
|
|
|
6
6
|
|
|
7
7
|
import atomicshop # Importing atomicshop package to get the version of the package.
|
|
8
8
|
|
|
9
|
-
from .. import filesystem,
|
|
9
|
+
from .. import filesystem, on_exit, print_api, networks, dns
|
|
10
10
|
from ..permissions import permissions
|
|
11
11
|
from ..python_functions import get_current_python_version_string, check_python_version_compliance
|
|
12
12
|
from ..wrappers.socketw import socket_wrapper, dns_server, base
|
|
13
13
|
from ..wrappers.loggingw import loggingw
|
|
14
14
|
from ..wrappers.ctyping import win_console
|
|
15
15
|
|
|
16
|
-
from .initialize_engines import ModuleCategory
|
|
17
16
|
from .connection_thread_worker import thread_worker_main
|
|
18
17
|
from . import config_static, recs_files
|
|
19
18
|
|
|
20
19
|
|
|
20
|
+
class NetworkSettings:
|
|
21
|
+
"""
|
|
22
|
+
Class to store network settings.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
description: str | None = None,
|
|
28
|
+
interface_index: int | None = None,
|
|
29
|
+
is_dynamic: bool = False,
|
|
30
|
+
ipv4s: list[str] = None,
|
|
31
|
+
ipv6s: list[str] = None,
|
|
32
|
+
ipv4_subnet_masks: list[str] = None,
|
|
33
|
+
ipv6_prefixes: list[str] = None,
|
|
34
|
+
default_gateways: list[str] = None,
|
|
35
|
+
dns_gateways: list[str] = None
|
|
36
|
+
):
|
|
37
|
+
|
|
38
|
+
self.description: str | None = description
|
|
39
|
+
self.interface_index: int | None = interface_index
|
|
40
|
+
self.is_dynamic: bool = is_dynamic
|
|
41
|
+
self.ipv4s: list[str] = ipv4s if ipv4s is not None else list()
|
|
42
|
+
self.ipv6s: list[str] = ipv6s if ipv6s is not None else list()
|
|
43
|
+
self.ipv4_subnet_masks: list[str] = ipv4_subnet_masks if ipv4_subnet_masks is not None else list()
|
|
44
|
+
self.ipv6_prefixes: list[str] = ipv6_prefixes if ipv6_prefixes is not None else list()
|
|
45
|
+
self.default_gateways: list[str] = default_gateways if default_gateways is not None else list()
|
|
46
|
+
self.dns_gateways: list[str] = dns_gateways if dns_gateways is not None else list()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Global variables for setting the network interface to external IPs (eg: 192.168.0.1)
|
|
50
|
+
NETWORK_INTERFACE_SETTINGS: NetworkSettings = NetworkSettings()
|
|
51
|
+
CURRENT_IPV4S: list[str] = list()
|
|
52
|
+
CURRENT_IPV4_MASKS: list[str] = list()
|
|
53
|
+
IPS_TO_ASSIGN: list[str] = list()
|
|
54
|
+
MASKS_TO_ASSIGN: list[str] = list()
|
|
55
|
+
|
|
56
|
+
# Global variables for setting the network interface to localhost IPs (eg: 127.0.0.1), Only DNS gateway is set.
|
|
21
57
|
NETWORK_INTERFACE_IS_DYNAMIC: bool = bool()
|
|
22
58
|
NETWORK_INTERFACE_IPV4_ADDRESS_LIST: list[str] = list()
|
|
23
59
|
IS_SET_DNS_GATEWAY: bool = False
|
|
60
|
+
|
|
61
|
+
|
|
24
62
|
# noinspection PyTypeChecker
|
|
25
63
|
RECS_PROCESS_INSTANCE: multiprocessing.Process = None
|
|
26
64
|
|
|
@@ -30,9 +68,6 @@ EXCEPTIONS_CSV_LOGGER_HEADER: str = 'time,exception'
|
|
|
30
68
|
# noinspection PyTypeChecker
|
|
31
69
|
MITM_ERROR_LOGGER: loggingw.ExceptionCsvLogger = None
|
|
32
70
|
|
|
33
|
-
# Create request domain queue.
|
|
34
|
-
DOMAIN_QUEUE: multiprocessing.Queue = multiprocessing.Queue()
|
|
35
|
-
|
|
36
71
|
# Create logger's queue.
|
|
37
72
|
NETWORK_LOGGER_QUEUE: multiprocessing.Queue = multiprocessing.Queue()
|
|
38
73
|
|
|
@@ -44,20 +79,39 @@ except win_console.NotWindowsConsoleError:
|
|
|
44
79
|
|
|
45
80
|
|
|
46
81
|
def exit_cleanup():
|
|
47
|
-
if
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
82
|
+
if config_static.ENGINES_LIST[0].is_localhost:
|
|
83
|
+
if permissions.is_admin() and IS_SET_DNS_GATEWAY:
|
|
84
|
+
is_dns_dynamic, current_dns_gateway = dns.get_default_dns_gateway()
|
|
85
|
+
status_string = 'Dynamic' if is_dns_dynamic else 'Static'
|
|
86
|
+
print_api.print_api(f'Current DNS Gateway: {status_string}, {current_dns_gateway}')
|
|
87
|
+
|
|
88
|
+
if is_dns_dynamic != NETWORK_INTERFACE_IS_DYNAMIC or \
|
|
89
|
+
(not is_dns_dynamic and current_dns_gateway != NETWORK_INTERFACE_IPV4_ADDRESS_LIST):
|
|
90
|
+
if NETWORK_INTERFACE_IS_DYNAMIC:
|
|
91
|
+
dns.set_connection_dns_gateway_dynamic(use_default_connection=True)
|
|
92
|
+
else:
|
|
93
|
+
dns.set_connection_dns_gateway_static(
|
|
94
|
+
dns_servers=NETWORK_INTERFACE_IPV4_ADDRESS_LIST, use_default_connection=True)
|
|
51
95
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
dns.set_connection_dns_gateway_static(
|
|
58
|
-
dns_servers=NETWORK_INTERFACE_IPV4_ADDRESS_LIST, use_default_connection=True)
|
|
96
|
+
print_api.print_api("Returned default DNS gateway...", color='blue')
|
|
97
|
+
else:
|
|
98
|
+
# Get current network interface state.
|
|
99
|
+
default_network_adapter_config, default_network_adapter, default_adapter_info = networks.get_wmi_network_adapter_configuration(
|
|
100
|
+
use_default_interface=True, get_info_from_network_config=True)
|
|
59
101
|
|
|
60
|
-
|
|
102
|
+
if NETWORK_INTERFACE_SETTINGS.is_dynamic:
|
|
103
|
+
# If the network interface was dynamic before the script started, we will return it to dynamic.
|
|
104
|
+
networks.set_dynamic_ip_for_adapter(default_network_adapter_config)
|
|
105
|
+
else:
|
|
106
|
+
networks.set_static_ip_for_adapter(
|
|
107
|
+
default_network_adapter,
|
|
108
|
+
ips=NETWORK_INTERFACE_SETTINGS.ipv4s,
|
|
109
|
+
masks=NETWORK_INTERFACE_SETTINGS.ipv4_subnet_masks,
|
|
110
|
+
gateways=NETWORK_INTERFACE_SETTINGS.default_gateways,
|
|
111
|
+
dns_gateways=NETWORK_INTERFACE_SETTINGS.dns_gateways
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
print_api.print_api("Returned network adapter settings...", color='blue')
|
|
61
115
|
|
|
62
116
|
# The process will not be executed if there was an exception in the beginning.
|
|
63
117
|
if RECS_PROCESS_INSTANCE is not None:
|
|
@@ -137,16 +191,12 @@ def startup_output(system_logger, script_version: str):
|
|
|
137
191
|
f"{engine.recorder_class_object.__name__}")
|
|
138
192
|
print_api.print_api(message, logger=system_logger)
|
|
139
193
|
print_api.print_api(f"[*] Name: {engine.engine_name}", logger=system_logger)
|
|
140
|
-
print_api.print_api(f"[*] Domains: {engine.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if engine.no_sni.serve_domain_on_address_enable:
|
|
147
|
-
print_api.print_api(
|
|
148
|
-
f"[*] No SNI setting: The DNS Server will send the domains to interfaces [{engine.no_sni.serve_domain_on_address_dict}]",
|
|
149
|
-
logger=system_logger)
|
|
194
|
+
print_api.print_api(f"[*] Domains: {list(engine.domain_target_dict.keys())}", logger=system_logger)
|
|
195
|
+
dns_targets: list = list()
|
|
196
|
+
for domain, ip_port in engine.domain_target_dict.items():
|
|
197
|
+
dns_targets.append(ip_port['ip'])
|
|
198
|
+
print_api.print_api(f"[*] DNS Targets: {dns_targets}", logger=system_logger)
|
|
199
|
+
# print_api.print_api(f"[*] TCP Listening Interfaces: {engine.tcp_listening_address_list}", logger=system_logger)
|
|
150
200
|
|
|
151
201
|
if config_static.DNSServer.enable:
|
|
152
202
|
print_api.print_api("DNS Server is enabled.", logger=system_logger)
|
|
@@ -178,6 +228,68 @@ def startup_output(system_logger, script_version: str):
|
|
|
178
228
|
print_api.print_api("TCP Server is disabled.", logger=system_logger, color="yellow")
|
|
179
229
|
|
|
180
230
|
|
|
231
|
+
def get_ipv4s_for_tcp_server():
|
|
232
|
+
"""
|
|
233
|
+
Function to get the IPv4 addresses for the default network adapter to set them to the adapter.
|
|
234
|
+
"""
|
|
235
|
+
|
|
236
|
+
# Create a list of all the domains in all the engines.
|
|
237
|
+
domains_to_create_ips_for: list[str] = list()
|
|
238
|
+
for engine in config_static.ENGINES_LIST:
|
|
239
|
+
domains_to_create_ips_for += list(engine.domain_target_dict.keys())
|
|
240
|
+
|
|
241
|
+
engine_ips: list[str] = list()
|
|
242
|
+
# Check if we need the localhost ips (12.0.0.1) or external local ips (192.168.0.100).
|
|
243
|
+
if config_static.ENGINES_LIST[0].is_localhost:
|
|
244
|
+
create_ips: int = len(domains_to_create_ips_for)
|
|
245
|
+
|
|
246
|
+
# Generate the list of localhost ips.
|
|
247
|
+
for i in range(create_ips):
|
|
248
|
+
engine_ips.append(f"127.0.0.{i+1}")
|
|
249
|
+
else:
|
|
250
|
+
# Get current network interface state.
|
|
251
|
+
default_network_adapter_config, default_network_adapter, default_adapter_info = networks.get_wmi_network_adapter_configuration(
|
|
252
|
+
use_default_interface=True, get_info_from_network_config=True)
|
|
253
|
+
|
|
254
|
+
global NETWORK_INTERFACE_SETTINGS
|
|
255
|
+
NETWORK_INTERFACE_SETTINGS = NetworkSettings(
|
|
256
|
+
description=default_adapter_info['description'],
|
|
257
|
+
interface_index=default_adapter_info['interface_index'],
|
|
258
|
+
is_dynamic=default_adapter_info['is_dynamic'],
|
|
259
|
+
ipv4s=default_adapter_info['ipv4s'],
|
|
260
|
+
ipv6s=default_adapter_info['ipv6s'],
|
|
261
|
+
ipv4_subnet_masks=default_adapter_info['ipv4_subnet_masks'],
|
|
262
|
+
ipv6_prefixes=default_adapter_info['ipv6_prefixes'],
|
|
263
|
+
default_gateways=default_adapter_info['default_gateways'],
|
|
264
|
+
dns_gateways=default_adapter_info['dns_gateways']
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
# Adding IP addresses to the default network adapter.
|
|
268
|
+
current_ipv4s: list[str] = default_adapter_info['ipv4s']
|
|
269
|
+
current_ips_count: int = len(current_ipv4s)
|
|
270
|
+
|
|
271
|
+
# If the number of currently assigned IPs is smaller than the number of IPs to create,
|
|
272
|
+
# subtract the current IPs count from the number of IPs to create, to create only what is missing.
|
|
273
|
+
create_ips: int = len(domains_to_create_ips_for)
|
|
274
|
+
if current_ips_count <= create_ips:
|
|
275
|
+
create_ips -= current_ips_count
|
|
276
|
+
|
|
277
|
+
# Generate the IPs for the domains.
|
|
278
|
+
global CURRENT_IPV4S, CURRENT_IPV4_MASKS, IPS_TO_ASSIGN, MASKS_TO_ASSIGN
|
|
279
|
+
CURRENT_IPV4S, CURRENT_IPV4_MASKS, IPS_TO_ASSIGN, MASKS_TO_ASSIGN = networks.add_virtual_ips_to_default_adapter_by_current_setting(
|
|
280
|
+
number_of_ips=create_ips,
|
|
281
|
+
simulate_only=True)
|
|
282
|
+
|
|
283
|
+
engine_ips += CURRENT_IPV4S + IPS_TO_ASSIGN
|
|
284
|
+
|
|
285
|
+
# Add the ips to engines.
|
|
286
|
+
for engine in config_static.ENGINES_LIST:
|
|
287
|
+
for domain in engine.domain_target_dict.keys():
|
|
288
|
+
# If the domain is in the list of domains to create IPs for, add the IP to the engine.
|
|
289
|
+
if domain in domains_to_create_ips_for:
|
|
290
|
+
engine.domain_target_dict[domain]['ip'] = engine_ips.pop(0)
|
|
291
|
+
|
|
292
|
+
|
|
181
293
|
def mitm_server(config_file_path: str, script_version: str):
|
|
182
294
|
on_exit.register_exit_handler(exit_cleanup, at_exit=False, kill_signal=False)
|
|
183
295
|
|
|
@@ -192,6 +304,9 @@ def mitm_server(config_file_path: str, script_version: str):
|
|
|
192
304
|
if result != 0:
|
|
193
305
|
return result
|
|
194
306
|
|
|
307
|
+
# Get the IPs that will be set for the adapter and fill the engine configuration with the IPs.
|
|
308
|
+
get_ipv4s_for_tcp_server()
|
|
309
|
+
|
|
195
310
|
global MITM_ERROR_LOGGER
|
|
196
311
|
MITM_ERROR_LOGGER = loggingw.ExceptionCsvLogger(
|
|
197
312
|
logger_name=EXCEPTIONS_CSV_LOGGER_NAME, directory_path=config_static.LogRec.logs_path)
|
|
@@ -253,7 +368,6 @@ def mitm_server(config_file_path: str, script_version: str):
|
|
|
253
368
|
config_static.DNSServer.resolve_all_domains_to_ipv4_enable, config_static.DNSServer.target_ipv4),
|
|
254
369
|
'offline_mode': config_static.MainConfig.offline,
|
|
255
370
|
'cache_timeout_minutes': config_static.DNSServer.cache_timeout_minutes,
|
|
256
|
-
'request_domain_queue': DOMAIN_QUEUE,
|
|
257
371
|
'logging_queue': NETWORK_LOGGER_QUEUE,
|
|
258
372
|
'logger_name': network_logger_name
|
|
259
373
|
},
|
|
@@ -331,7 +445,6 @@ def mitm_server(config_file_path: str, script_version: str):
|
|
|
331
445
|
statistics_logs_directory=config_static.LogRec.logs_path,
|
|
332
446
|
forwarding_dns_service_ipv4_list___only_for_localhost=[config_static.DNSServer.forwarding_dns_service_ipv4],
|
|
333
447
|
skip_extension_id_list=config_static.SkipExtensions.SKIP_EXTENSION_ID_LIST,
|
|
334
|
-
request_domain_from_dns_server_queue=DOMAIN_QUEUE,
|
|
335
448
|
no_engine_usage_enable=config_static.TCPServer.no_engines_usage_to_listen_addresses_enable,
|
|
336
449
|
no_engines_listening_address_list=config_static.TCPServer.no_engines_listening_address_list,
|
|
337
450
|
engines_list=config_static.ENGINES_LIST
|
|
@@ -349,42 +462,57 @@ def mitm_server(config_file_path: str, script_version: str):
|
|
|
349
462
|
network_logger_queue_listener.stop()
|
|
350
463
|
return 1
|
|
351
464
|
|
|
352
|
-
#
|
|
353
|
-
|
|
354
|
-
|
|
465
|
+
# ----------------------- Get the default network adapter configuration. --------------------------
|
|
466
|
+
# This setting is needed only for the dns gateways configurations from the main config on localhost.
|
|
467
|
+
set_local_dns_gateway: bool = False
|
|
468
|
+
# Set the default gateway if specified.
|
|
355
469
|
if config_static.DNSServer.set_default_dns_gateway:
|
|
356
470
|
dns_gateway_server_list = config_static.DNSServer.set_default_dns_gateway
|
|
357
|
-
|
|
471
|
+
set_local_dns_gateway = True
|
|
358
472
|
elif config_static.DNSServer.set_default_dns_gateway_to_localhost:
|
|
359
473
|
dns_gateway_server_list = [base.LOCALHOST_IPV4]
|
|
360
|
-
|
|
474
|
+
set_local_dns_gateway = True
|
|
361
475
|
elif config_static.DNSServer.set_default_dns_gateway_to_default_interface_ipv4:
|
|
362
476
|
dns_gateway_server_list = [base.DEFAULT_IPV4]
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
477
|
+
set_local_dns_gateway = True
|
|
478
|
+
else:
|
|
479
|
+
dns_gateway_server_list = NETWORK_INTERFACE_SETTINGS.dns_gateways
|
|
480
|
+
|
|
481
|
+
if config_static.ENGINES_LIST[0].is_localhost:
|
|
482
|
+
if set_local_dns_gateway:
|
|
483
|
+
global IS_SET_DNS_GATEWAY
|
|
484
|
+
IS_SET_DNS_GATEWAY = True
|
|
485
|
+
|
|
486
|
+
# Get current network interface state.
|
|
487
|
+
global NETWORK_INTERFACE_IS_DYNAMIC, NETWORK_INTERFACE_IPV4_ADDRESS_LIST
|
|
488
|
+
NETWORK_INTERFACE_IS_DYNAMIC, NETWORK_INTERFACE_IPV4_ADDRESS_LIST = dns.get_default_dns_gateway()
|
|
489
|
+
|
|
490
|
+
# Set the DNS gateway to the specified one only if the DNS gateway is dynamic, or it is static but different
|
|
491
|
+
# from the one specified in the configuration file.
|
|
492
|
+
if (NETWORK_INTERFACE_IS_DYNAMIC or (not NETWORK_INTERFACE_IS_DYNAMIC and
|
|
493
|
+
NETWORK_INTERFACE_IPV4_ADDRESS_LIST != dns_gateway_server_list)):
|
|
494
|
+
try:
|
|
495
|
+
dns.set_connection_dns_gateway_static(
|
|
496
|
+
dns_servers=dns_gateway_server_list,
|
|
497
|
+
use_default_connection=True
|
|
498
|
+
)
|
|
499
|
+
except PermissionError as e:
|
|
500
|
+
print_api.print_api(e, error_type=True, color="red", logger=system_logger)
|
|
501
|
+
# Wait for the message to be printed and saved to file.
|
|
502
|
+
time.sleep(1)
|
|
503
|
+
network_logger_queue_listener.stop()
|
|
504
|
+
return 1
|
|
505
|
+
else:
|
|
506
|
+
# Change the adapter settings and add the virtual IPs.
|
|
507
|
+
try:
|
|
508
|
+
networks.add_virtual_ips_to_default_adapter_by_current_setting(
|
|
509
|
+
virtual_ipv4s_to_add=IPS_TO_ASSIGN, virtual_ipv4_masks_to_add=MASKS_TO_ASSIGN, dns_gateways=dns_gateway_server_list)
|
|
510
|
+
except PermissionError as e:
|
|
511
|
+
print_api.print_api(e, error_type=True, color="red", logger=system_logger)
|
|
512
|
+
# Wait for the message to be printed and saved to file.
|
|
513
|
+
time.sleep(1)
|
|
514
|
+
network_logger_queue_listener.stop()
|
|
515
|
+
return 1
|
|
388
516
|
|
|
389
517
|
statistics_writer = socket_wrapper_instance.statistics_writer
|
|
390
518
|
|