atomicshop 2.15.13__py3-none-any.whl → 2.16.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.

Files changed (42) hide show
  1. atomicshop/__init__.py +1 -1
  2. atomicshop/a_mains/dns_gateway_setting.py +11 -0
  3. atomicshop/basics/booleans.py +14 -5
  4. atomicshop/dns.py +104 -0
  5. atomicshop/file_io/docxs.py +8 -0
  6. atomicshop/file_io/tomls.py +133 -0
  7. atomicshop/filesystem.py +5 -4
  8. atomicshop/get_process_list.py +3 -3
  9. atomicshop/mitm/config_static.py +195 -0
  10. atomicshop/mitm/config_toml_editor.py +55 -0
  11. atomicshop/mitm/connection_thread_worker.py +54 -90
  12. atomicshop/mitm/import_config.py +147 -139
  13. atomicshop/mitm/initialize_engines.py +7 -2
  14. atomicshop/mitm/initialize_mitm_server.py +161 -107
  15. atomicshop/mitm/shared_functions.py +0 -1
  16. atomicshop/mitm/statistic_analyzer.py +13 -1
  17. atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +54 -14
  18. atomicshop/script_as_string_processor.py +5 -1
  19. atomicshop/wrappers/cryptographyw.py +3 -3
  20. atomicshop/wrappers/psutilw/networks.py +25 -1
  21. atomicshop/wrappers/pywin32w/wmis/__init__.py +0 -0
  22. atomicshop/wrappers/pywin32w/wmis/helpers.py +127 -0
  23. atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +167 -0
  24. atomicshop/wrappers/socketw/accepter.py +8 -8
  25. atomicshop/wrappers/socketw/base.py +13 -0
  26. atomicshop/wrappers/socketw/certificator.py +202 -149
  27. atomicshop/wrappers/socketw/creator.py +15 -35
  28. atomicshop/wrappers/socketw/dns_server.py +155 -102
  29. atomicshop/wrappers/socketw/exception_wrapper.py +8 -27
  30. atomicshop/wrappers/socketw/get_process.py +115 -95
  31. atomicshop/wrappers/socketw/sni.py +298 -164
  32. atomicshop/wrappers/socketw/socket_client.py +5 -12
  33. atomicshop/wrappers/socketw/socket_server_tester.py +1 -1
  34. atomicshop/wrappers/socketw/socket_wrapper.py +328 -72
  35. atomicshop/wrappers/socketw/statistics_csv.py +94 -16
  36. {atomicshop-2.15.13.dist-info → atomicshop-2.16.0.dist-info}/METADATA +1 -1
  37. {atomicshop-2.15.13.dist-info → atomicshop-2.16.0.dist-info}/RECORD +41 -36
  38. atomicshop/mitm/config_editor.py +0 -37
  39. /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
  40. {atomicshop-2.15.13.dist-info → atomicshop-2.16.0.dist-info}/LICENSE.txt +0 -0
  41. {atomicshop-2.15.13.dist-info → atomicshop-2.16.0.dist-info}/WHEEL +0 -0
  42. {atomicshop-2.15.13.dist-info → atomicshop-2.16.0.dist-info}/top_level.txt +0 -0
@@ -9,99 +9,119 @@ from ...print_api import print_api
9
9
  import psutil
10
10
 
11
11
 
12
- def get_process_name(client_socket, config: dict, ssh_script_processor, print_kwargs: dict = None):
13
- # Get client ip and the source port.
14
- client_ip, source_port = base.get_source_address_from_socket(client_socket)
15
-
16
- # Put source port variable inside the string script.
17
- updated_script_string = ssh_script_processor.put_variable_into_script_string(source_port, print_kwargs=print_kwargs)
18
-
19
- process_name = get_process_commandline(
20
- client_ip=client_ip,
21
- username=config['ssh']['user'],
22
- password=config['ssh']['pass'],
23
- script_string=updated_script_string,
24
- print_kwargs=print_kwargs)
25
-
26
- return process_name
27
-
28
-
29
- def get_process_commandline(
30
- client_ip: str, username: str, password: str, script_string: str, print_kwargs: dict = None):
31
- execution_output = None
32
- execution_error = None
33
-
34
- # Checking if we're on localhost. If not, we'll execute SSH connection to get calling process name.
35
- if client_ip != "127.0.0.1":
36
- # Tried using paramiko SSH concurrently within threads, but with bigger loads it just breaks.
37
- # So, better using it separately for each thread.
38
-
39
- print_api(f"Initializing SSH connection to [{client_ip}]", **print_kwargs)
40
- # Initializing SSHRemote class.
41
- current_ssh_client = SSHRemote(ip_address=client_ip, username=username, password=password)
42
-
43
- execution_output, execution_error = current_ssh_client.connect_get_client_commandline(script_string)
44
- # Else, if we're on localhost, then execute the script directly without SSH.
45
- else:
46
- print_api(f"Executing LOCALHOST command to get the calling process.", **print_kwargs)
47
- # Getting the redirection from console print, since that what the 'script_string' does.
48
- with io.StringIO() as buffer, redirect_stdout(buffer):
49
- # Executing the script with print to console.
50
- try:
51
- exec(script_string)
52
- except ModuleNotFoundError as function_exception_object:
53
- execution_error = f"Module not installed: {function_exception_object}"
54
- print_api(
55
- execution_error, error_type=True, logger_method="error", traceback_string=True, oneline=True,
56
- **print_kwargs)
57
- pass
58
- except psutil.AccessDenied:
59
- execution_error = f"Access Denied for 'psutil' to read system process command line. " \
60
- f"Run script with Admin Rights."
61
- print_api(
62
- execution_error, error_type=True, logger_method="error", traceback_string=True, oneline=True,
63
- **print_kwargs)
64
- pass
65
- except Exception:
66
- execution_error = "There was undocumented exception in localhost script execution."
67
- print_api(
68
- execution_error, error_type=True, logger_method="error", traceback_string=True, oneline=True,
69
- **print_kwargs)
70
- pass
71
-
72
- if not execution_error:
73
- # Reading the buffer.
74
- execution_output = buffer.getvalue()
75
-
76
- # This section is generic for both remote SSH and localhost executions of the script.
77
- process_name = get_commandline_and_error(execution_output, execution_error, print_kwargs=print_kwargs)
78
-
79
- return process_name
80
-
81
-
82
- def get_commandline_and_error(execution_output, execution_error, print_kwargs: dict = None):
83
- # If there was known error on localhost / known error on remote or any kind of error on remote, it was
84
- # already logged, so we'll just put the error into 'process_name'.
85
- if execution_error:
86
- process_name = execution_error
87
- print_api(
88
- f"Error During Command Execution: {process_name}", error_type=True, logger_method='error', **print_kwargs)
89
- # If there wasn't any error of above types, then we can put the output from either local or remote script
90
- # execution into 'process_name' and log it / output to console.
91
- else:
92
- # If the output that was returned is not empty.
93
- if execution_output:
94
- # Replacing '\r\n' escape lines with string, so that the line will not be escaped in logs.
95
- if '\r\n' in execution_output:
96
- execution_output = execution_output.replace('\r\n', '')
97
- elif '\n' in execution_output:
98
- execution_output = execution_output.replace('\n', '')
99
-
100
- process_name = execution_output
101
- print_api(f"Client Process Command Line: {process_name}", **print_kwargs)
102
- # Else if the script output came back empty.
12
+ class GetCommandLine:
13
+ def __init__(
14
+ self,
15
+ client_socket=None,
16
+ ssh_script_processor=None,
17
+ ssh_user: str = None,
18
+ ssh_pass: str = None
19
+ ):
20
+ self.client_socket = client_socket
21
+ self.ssh_script_processor = ssh_script_processor
22
+ self.ssh_user: str = ssh_user
23
+ self.ssh_pass: str = ssh_pass
24
+
25
+ def get_process_name(self, print_kwargs: dict = None):
26
+ # Get client ip and the source port.
27
+ client_ip, source_port = base.get_source_address_from_socket(self.client_socket)
28
+
29
+ # Put source port variable inside the string script.
30
+ updated_script_string = self.ssh_script_processor.put_variable_into_script_string(
31
+ source_port, print_kwargs=print_kwargs)
32
+
33
+ process_name = self.get_process_commandline(
34
+ client_ip=client_ip,
35
+ script_string=updated_script_string,
36
+ print_kwargs=print_kwargs)
37
+
38
+ return process_name
39
+
40
+ def get_process_commandline(
41
+ self,
42
+ client_ip: str,
43
+ script_string: str,
44
+ print_kwargs: dict = None
45
+ ):
46
+ execution_output = None
47
+ execution_error = None
48
+
49
+ # Checking if we're on localhost. If not, we'll execute SSH connection to get calling process name.
50
+ if client_ip not in base.THIS_DEVICE_IP_LIST:
51
+ # Tried using paramiko SSH concurrently within threads, but with bigger loads it just breaks.
52
+ # So, better using it separately for each thread.
53
+
54
+ print_api(f"Initializing SSH connection to [{client_ip}]", **print_kwargs)
55
+ # Initializing SSHRemote class.
56
+ current_ssh_client = SSHRemote(ip_address=client_ip, username=self.ssh_user, password=self.ssh_pass)
57
+
58
+ execution_output, execution_error = current_ssh_client.connect_get_client_commandline(script_string)
59
+ # Else, if we're on localhost, then execute the script directly without SSH.
103
60
  else:
104
- process_name = "Client Process Command Line came back empty after script execution."
105
- print_api(process_name, error_type=True, logger_method='error', **print_kwargs)
106
-
107
- return process_name
61
+ print_api(f"Executing LOCALHOST command to get the calling process.", **print_kwargs)
62
+ # Getting the redirection from console print, since that what the 'script_string' does.
63
+ with io.StringIO() as buffer, redirect_stdout(buffer):
64
+ # Executing the script with print to console.
65
+ try:
66
+ exec(script_string)
67
+ except ModuleNotFoundError as function_exception_object:
68
+ execution_error = f"Module not installed: {function_exception_object}"
69
+ print_api(
70
+ execution_error, error_type=True, logger_method="error", traceback_string=True, oneline=True,
71
+ **print_kwargs)
72
+ pass
73
+ except psutil.AccessDenied:
74
+ execution_error = f"Access Denied for 'psutil' to read system process command line. " \
75
+ f"Run script with Admin Rights."
76
+ print_api(
77
+ execution_error, error_type=True, logger_method="error", traceback_string=True, oneline=True,
78
+ **print_kwargs)
79
+ pass
80
+ except Exception:
81
+ execution_error = "There was undocumented exception in localhost script execution."
82
+ print_api(
83
+ execution_error, error_type=True, logger_method="error", traceback_string=True, oneline=True,
84
+ **print_kwargs)
85
+ pass
86
+
87
+ if not execution_error:
88
+ # Reading the buffer.
89
+ execution_output = buffer.getvalue()
90
+
91
+ # This section is generic for both remote SSH and localhost executions of the script.
92
+ process_name = self.get_commandline_and_error(execution_output, execution_error, print_kwargs=print_kwargs)
93
+
94
+ return process_name
95
+
96
+ def get_commandline_and_error(
97
+ self,
98
+ execution_output,
99
+ execution_error,
100
+ print_kwargs: dict = None
101
+ ):
102
+ # If there was known error on localhost / known error on remote or any kind of error on remote, it was
103
+ # already logged, so we'll just put the error into 'process_name'.
104
+ if execution_error:
105
+ process_name = execution_error
106
+ print_api(
107
+ f"Error During Command Execution: {process_name}", error_type=True,
108
+ logger_method='error', **(print_kwargs or {}))
109
+ # If there wasn't any error of above types, then we can put the output from either local or remote script
110
+ # execution into 'process_name' and log it / output to console.
111
+ else:
112
+ # If the output that was returned is not empty.
113
+ if execution_output:
114
+ # Replacing '\r\n' escape lines with string, so that the line will not be escaped in logs.
115
+ if '\r\n' in execution_output:
116
+ execution_output = execution_output.replace('\r\n', '')
117
+ elif '\n' in execution_output:
118
+ execution_output = execution_output.replace('\n', '')
119
+
120
+ process_name = execution_output
121
+ print_api(f"Client Process Command Line: {process_name}", **(print_kwargs or {}))
122
+ # Else if the script output came back empty.
123
+ else:
124
+ process_name = "Client Process Command Line came back empty after script execution."
125
+ print_api(process_name, error_type=True, logger_method='error', **(print_kwargs or {}))
126
+
127
+ return process_name