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.

Files changed (66) hide show
  1. atomicshop/__init__.py +1 -1
  2. atomicshop/a_installs/ubuntu/pycharm.py +7 -0
  3. atomicshop/a_installs/win/pycharm.py +2 -2
  4. atomicshop/{addons/mains/install_wsl_ubuntu_lts_admin.py → a_installs/win/wsl_ubuntu_lts.py} +1 -0
  5. atomicshop/{addons/mains → a_mains}/FACT/update_extract.py +3 -2
  6. atomicshop/a_mains/dns_gateway_setting.py +11 -0
  7. atomicshop/basics/booleans.py +14 -5
  8. atomicshop/dns.py +104 -0
  9. atomicshop/file_io/docxs.py +8 -0
  10. atomicshop/file_io/tomls.py +133 -0
  11. atomicshop/filesystem.py +5 -4
  12. atomicshop/get_process_list.py +3 -3
  13. atomicshop/mitm/config_static.py +195 -0
  14. atomicshop/mitm/config_toml_editor.py +55 -0
  15. atomicshop/mitm/connection_thread_worker.py +54 -90
  16. atomicshop/mitm/import_config.py +148 -139
  17. atomicshop/mitm/initialize_engines.py +7 -2
  18. atomicshop/mitm/initialize_mitm_server.py +162 -107
  19. atomicshop/mitm/shared_functions.py +0 -1
  20. atomicshop/mitm/statistic_analyzer.py +13 -1
  21. atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +54 -14
  22. atomicshop/permissions/__init__.py +0 -0
  23. atomicshop/permissions/permissions.py +22 -0
  24. atomicshop/{permissions.py → permissions/ubuntu_permissions.py} +4 -54
  25. atomicshop/permissions/win_permissions.py +33 -0
  26. atomicshop/script_as_string_processor.py +5 -1
  27. atomicshop/wrappers/cryptographyw.py +3 -3
  28. atomicshop/wrappers/dockerw/install_docker.py +6 -5
  29. atomicshop/wrappers/elasticsearchw/install_elastic.py +2 -1
  30. atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py +5 -4
  31. atomicshop/wrappers/mongodbw/install_mongodb.py +2 -1
  32. atomicshop/wrappers/msiw.py +2 -3
  33. atomicshop/wrappers/psutilw/networks.py +25 -1
  34. atomicshop/wrappers/pycharmw/__init__.py +0 -0
  35. atomicshop/wrappers/pycharmw/ubuntu.py +38 -0
  36. atomicshop/wrappers/{pycharmw.py → pycharmw/win.py} +2 -2
  37. atomicshop/wrappers/pywin32w/wmis/__init__.py +0 -0
  38. atomicshop/wrappers/pywin32w/wmis/helpers.py +127 -0
  39. atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +167 -0
  40. atomicshop/wrappers/socketw/accepter.py +8 -8
  41. atomicshop/wrappers/socketw/base.py +13 -0
  42. atomicshop/wrappers/socketw/certificator.py +202 -149
  43. atomicshop/wrappers/socketw/creator.py +15 -35
  44. atomicshop/wrappers/socketw/dns_server.py +155 -102
  45. atomicshop/wrappers/socketw/exception_wrapper.py +8 -27
  46. atomicshop/wrappers/socketw/get_process.py +115 -95
  47. atomicshop/wrappers/socketw/sni.py +298 -164
  48. atomicshop/wrappers/socketw/socket_client.py +5 -12
  49. atomicshop/wrappers/socketw/socket_server_tester.py +1 -1
  50. atomicshop/wrappers/socketw/socket_wrapper.py +328 -72
  51. atomicshop/wrappers/socketw/statistics_csv.py +94 -16
  52. atomicshop/wrappers/ubuntu_terminal.py +6 -6
  53. atomicshop/wrappers/wslw.py +1 -0
  54. {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/METADATA +1 -1
  55. {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/RECORD +63 -54
  56. atomicshop/addons/mains/__pycache__/install_fibratus_windows.cpython-312.pyc +0 -0
  57. atomicshop/addons/mains/__pycache__/msi_unpacker.cpython-312.pyc +0 -0
  58. atomicshop/mitm/config_editor.py +0 -37
  59. /atomicshop/{addons/mains/install_docker_rootless_ubuntu.py → a_installs/ubuntu/docker_rootless.py} +0 -0
  60. /atomicshop/{addons/mains/install_docker_ubuntu_main_sudo.py → a_installs/ubuntu/docker_sudo.py} +0 -0
  61. /atomicshop/{addons/mains/install_elastic_search_and_kibana_ubuntu.py → a_installs/ubuntu/elastic_search_and_kibana.py} +0 -0
  62. /atomicshop/{addons/mains → a_mains}/FACT/factw_fact_extractor_docker_image_main_sudo.py +0 -0
  63. /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
  64. {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/LICENSE.txt +0 -0
  65. {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/WHEEL +0 -0
  66. {atomicshop-2.15.13.dist-info → atomicshop-2.16.1.dist-info}/top_level.txt +0 -0
@@ -24,13 +24,13 @@ def connection_exception_decorator(function_name):
24
24
  # After that second exception will be "pass"-ed. This is an exception inside an exception handling.
25
25
  # Looks like was introduced in Python 3 in PEP 3134.
26
26
  except ConnectionAbortedError:
27
- message = f"Socket Accept: {kwargs['dns_domain']}:{port}: " \
27
+ message = f"Socket Accept: {kwargs['domain_from_dns_server']}:{port}: " \
28
28
  f"* Established connection was aborted by software on the host..."
29
29
  wrapper_handle_connection_exceptions.message = message
30
- print_api(message, logger_method='error', traceback_string=True, oneline=True, **kwargs['print_kwargs'])
30
+ print_api(message, logger_method='error', traceback_string=True, **kwargs['print_kwargs'])
31
31
  pass
32
32
  except ConnectionResetError:
33
- message = f"Socket Accept: {kwargs['dns_domain']}:{port}: " \
33
+ message = f"Socket Accept: {kwargs['domain_from_dns_server']}:{port}: " \
34
34
  f"* An existing connection was forcibly closed by the remote host..."
35
35
  wrapper_handle_connection_exceptions.message = message
36
36
  print_api(message, logger_method='error', traceback_string=True, oneline=True, **kwargs['print_kwargs'])
@@ -45,7 +45,7 @@ def connection_exception_decorator(function_name):
45
45
  wrapper_handle_connection_exceptions.message = message
46
46
  try:
47
47
  message = \
48
- f"Socket Accept: {kwargs['dns_domain']}:{port}: {message}"
48
+ f"Socket Accept: {kwargs['domain_from_dns_server']}:{port}: {message}"
49
49
  wrapper_handle_connection_exceptions.message = message
50
50
  print_api(message, error_type=True, logger_method='error', **kwargs['print_kwargs'])
51
51
  except Exception:
@@ -59,7 +59,7 @@ def connection_exception_decorator(function_name):
59
59
  wrapper_handle_connection_exceptions.message = message
60
60
  try:
61
61
  message = \
62
- f"Socket Accept: {kwargs['dns_domain']}:{port}: {message}"
62
+ f"Socket Accept: {kwargs['domain_from_dns_server']}:{port}: {message}"
63
63
  wrapper_handle_connection_exceptions.message = message
64
64
  print_api(message, logger_method='error', **kwargs['print_kwargs'])
65
65
  except Exception:
@@ -80,14 +80,6 @@ def connection_exception_decorator(function_name):
80
80
  f"{base.get_source_destination(kwargs['socket_object'])}"
81
81
  wrapper_handle_connection_exceptions.message = message
82
82
  print_api(message, logger_method='error', traceback_string=True, oneline=True, **kwargs['print_kwargs'])
83
- # elif exception_object.reason == "SSLV3_ALERT_CERTIFICATE_UNKNOWN":
84
- # message = f"ssl.SSLError:{exception_object}"
85
- # message = f"Socket Accept: {domain_name}:{socket_object.getsockname()[1]}: {message}"
86
- # print_api(message, logger=self.logger, logger_method='error', traceback_string=True, oneline=True)
87
- # elif exception_object.reason == "NO_SHARED_CIPHER":
88
- # message = f"ssl.SSLError:{exception_object}"
89
- # message = f"Socket Accept: {domain_name}:{socket_object.getsockname()[1]}: {message}"
90
- # print_api(message, logger=self.logger, logger_method='error', traceback_string=True, oneline=True)
91
83
  else:
92
84
  # Not all requests have the server name passed through Client Hello.
93
85
  # If it is not passed an error of undefined variable will be raised.
@@ -97,35 +89,24 @@ def connection_exception_decorator(function_name):
97
89
  message = "SSLError on accept. Not documented..."
98
90
  wrapper_handle_connection_exceptions.message = message
99
91
  print_api(message, logger_method='error', **kwargs['print_kwargs'])
100
- # try:
101
- # message = f"Socket Accept: {domain_name}:{socket_object.getsockname()[1]}: {message}"
102
- # print_api(message, logger=self.logger, logger_method='error', traceback_string=True, oneline=True)
103
- # except Exception:
104
- # message = f"Socket Accept: port {socket_object.getsockname()[1]}: {message}"
105
- # print_api(message, logger=self.logger, logger_method='error', traceback_string=True, oneline=True)
106
- # pass
107
92
 
108
93
  message = f'ssl.SSLError:{exception_object}'
109
94
  wrapper_handle_connection_exceptions.message = message
110
95
  message = \
111
- f"Socket Accept: {kwargs['dns_domain']}:{port}: {message}"
96
+ f"Socket Accept: {kwargs['domain_from_dns_server']}:{port}: {message}"
112
97
  wrapper_handle_connection_exceptions.message = message
113
98
  print_api(message, logger_method='error', **kwargs['print_kwargs'])
114
99
  pass
115
100
  except FileNotFoundError:
116
101
  message = "'SSLSocket.accept()' crashed: 'FileNotFoundError'. Some problem with SSL during Handshake - " \
117
102
  "Could be certificate, client, or server."
118
- message = f"Socket Accept: {kwargs['dns_domain']}:{port}: {message}"
103
+ message = f"Socket Accept: {kwargs['domain_from_dns_server']}:{port}: {message}"
119
104
  wrapper_handle_connection_exceptions.message = message
120
105
  print_api(message, logger_method='error', traceback_string=True, oneline=True, **kwargs['print_kwargs'])
121
- # except Exception:
122
- # message = f"Socket Accept: port {socket_object.getsockname()[1]}: {message}"
123
- # print_api(message, logger=self.logger, logger_method='error', traceback_string=True, oneline=True)
124
- # pass
125
106
  pass
126
107
  except Exception:
127
108
  message = "Undocumented exception on accept."
128
- message = f"Socket Accept: {kwargs['dns_domain']}:{port}: {message}"
109
+ message = f"Socket Accept: {kwargs['domain_from_dns_server']}:{port}: {message}"
129
110
  wrapper_handle_connection_exceptions.message = message
130
111
  print_api(message, logger_method='error', traceback_string=True, oneline=True, **kwargs['print_kwargs'])
131
112
  pass
@@ -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