atomicshop 2.11.47__py3-none-any.whl → 3.10.5__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.
Files changed (268) hide show
  1. atomicshop/__init__.py +1 -1
  2. atomicshop/{addons/mains → a_mains}/FACT/update_extract.py +3 -2
  3. atomicshop/a_mains/addons/process_list/compile.cmd +7 -0
  4. atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.dll +0 -0
  5. atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.exp +0 -0
  6. atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.lib +0 -0
  7. atomicshop/{addons → a_mains/addons}/process_list/process_list.cpp +8 -1
  8. atomicshop/a_mains/dns_gateway_setting.py +11 -0
  9. atomicshop/a_mains/get_local_tcp_ports.py +85 -0
  10. atomicshop/a_mains/github_wrapper.py +11 -0
  11. atomicshop/a_mains/install_ca_certificate.py +172 -0
  12. atomicshop/{addons/mains → a_mains}/msi_unpacker.py +3 -1
  13. atomicshop/a_mains/process_from_port.py +119 -0
  14. atomicshop/a_mains/set_default_dns_gateway.py +90 -0
  15. atomicshop/a_mains/update_config_toml.py +38 -0
  16. atomicshop/appointment_management.py +5 -3
  17. atomicshop/basics/ansi_escape_codes.py +3 -1
  18. atomicshop/basics/argparse_template.py +2 -0
  19. atomicshop/basics/booleans.py +27 -30
  20. atomicshop/basics/bytes_arrays.py +43 -0
  21. atomicshop/basics/classes.py +149 -1
  22. atomicshop/basics/dicts.py +12 -0
  23. atomicshop/basics/enums.py +2 -2
  24. atomicshop/basics/exceptions.py +5 -1
  25. atomicshop/basics/list_of_classes.py +29 -0
  26. atomicshop/basics/list_of_dicts.py +69 -5
  27. atomicshop/basics/lists.py +14 -0
  28. atomicshop/basics/multiprocesses.py +374 -50
  29. atomicshop/basics/package_module.py +10 -0
  30. atomicshop/basics/strings.py +160 -7
  31. atomicshop/basics/threads.py +14 -0
  32. atomicshop/basics/tracebacks.py +13 -4
  33. atomicshop/certificates.py +153 -52
  34. atomicshop/config_init.py +12 -7
  35. atomicshop/console_user_response.py +7 -14
  36. atomicshop/consoles.py +9 -0
  37. atomicshop/datetimes.py +98 -0
  38. atomicshop/diff_check.py +340 -40
  39. atomicshop/dns.py +128 -12
  40. atomicshop/etws/_pywintrace_fix.py +17 -0
  41. atomicshop/etws/const.py +38 -0
  42. atomicshop/etws/providers.py +21 -0
  43. atomicshop/etws/sessions.py +43 -0
  44. atomicshop/etws/trace.py +168 -0
  45. atomicshop/etws/traces/trace_dns.py +162 -0
  46. atomicshop/etws/traces/trace_sysmon_process_creation.py +126 -0
  47. atomicshop/etws/traces/trace_tcp.py +130 -0
  48. atomicshop/file_io/csvs.py +222 -24
  49. atomicshop/file_io/docxs.py +35 -18
  50. atomicshop/file_io/file_io.py +35 -19
  51. atomicshop/file_io/jsons.py +49 -0
  52. atomicshop/file_io/tomls.py +139 -0
  53. atomicshop/filesystem.py +864 -293
  54. atomicshop/get_process_list.py +133 -0
  55. atomicshop/{process_name_cmd.py → get_process_name_cmd_dll.py} +52 -19
  56. atomicshop/http_parse.py +149 -93
  57. atomicshop/ip_addresses.py +6 -1
  58. atomicshop/mitm/centered_settings.py +132 -0
  59. atomicshop/mitm/config_static.py +207 -0
  60. atomicshop/mitm/config_toml_editor.py +55 -0
  61. atomicshop/mitm/connection_thread_worker.py +875 -357
  62. atomicshop/mitm/engines/__parent/parser___parent.py +4 -17
  63. atomicshop/mitm/engines/__parent/recorder___parent.py +108 -51
  64. atomicshop/mitm/engines/__parent/requester___parent.py +116 -0
  65. atomicshop/mitm/engines/__parent/responder___parent.py +75 -114
  66. atomicshop/mitm/engines/__reference_general/parser___reference_general.py +10 -7
  67. atomicshop/mitm/engines/__reference_general/recorder___reference_general.py +5 -5
  68. atomicshop/mitm/engines/__reference_general/requester___reference_general.py +47 -0
  69. atomicshop/mitm/engines/__reference_general/responder___reference_general.py +95 -13
  70. atomicshop/mitm/engines/create_module_template.py +58 -14
  71. atomicshop/mitm/import_config.py +359 -139
  72. atomicshop/mitm/initialize_engines.py +160 -74
  73. atomicshop/mitm/message.py +64 -23
  74. atomicshop/mitm/mitm_main.py +892 -0
  75. atomicshop/mitm/recs_files.py +183 -0
  76. atomicshop/mitm/shared_functions.py +4 -10
  77. atomicshop/mitm/ssh_tester.py +82 -0
  78. atomicshop/mitm/statistic_analyzer.py +257 -166
  79. atomicshop/mitm/statistic_analyzer_helper/analyzer_helper.py +136 -0
  80. atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +525 -0
  81. atomicshop/monitor/change_monitor.py +96 -120
  82. atomicshop/monitor/checks/dns.py +139 -70
  83. atomicshop/monitor/checks/file.py +77 -0
  84. atomicshop/monitor/checks/network.py +81 -77
  85. atomicshop/monitor/checks/process_running.py +33 -34
  86. atomicshop/monitor/checks/url.py +94 -0
  87. atomicshop/networks.py +671 -0
  88. atomicshop/on_exit.py +205 -0
  89. atomicshop/package_mains_processor.py +84 -0
  90. atomicshop/permissions/permissions.py +22 -0
  91. atomicshop/permissions/ubuntu_permissions.py +239 -0
  92. atomicshop/permissions/win_permissions.py +33 -0
  93. atomicshop/print_api.py +24 -41
  94. atomicshop/process.py +63 -17
  95. atomicshop/process_poller/__init__.py +0 -0
  96. atomicshop/process_poller/pollers/__init__.py +0 -0
  97. atomicshop/process_poller/pollers/psutil_pywin32wmi_dll.py +95 -0
  98. atomicshop/process_poller/process_pool.py +207 -0
  99. atomicshop/process_poller/simple_process_pool.py +311 -0
  100. atomicshop/process_poller/tracer_base.py +45 -0
  101. atomicshop/process_poller/tracers/__init__.py +0 -0
  102. atomicshop/process_poller/tracers/event_log.py +46 -0
  103. atomicshop/process_poller/tracers/sysmon_etw.py +68 -0
  104. atomicshop/python_file_patcher.py +1 -1
  105. atomicshop/python_functions.py +27 -75
  106. atomicshop/question_answer_engine.py +2 -2
  107. atomicshop/scheduling.py +24 -5
  108. atomicshop/sound.py +4 -2
  109. atomicshop/speech_recognize.py +8 -0
  110. atomicshop/ssh_remote.py +158 -172
  111. atomicshop/startup/__init__.py +0 -0
  112. atomicshop/startup/win/__init__.py +0 -0
  113. atomicshop/startup/win/startup_folder.py +53 -0
  114. atomicshop/startup/win/task_scheduler.py +119 -0
  115. atomicshop/system_resource_monitor.py +61 -46
  116. atomicshop/system_resources.py +8 -8
  117. atomicshop/tempfiles.py +1 -2
  118. atomicshop/timer.py +30 -11
  119. atomicshop/urls.py +41 -0
  120. atomicshop/venvs.py +28 -0
  121. atomicshop/versioning.py +27 -0
  122. atomicshop/web.py +110 -25
  123. atomicshop/web_apis/__init__.py +0 -0
  124. atomicshop/web_apis/google_custom_search.py +44 -0
  125. atomicshop/web_apis/google_llm.py +188 -0
  126. atomicshop/websocket_parse.py +450 -0
  127. atomicshop/wrappers/certauthw/certauth.py +1 -0
  128. atomicshop/wrappers/cryptographyw.py +29 -8
  129. atomicshop/wrappers/ctyping/etw_winapi/__init__.py +0 -0
  130. atomicshop/wrappers/ctyping/etw_winapi/const.py +335 -0
  131. atomicshop/wrappers/ctyping/etw_winapi/etw_functions.py +393 -0
  132. atomicshop/wrappers/ctyping/file_details_winapi.py +67 -0
  133. atomicshop/wrappers/ctyping/msi_windows_installer/cabs.py +2 -1
  134. atomicshop/wrappers/ctyping/msi_windows_installer/extract_msi_main.py +13 -9
  135. atomicshop/wrappers/ctyping/msi_windows_installer/tables.py +35 -0
  136. atomicshop/wrappers/ctyping/setup_device.py +466 -0
  137. atomicshop/wrappers/ctyping/win_console.py +39 -0
  138. atomicshop/wrappers/dockerw/dockerw.py +113 -2
  139. atomicshop/wrappers/elasticsearchw/config_basic.py +0 -12
  140. atomicshop/wrappers/elasticsearchw/elastic_infra.py +75 -0
  141. atomicshop/wrappers/elasticsearchw/elasticsearchw.py +2 -20
  142. atomicshop/wrappers/factw/get_file_data.py +12 -5
  143. atomicshop/wrappers/factw/install/install_after_restart.py +89 -5
  144. atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py +20 -14
  145. atomicshop/wrappers/factw/postgresql/firmware.py +4 -6
  146. atomicshop/wrappers/githubw.py +583 -51
  147. atomicshop/wrappers/loggingw/consts.py +49 -0
  148. atomicshop/wrappers/loggingw/filters.py +102 -0
  149. atomicshop/wrappers/loggingw/formatters.py +58 -71
  150. atomicshop/wrappers/loggingw/handlers.py +459 -40
  151. atomicshop/wrappers/loggingw/loggers.py +19 -0
  152. atomicshop/wrappers/loggingw/loggingw.py +1010 -178
  153. atomicshop/wrappers/loggingw/reading.py +344 -19
  154. atomicshop/wrappers/mongodbw/__init__.py +0 -0
  155. atomicshop/wrappers/mongodbw/mongo_infra.py +31 -0
  156. atomicshop/wrappers/mongodbw/mongodbw.py +1432 -0
  157. atomicshop/wrappers/netshw.py +271 -0
  158. atomicshop/wrappers/playwrightw/engine.py +34 -19
  159. atomicshop/wrappers/playwrightw/infra.py +5 -0
  160. atomicshop/wrappers/playwrightw/javascript.py +7 -3
  161. atomicshop/wrappers/playwrightw/keyboard.py +14 -0
  162. atomicshop/wrappers/playwrightw/scenarios.py +172 -5
  163. atomicshop/wrappers/playwrightw/waits.py +9 -7
  164. atomicshop/wrappers/powershell_networking.py +80 -0
  165. atomicshop/wrappers/psutilw/processes.py +81 -0
  166. atomicshop/wrappers/psutilw/psutil_networks.py +85 -0
  167. atomicshop/wrappers/psutilw/psutilw.py +9 -0
  168. atomicshop/wrappers/pyopensslw.py +9 -2
  169. atomicshop/wrappers/pywin32w/__init__.py +0 -0
  170. atomicshop/wrappers/pywin32w/cert_store.py +116 -0
  171. atomicshop/wrappers/pywin32w/console.py +34 -0
  172. atomicshop/wrappers/pywin32w/win_event_log/__init__.py +0 -0
  173. atomicshop/wrappers/pywin32w/win_event_log/fetch.py +174 -0
  174. atomicshop/wrappers/pywin32w/win_event_log/subscribe.py +212 -0
  175. atomicshop/wrappers/pywin32w/win_event_log/subscribes/__init__.py +0 -0
  176. atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_create.py +57 -0
  177. atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_terminate.py +49 -0
  178. atomicshop/wrappers/pywin32w/win_event_log/subscribes/schannel_logging.py +97 -0
  179. atomicshop/wrappers/pywin32w/winshell.py +19 -0
  180. atomicshop/wrappers/pywin32w/wmis/__init__.py +0 -0
  181. atomicshop/wrappers/pywin32w/wmis/msft_netipaddress.py +113 -0
  182. atomicshop/wrappers/pywin32w/wmis/win32_networkadapterconfiguration.py +259 -0
  183. atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +112 -0
  184. atomicshop/wrappers/pywin32w/wmis/wmi_helpers.py +236 -0
  185. atomicshop/wrappers/socketw/accepter.py +21 -7
  186. atomicshop/wrappers/socketw/certificator.py +216 -150
  187. atomicshop/wrappers/socketw/creator.py +190 -50
  188. atomicshop/wrappers/socketw/dns_server.py +500 -173
  189. atomicshop/wrappers/socketw/exception_wrapper.py +45 -52
  190. atomicshop/wrappers/socketw/process_getter.py +86 -0
  191. atomicshop/wrappers/socketw/receiver.py +144 -102
  192. atomicshop/wrappers/socketw/sender.py +65 -35
  193. atomicshop/wrappers/socketw/sni.py +334 -165
  194. atomicshop/wrappers/socketw/socket_base.py +134 -0
  195. atomicshop/wrappers/socketw/socket_client.py +137 -95
  196. atomicshop/wrappers/socketw/socket_server_tester.py +14 -9
  197. atomicshop/wrappers/socketw/socket_wrapper.py +717 -116
  198. atomicshop/wrappers/socketw/ssl_base.py +15 -14
  199. atomicshop/wrappers/socketw/statistics_csv.py +148 -17
  200. atomicshop/wrappers/sysmonw.py +157 -0
  201. atomicshop/wrappers/ubuntu_terminal.py +65 -26
  202. atomicshop/wrappers/win_auditw.py +189 -0
  203. atomicshop/wrappers/winregw/__init__.py +0 -0
  204. atomicshop/wrappers/winregw/winreg_installed_software.py +58 -0
  205. atomicshop/wrappers/winregw/winreg_network.py +232 -0
  206. {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info}/METADATA +31 -49
  207. atomicshop-3.10.5.dist-info/RECORD +306 -0
  208. {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info}/WHEEL +1 -1
  209. atomicshop/_basics_temp.py +0 -101
  210. atomicshop/addons/a_setup_scripts/install_psycopg2_ubuntu.sh +0 -3
  211. atomicshop/addons/a_setup_scripts/install_pywintrace_0.3.cmd +0 -2
  212. atomicshop/addons/mains/install_docker_rootless_ubuntu.py +0 -11
  213. atomicshop/addons/mains/install_docker_ubuntu_main_sudo.py +0 -11
  214. atomicshop/addons/mains/install_elastic_search_and_kibana_ubuntu.py +0 -10
  215. atomicshop/addons/mains/install_wsl_ubuntu_lts_admin.py +0 -9
  216. atomicshop/addons/package_setup/CreateWheel.cmd +0 -7
  217. atomicshop/addons/package_setup/Setup in Edit mode.cmd +0 -6
  218. atomicshop/addons/package_setup/Setup.cmd +0 -7
  219. atomicshop/addons/process_list/compile.cmd +0 -2
  220. atomicshop/addons/process_list/compiled/Win10x64/process_list.dll +0 -0
  221. atomicshop/addons/process_list/compiled/Win10x64/process_list.exp +0 -0
  222. atomicshop/addons/process_list/compiled/Win10x64/process_list.lib +0 -0
  223. atomicshop/archiver/_search_in_zip.py +0 -189
  224. atomicshop/archiver/archiver.py +0 -34
  225. atomicshop/archiver/search_in_archive.py +0 -250
  226. atomicshop/archiver/sevenz_app_w.py +0 -86
  227. atomicshop/archiver/sevenzs.py +0 -44
  228. atomicshop/archiver/zips.py +0 -293
  229. atomicshop/etw/dns_trace.py +0 -118
  230. atomicshop/etw/etw.py +0 -61
  231. atomicshop/file_types.py +0 -24
  232. atomicshop/mitm/engines/create_module_template_example.py +0 -13
  233. atomicshop/mitm/initialize_mitm_server.py +0 -240
  234. atomicshop/monitor/checks/hash.py +0 -44
  235. atomicshop/monitor/checks/hash_checks/file.py +0 -55
  236. atomicshop/monitor/checks/hash_checks/url.py +0 -62
  237. atomicshop/pbtkmultifile_argparse.py +0 -88
  238. atomicshop/permissions.py +0 -110
  239. atomicshop/process_poller.py +0 -237
  240. atomicshop/script_as_string_processor.py +0 -38
  241. atomicshop/ssh_scripts/process_from_ipv4.py +0 -37
  242. atomicshop/ssh_scripts/process_from_port.py +0 -27
  243. atomicshop/wrappers/_process_wrapper_curl.py +0 -27
  244. atomicshop/wrappers/_process_wrapper_tar.py +0 -21
  245. atomicshop/wrappers/dockerw/install_docker.py +0 -209
  246. atomicshop/wrappers/elasticsearchw/infrastructure.py +0 -265
  247. atomicshop/wrappers/elasticsearchw/install_elastic.py +0 -232
  248. atomicshop/wrappers/ffmpegw.py +0 -125
  249. atomicshop/wrappers/loggingw/checks.py +0 -20
  250. atomicshop/wrappers/nodejsw/install_nodejs.py +0 -139
  251. atomicshop/wrappers/process_wrapper_pbtk.py +0 -16
  252. atomicshop/wrappers/socketw/base.py +0 -59
  253. atomicshop/wrappers/socketw/get_process.py +0 -107
  254. atomicshop/wrappers/wslw.py +0 -191
  255. atomicshop-2.11.47.dist-info/RECORD +0 -251
  256. /atomicshop/{addons/mains → a_mains}/FACT/factw_fact_extractor_docker_image_main_sudo.py +0 -0
  257. /atomicshop/{addons → a_mains/addons}/PlayWrightCodegen.cmd +0 -0
  258. /atomicshop/{addons → a_mains/addons}/ScriptExecution.cmd +0 -0
  259. /atomicshop/{addons/mains → a_mains/addons}/inits/init_to_import_all_modules.py +0 -0
  260. /atomicshop/{addons → a_mains/addons}/process_list/ReadMe.txt +0 -0
  261. /atomicshop/{addons/mains → a_mains}/search_for_hyperlinks_in_docx.py +0 -0
  262. /atomicshop/{archiver → etws}/__init__.py +0 -0
  263. /atomicshop/{etw → etws/traces}/__init__.py +0 -0
  264. /atomicshop/{monitor/checks/hash_checks → mitm/statistic_analyzer_helper}/__init__.py +0 -0
  265. /atomicshop/{wrappers/nodejsw → permissions}/__init__.py +0 -0
  266. /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
  267. {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info/licenses}/LICENSE.txt +0 -0
  268. {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info}/top_level.txt +0 -0
@@ -1,87 +1,91 @@
1
+ from pathlib import Path
2
+ from typing import Union
3
+
1
4
  from ...wrappers.psutilw import psutilw
2
5
  from ...basics import list_of_dicts
3
6
  from ...print_api import print_api
7
+ from ... import diff_check
4
8
 
5
9
 
6
- def _execute_cycle(change_monitor_instance, print_kwargs: dict = None):
7
- """
8
- This function executes the cycle of the change monitor: network.
9
-
10
- :param change_monitor_instance: Instance of the ChangeMonitor class.
11
-
12
- :return: List of dictionaries with the results of the cycle.
13
- """
14
-
15
- if print_kwargs is None:
16
- print_kwargs = dict()
17
-
18
- return_list = list()
19
-
20
- _get_list(change_monitor_instance)
21
-
22
- change_monitor_instance._set_input_file_path()
23
-
24
- # Check if 'known_domains' list was updated from previous cycle.
25
- result, message = change_monitor_instance.diff_check_list[0].check_list_of_dicts(print_kwargs=print_kwargs)
26
-
27
- if result:
28
- # Get list of new connections only.
29
- new_connections_only: list = list_of_dicts.get_difference(result['old'], result['updated'])
30
-
31
- for connection in new_connections_only:
32
- message = \
33
- f"New connection: {connection['name']} | " \
34
- f"{connection['dst_ip']}:{connection['dst_port']} | " \
35
- f"{connection['family']} | {connection['type']} | {connection['cmdline']}"
36
- # f"{connection['src_ip']}:{connection['src_port']} -> " \
37
- print_api(message, color='yellow', **print_kwargs)
10
+ INPUT_FILE_DEFAULT_NAME: str = 'known_connections.txt'
38
11
 
39
- return_list.append(message)
40
12
 
41
- return return_list
42
-
43
-
44
- def _get_list(change_monitor_instance):
13
+ class NetworkCheck:
45
14
  """
46
- The function will get the list of opened network sockets and return only the new ones.
47
-
48
- :param change_monitor_instance: Instance of the ChangeMonitor class.
49
-
50
- :return: list of dicts, of new network sockets.
15
+ Class for network monitoring.
51
16
  """
52
17
 
53
- if change_monitor_instance.first_cycle:
54
- original_name: str = str()
55
-
56
- # Initialize objects for network monitoring.
57
- change_monitor_instance.fetch_engine = psutilw.PsutilConnections()
58
-
59
- # Change settings for the DiffChecker object.
60
- change_monitor_instance.diff_check_list[0].return_first_cycle = True
61
-
62
- if change_monitor_instance.generate_input_file_name:
63
- original_name = 'known_connections'
64
- # Make path for 'input_file_name'.
65
- change_monitor_instance.input_file_name = f'{original_name}.txt'
66
-
67
- change_monitor_instance.diff_check_list[0].check_object_display_name = \
68
- f'{original_name}|{change_monitor_instance.object_type}'
69
-
70
- # Set the 'check_object' to empty list, since we will append the list of DNS events.
71
- change_monitor_instance.diff_check_list[0].check_object = list()
72
-
73
- # Get all connections (list of dicts), including process name and cmdline.
74
- connections_list_of_dicts: list = \
75
- change_monitor_instance.fetch_engine.get_connections_with_process_as_list_of_dicts(
76
- attrs=['name', 'cmdline', 'family', 'type', 'dst_ip', 'dst_port'], skip_empty_dst=True,
77
- cmdline_to_string=True, remove_duplicates=True)
78
-
79
- # Get list of connections that are not in 'known_connections' list.
80
- missing_connections_from_cycle: list = list_of_dicts.get_difference(
81
- change_monitor_instance.diff_check_list[0].check_object, connections_list_of_dicts)
82
- # Add missing new connections to 'known_connections' list.
83
- change_monitor_instance.diff_check_list[0].check_object.extend(missing_connections_from_cycle)
84
-
85
- # Sort list of dicts by process name and then by process cmdline.
86
- change_monitor_instance.diff_check_list[0].check_object = list_of_dicts.sort_by_keys(
87
- change_monitor_instance.diff_check_list[0].check_object, key_list=['cmdline', 'name'], case_insensitive=True)
18
+ def __init__(self, change_monitor_instance):
19
+ self.change_monitor_instance = change_monitor_instance
20
+ self.diff_checker: Union[diff_check.DiffChecker, None] = None
21
+ self.fetch_engine = psutilw.PsutilConnections()
22
+
23
+ if not change_monitor_instance.input_file_name:
24
+ change_monitor_instance.input_file_name = INPUT_FILE_DEFAULT_NAME
25
+ input_file_path = (
26
+ str(Path(change_monitor_instance.input_directory, change_monitor_instance.input_file_name)))
27
+
28
+ diff_checker_display_name = \
29
+ f'{change_monitor_instance.input_file_name}|{change_monitor_instance.object_type}'
30
+ self.diff_checker = diff_check.DiffChecker(
31
+ check_object=list(), # we will append the list of connection events.
32
+ return_first_cycle=True,
33
+ operation_type='single_object',
34
+ check_object_display_name=diff_checker_display_name,
35
+ input_file_path=input_file_path
36
+ )
37
+ self.diff_checker.initiate_before_action()
38
+
39
+ def execute_cycle(self, print_kwargs: dict = None):
40
+ """
41
+ This function executes the cycle of the change monitor: network.
42
+
43
+ :param print_kwargs: print_api kwargs.
44
+ :return: List of dictionaries with the results of the cycle.
45
+ """
46
+
47
+ return_list = list()
48
+
49
+ self._get_list()
50
+
51
+ # Check if 'known_domains' list was updated from previous cycle.
52
+ result, message = self.diff_checker.check_list_of_dicts(print_kwargs=print_kwargs)
53
+
54
+ if result:
55
+ # Get list of new connections only.
56
+ new_connections_only: list = list_of_dicts.get_difference(result['old'], result['updated'])
57
+
58
+ for connection in new_connections_only:
59
+ message = \
60
+ f"New connection: {connection['name']} | " \
61
+ f"{connection['dst_ip']}:{connection['dst_port']} | " \
62
+ f"{connection['family']} | {connection['type']} | {connection['cmdline']}"
63
+ # f"{connection['src_ip']}:{connection['src_port']} -> " \
64
+ print_api(message, color='yellow', **(print_kwargs or {}))
65
+
66
+ return_list.append(message)
67
+
68
+ return return_list
69
+
70
+ def _get_list(self):
71
+ """
72
+ The function will get the list of opened network sockets and return only the new ones.
73
+
74
+ :return: list of dicts, of new network sockets.
75
+ """
76
+
77
+ # Get all connections (list of dicts), including process name and cmdline.
78
+ connections_list_of_dicts: list = \
79
+ self.fetch_engine.get_connections_with_process_as_list_of_dicts(
80
+ attrs=['name', 'cmdline', 'family', 'type', 'dst_ip', 'dst_port'], skip_empty_dst=True,
81
+ cmdline_to_string=True, remove_duplicates=True)
82
+
83
+ # Get list of connections that are not in 'known_connections' list.
84
+ missing_connections_from_cycle: list = list_of_dicts.get_difference(
85
+ self.diff_checker.check_object, connections_list_of_dicts)
86
+ # Add missing new connections to 'known_connections' list.
87
+ self.diff_checker.check_object.extend(missing_connections_from_cycle)
88
+
89
+ # Sort list of dicts by process name and then by process cmdline.
90
+ self.diff_checker.check_object = list_of_dicts.sort_by_keys(
91
+ self.diff_checker.check_object, key_list=['cmdline', 'name'], case_insensitive=True)
@@ -3,51 +3,50 @@ from ...basics import list_of_dicts
3
3
  from ...print_api import print_api
4
4
 
5
5
 
6
- def _execute_cycle(change_monitor_instance, print_kwargs: dict = None):
6
+ class ProcessRunningCheck:
7
7
  """
8
- This function executes the cycle of the change monitor: process_running.
9
-
10
- :param change_monitor_instance: Instance of the ChangeMonitor class.
11
-
12
- :return: List of dictionaries with the results of the cycle.
8
+ Class for process running monitoring.
13
9
  """
14
10
 
15
- if print_kwargs is None:
16
- print_kwargs = dict()
11
+ def __init__(self, change_monitor_instance):
12
+ self.change_monitor_instance = change_monitor_instance
13
+ self.fetch_engine = psutilw.PsutilProcesses()
17
14
 
18
- return_list = list()
15
+ def execute_cycle(self, print_kwargs: dict = None):
16
+ """
17
+ This function executes the cycle of the change monitor: process_running.
19
18
 
20
- processes = _get_list(change_monitor_instance)
19
+ :param print_kwargs: Dictionary with the print arguments.
20
+ :return: List of dictionaries with the results of the cycle.
21
+ """
21
22
 
22
- for process_name in change_monitor_instance.check_object_list:
23
- result = list_of_dicts.is_value_exist_in_key(processes, 'cmdline', process_name)
23
+ return_list = list()
24
24
 
25
- # If the process name was found in the list of currently running processes.
26
- if result:
27
- message = f"Process [{process_name}] is Running."
28
- print_api(message, color='green', **print_kwargs)
29
- # If the process name was not found in the list of currently running processes.
30
- else:
31
- message = f"Process [{process_name}] not Running!"
32
- print_api(message, color='red', **print_kwargs)
25
+ processes = self._get_list()
33
26
 
34
- return_list.append(message)
27
+ for process_name in self.change_monitor_instance.check_object:
28
+ result = list_of_dicts.is_value_exist_in_key(
29
+ processes, 'cmdline', process_name, value_case_insensitive=True)
35
30
 
36
- return return_list
31
+ # If the process name was found in the list of currently running processes.
32
+ if result:
33
+ message = f"Process [{process_name}] is Running."
34
+ print_api(message, color='green', **(print_kwargs or {}))
35
+ # If the process name was not found in the list of currently running processes.
36
+ else:
37
+ message = f"Process [{process_name}] not Running!"
38
+ print_api(message, color='red', **(print_kwargs or {}))
37
39
 
40
+ return_list.append(message)
38
41
 
39
- def _get_list(change_monitor_instance):
40
- """
41
- The function will get the list of opened network sockets and return only the new ones.
42
+ return return_list
42
43
 
43
- :param change_monitor_instance: Instance of the ChangeMonitor class.
44
-
45
- :return: list of dicts, of new network sockets.
46
- """
44
+ def _get_list(self):
45
+ """
46
+ The function will get the list of opened network sockets and return only the new ones.
47
47
 
48
- if change_monitor_instance.first_cycle:
49
- # Initialize objects for network monitoring.
50
- change_monitor_instance.fetch_engine = psutilw.PsutilProcesses()
48
+ :return: list of dicts, of new network sockets.
49
+ """
51
50
 
52
- return change_monitor_instance.fetch_engine.get_processes_as_list_of_dicts(
53
- default_keys=True, cmdline_to_string=True)
51
+ return self.fetch_engine.get_processes_as_list_of_dicts(
52
+ default_keys=True, cmdline_to_string=True)
@@ -0,0 +1,94 @@
1
+ from pathlib import Path
2
+
3
+ from ... import hashing, urls
4
+ from ... import diff_check
5
+ from ...print_api import print_api
6
+
7
+
8
+ class UrlCheck:
9
+ """
10
+ Class for file monitoring.
11
+ """
12
+ def __init__(self, change_monitor_instance):
13
+ self.diff_checker = None
14
+ self.change_monitor_instance = None
15
+ self.store_original_file_path = None
16
+ self.get_method = None
17
+
18
+ # Extract the method name from the object type.
19
+ self.get_method = change_monitor_instance.object_type.split('_', 1)[1]
20
+
21
+ if not change_monitor_instance.input_file_name:
22
+ change_monitor_instance.input_file_name = (
23
+ urls.url_parser(change_monitor_instance.check_object))['directories'][-1]
24
+ change_monitor_instance.input_file_name = change_monitor_instance.input_file_name.lower()
25
+ change_monitor_instance.input_file_name = f'{change_monitor_instance.input_file_name}.txt'
26
+
27
+ input_file_path = (
28
+ str(Path(change_monitor_instance.input_directory, change_monitor_instance.input_file_name)))
29
+
30
+ # If 'store_original_object' is True, create filename for the store original object.
31
+ if change_monitor_instance.object_type_settings['store_original_object']:
32
+ # Add extension to the file name.
33
+ extension: str = str()
34
+ if 'playwright' in self.get_method:
35
+ extension = self.get_method.split('_')[1]
36
+ elif self.get_method == 'urllib':
37
+ extension = 'html'
38
+
39
+ store_original_file_name: str = Path(change_monitor_instance.input_file_name).stem
40
+ store_original_file_name = f'{store_original_file_name}.{extension}'
41
+ self.store_original_file_path = str(Path(change_monitor_instance.input_directory, store_original_file_name))
42
+
43
+ self.diff_checker = diff_check.DiffChecker(
44
+ return_first_cycle=False,
45
+ operation_type='single_object',
46
+ input_file_path=input_file_path,
47
+ check_object_display_name=f'{change_monitor_instance.input_file_name}|{change_monitor_instance.object_type}'
48
+ )
49
+ self.diff_checker.initiate_before_action()
50
+ self.change_monitor_instance = change_monitor_instance
51
+
52
+ def execute_cycle(self, print_kwargs: dict = None):
53
+ """
54
+ This function executes the cycle of the change monitor: hash.
55
+
56
+ :param print_kwargs: print_api kwargs.
57
+ :return: List of dictionaries with the results of the cycle.
58
+ """
59
+
60
+ return_list = list()
61
+
62
+ self._get_hash(print_kwargs=print_kwargs)
63
+
64
+ # Check if the object was updated.
65
+ result, message = self.diff_checker.check_string(
66
+ print_kwargs=print_kwargs)
67
+
68
+ # If the object was updated, print the message in yellow color, otherwise print in green color.
69
+ if result:
70
+ print_api(message, color='yellow', **print_kwargs)
71
+ # create_message_file(message, self.__class__.__name__, logger=self.logger)
72
+
73
+ return_list.append(message)
74
+ else:
75
+ print_api(message, color='green', **print_kwargs)
76
+
77
+ return return_list
78
+
79
+ def _get_hash(self, print_kwargs: dict = None):
80
+ """
81
+ The function will get the hash of the URL content.
82
+
83
+ :param print_kwargs: print_api kwargs.
84
+ """
85
+ # Get hash of the url. The hash will be different between direct hash of the URL content and the
86
+ # hash of the file that was downloaded from the URL. Since the file has headers and other information
87
+ # that is not part of the URL content. The Original downloaded file is for reference only to see
88
+ # what was the content of the URL at the time of the download.
89
+ hash_string = hashing.hash_url(
90
+ self.change_monitor_instance.check_object, get_method=self.get_method,
91
+ path=self.store_original_file_path, print_kwargs=print_kwargs)
92
+
93
+ # Set the hash string to the 'check_object' variable.
94
+ self.diff_checker.check_object = hash_string