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.
- atomicshop/__init__.py +1 -1
- atomicshop/{addons/mains → a_mains}/FACT/update_extract.py +3 -2
- atomicshop/a_mains/addons/process_list/compile.cmd +7 -0
- atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.dll +0 -0
- atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.exp +0 -0
- atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.lib +0 -0
- atomicshop/{addons → a_mains/addons}/process_list/process_list.cpp +8 -1
- atomicshop/a_mains/dns_gateway_setting.py +11 -0
- atomicshop/a_mains/get_local_tcp_ports.py +85 -0
- atomicshop/a_mains/github_wrapper.py +11 -0
- atomicshop/a_mains/install_ca_certificate.py +172 -0
- atomicshop/{addons/mains → a_mains}/msi_unpacker.py +3 -1
- atomicshop/a_mains/process_from_port.py +119 -0
- atomicshop/a_mains/set_default_dns_gateway.py +90 -0
- atomicshop/a_mains/update_config_toml.py +38 -0
- atomicshop/appointment_management.py +5 -3
- atomicshop/basics/ansi_escape_codes.py +3 -1
- atomicshop/basics/argparse_template.py +2 -0
- atomicshop/basics/booleans.py +27 -30
- atomicshop/basics/bytes_arrays.py +43 -0
- atomicshop/basics/classes.py +149 -1
- atomicshop/basics/dicts.py +12 -0
- atomicshop/basics/enums.py +2 -2
- atomicshop/basics/exceptions.py +5 -1
- atomicshop/basics/list_of_classes.py +29 -0
- atomicshop/basics/list_of_dicts.py +69 -5
- atomicshop/basics/lists.py +14 -0
- atomicshop/basics/multiprocesses.py +374 -50
- atomicshop/basics/package_module.py +10 -0
- atomicshop/basics/strings.py +160 -7
- atomicshop/basics/threads.py +14 -0
- atomicshop/basics/tracebacks.py +13 -4
- atomicshop/certificates.py +153 -52
- atomicshop/config_init.py +12 -7
- atomicshop/console_user_response.py +7 -14
- atomicshop/consoles.py +9 -0
- atomicshop/datetimes.py +98 -0
- atomicshop/diff_check.py +340 -40
- atomicshop/dns.py +128 -12
- atomicshop/etws/_pywintrace_fix.py +17 -0
- atomicshop/etws/const.py +38 -0
- atomicshop/etws/providers.py +21 -0
- atomicshop/etws/sessions.py +43 -0
- atomicshop/etws/trace.py +168 -0
- atomicshop/etws/traces/trace_dns.py +162 -0
- atomicshop/etws/traces/trace_sysmon_process_creation.py +126 -0
- atomicshop/etws/traces/trace_tcp.py +130 -0
- atomicshop/file_io/csvs.py +222 -24
- atomicshop/file_io/docxs.py +35 -18
- atomicshop/file_io/file_io.py +35 -19
- atomicshop/file_io/jsons.py +49 -0
- atomicshop/file_io/tomls.py +139 -0
- atomicshop/filesystem.py +864 -293
- atomicshop/get_process_list.py +133 -0
- atomicshop/{process_name_cmd.py → get_process_name_cmd_dll.py} +52 -19
- atomicshop/http_parse.py +149 -93
- atomicshop/ip_addresses.py +6 -1
- atomicshop/mitm/centered_settings.py +132 -0
- atomicshop/mitm/config_static.py +207 -0
- atomicshop/mitm/config_toml_editor.py +55 -0
- atomicshop/mitm/connection_thread_worker.py +875 -357
- atomicshop/mitm/engines/__parent/parser___parent.py +4 -17
- atomicshop/mitm/engines/__parent/recorder___parent.py +108 -51
- atomicshop/mitm/engines/__parent/requester___parent.py +116 -0
- atomicshop/mitm/engines/__parent/responder___parent.py +75 -114
- atomicshop/mitm/engines/__reference_general/parser___reference_general.py +10 -7
- atomicshop/mitm/engines/__reference_general/recorder___reference_general.py +5 -5
- atomicshop/mitm/engines/__reference_general/requester___reference_general.py +47 -0
- atomicshop/mitm/engines/__reference_general/responder___reference_general.py +95 -13
- atomicshop/mitm/engines/create_module_template.py +58 -14
- atomicshop/mitm/import_config.py +359 -139
- atomicshop/mitm/initialize_engines.py +160 -74
- atomicshop/mitm/message.py +64 -23
- atomicshop/mitm/mitm_main.py +892 -0
- atomicshop/mitm/recs_files.py +183 -0
- atomicshop/mitm/shared_functions.py +4 -10
- atomicshop/mitm/ssh_tester.py +82 -0
- atomicshop/mitm/statistic_analyzer.py +257 -166
- atomicshop/mitm/statistic_analyzer_helper/analyzer_helper.py +136 -0
- atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +525 -0
- atomicshop/monitor/change_monitor.py +96 -120
- atomicshop/monitor/checks/dns.py +139 -70
- atomicshop/monitor/checks/file.py +77 -0
- atomicshop/monitor/checks/network.py +81 -77
- atomicshop/monitor/checks/process_running.py +33 -34
- atomicshop/monitor/checks/url.py +94 -0
- atomicshop/networks.py +671 -0
- atomicshop/on_exit.py +205 -0
- atomicshop/package_mains_processor.py +84 -0
- atomicshop/permissions/permissions.py +22 -0
- atomicshop/permissions/ubuntu_permissions.py +239 -0
- atomicshop/permissions/win_permissions.py +33 -0
- atomicshop/print_api.py +24 -41
- atomicshop/process.py +63 -17
- atomicshop/process_poller/__init__.py +0 -0
- atomicshop/process_poller/pollers/__init__.py +0 -0
- atomicshop/process_poller/pollers/psutil_pywin32wmi_dll.py +95 -0
- atomicshop/process_poller/process_pool.py +207 -0
- atomicshop/process_poller/simple_process_pool.py +311 -0
- atomicshop/process_poller/tracer_base.py +45 -0
- atomicshop/process_poller/tracers/__init__.py +0 -0
- atomicshop/process_poller/tracers/event_log.py +46 -0
- atomicshop/process_poller/tracers/sysmon_etw.py +68 -0
- atomicshop/python_file_patcher.py +1 -1
- atomicshop/python_functions.py +27 -75
- atomicshop/question_answer_engine.py +2 -2
- atomicshop/scheduling.py +24 -5
- atomicshop/sound.py +4 -2
- atomicshop/speech_recognize.py +8 -0
- atomicshop/ssh_remote.py +158 -172
- atomicshop/startup/__init__.py +0 -0
- atomicshop/startup/win/__init__.py +0 -0
- atomicshop/startup/win/startup_folder.py +53 -0
- atomicshop/startup/win/task_scheduler.py +119 -0
- atomicshop/system_resource_monitor.py +61 -46
- atomicshop/system_resources.py +8 -8
- atomicshop/tempfiles.py +1 -2
- atomicshop/timer.py +30 -11
- atomicshop/urls.py +41 -0
- atomicshop/venvs.py +28 -0
- atomicshop/versioning.py +27 -0
- atomicshop/web.py +110 -25
- atomicshop/web_apis/__init__.py +0 -0
- atomicshop/web_apis/google_custom_search.py +44 -0
- atomicshop/web_apis/google_llm.py +188 -0
- atomicshop/websocket_parse.py +450 -0
- atomicshop/wrappers/certauthw/certauth.py +1 -0
- atomicshop/wrappers/cryptographyw.py +29 -8
- atomicshop/wrappers/ctyping/etw_winapi/__init__.py +0 -0
- atomicshop/wrappers/ctyping/etw_winapi/const.py +335 -0
- atomicshop/wrappers/ctyping/etw_winapi/etw_functions.py +393 -0
- atomicshop/wrappers/ctyping/file_details_winapi.py +67 -0
- atomicshop/wrappers/ctyping/msi_windows_installer/cabs.py +2 -1
- atomicshop/wrappers/ctyping/msi_windows_installer/extract_msi_main.py +13 -9
- atomicshop/wrappers/ctyping/msi_windows_installer/tables.py +35 -0
- atomicshop/wrappers/ctyping/setup_device.py +466 -0
- atomicshop/wrappers/ctyping/win_console.py +39 -0
- atomicshop/wrappers/dockerw/dockerw.py +113 -2
- atomicshop/wrappers/elasticsearchw/config_basic.py +0 -12
- atomicshop/wrappers/elasticsearchw/elastic_infra.py +75 -0
- atomicshop/wrappers/elasticsearchw/elasticsearchw.py +2 -20
- atomicshop/wrappers/factw/get_file_data.py +12 -5
- atomicshop/wrappers/factw/install/install_after_restart.py +89 -5
- atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py +20 -14
- atomicshop/wrappers/factw/postgresql/firmware.py +4 -6
- atomicshop/wrappers/githubw.py +583 -51
- atomicshop/wrappers/loggingw/consts.py +49 -0
- atomicshop/wrappers/loggingw/filters.py +102 -0
- atomicshop/wrappers/loggingw/formatters.py +58 -71
- atomicshop/wrappers/loggingw/handlers.py +459 -40
- atomicshop/wrappers/loggingw/loggers.py +19 -0
- atomicshop/wrappers/loggingw/loggingw.py +1010 -178
- atomicshop/wrappers/loggingw/reading.py +344 -19
- atomicshop/wrappers/mongodbw/__init__.py +0 -0
- atomicshop/wrappers/mongodbw/mongo_infra.py +31 -0
- atomicshop/wrappers/mongodbw/mongodbw.py +1432 -0
- atomicshop/wrappers/netshw.py +271 -0
- atomicshop/wrappers/playwrightw/engine.py +34 -19
- atomicshop/wrappers/playwrightw/infra.py +5 -0
- atomicshop/wrappers/playwrightw/javascript.py +7 -3
- atomicshop/wrappers/playwrightw/keyboard.py +14 -0
- atomicshop/wrappers/playwrightw/scenarios.py +172 -5
- atomicshop/wrappers/playwrightw/waits.py +9 -7
- atomicshop/wrappers/powershell_networking.py +80 -0
- atomicshop/wrappers/psutilw/processes.py +81 -0
- atomicshop/wrappers/psutilw/psutil_networks.py +85 -0
- atomicshop/wrappers/psutilw/psutilw.py +9 -0
- atomicshop/wrappers/pyopensslw.py +9 -2
- atomicshop/wrappers/pywin32w/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/cert_store.py +116 -0
- atomicshop/wrappers/pywin32w/console.py +34 -0
- atomicshop/wrappers/pywin32w/win_event_log/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/win_event_log/fetch.py +174 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribe.py +212 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_create.py +57 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_terminate.py +49 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/schannel_logging.py +97 -0
- atomicshop/wrappers/pywin32w/winshell.py +19 -0
- atomicshop/wrappers/pywin32w/wmis/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/wmis/msft_netipaddress.py +113 -0
- atomicshop/wrappers/pywin32w/wmis/win32_networkadapterconfiguration.py +259 -0
- atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +112 -0
- atomicshop/wrappers/pywin32w/wmis/wmi_helpers.py +236 -0
- atomicshop/wrappers/socketw/accepter.py +21 -7
- atomicshop/wrappers/socketw/certificator.py +216 -150
- atomicshop/wrappers/socketw/creator.py +190 -50
- atomicshop/wrappers/socketw/dns_server.py +500 -173
- atomicshop/wrappers/socketw/exception_wrapper.py +45 -52
- atomicshop/wrappers/socketw/process_getter.py +86 -0
- atomicshop/wrappers/socketw/receiver.py +144 -102
- atomicshop/wrappers/socketw/sender.py +65 -35
- atomicshop/wrappers/socketw/sni.py +334 -165
- atomicshop/wrappers/socketw/socket_base.py +134 -0
- atomicshop/wrappers/socketw/socket_client.py +137 -95
- atomicshop/wrappers/socketw/socket_server_tester.py +14 -9
- atomicshop/wrappers/socketw/socket_wrapper.py +717 -116
- atomicshop/wrappers/socketw/ssl_base.py +15 -14
- atomicshop/wrappers/socketw/statistics_csv.py +148 -17
- atomicshop/wrappers/sysmonw.py +157 -0
- atomicshop/wrappers/ubuntu_terminal.py +65 -26
- atomicshop/wrappers/win_auditw.py +189 -0
- atomicshop/wrappers/winregw/__init__.py +0 -0
- atomicshop/wrappers/winregw/winreg_installed_software.py +58 -0
- atomicshop/wrappers/winregw/winreg_network.py +232 -0
- {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info}/METADATA +31 -49
- atomicshop-3.10.5.dist-info/RECORD +306 -0
- {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info}/WHEEL +1 -1
- atomicshop/_basics_temp.py +0 -101
- atomicshop/addons/a_setup_scripts/install_psycopg2_ubuntu.sh +0 -3
- atomicshop/addons/a_setup_scripts/install_pywintrace_0.3.cmd +0 -2
- atomicshop/addons/mains/install_docker_rootless_ubuntu.py +0 -11
- atomicshop/addons/mains/install_docker_ubuntu_main_sudo.py +0 -11
- atomicshop/addons/mains/install_elastic_search_and_kibana_ubuntu.py +0 -10
- atomicshop/addons/mains/install_wsl_ubuntu_lts_admin.py +0 -9
- atomicshop/addons/package_setup/CreateWheel.cmd +0 -7
- atomicshop/addons/package_setup/Setup in Edit mode.cmd +0 -6
- atomicshop/addons/package_setup/Setup.cmd +0 -7
- atomicshop/addons/process_list/compile.cmd +0 -2
- atomicshop/addons/process_list/compiled/Win10x64/process_list.dll +0 -0
- atomicshop/addons/process_list/compiled/Win10x64/process_list.exp +0 -0
- atomicshop/addons/process_list/compiled/Win10x64/process_list.lib +0 -0
- atomicshop/archiver/_search_in_zip.py +0 -189
- atomicshop/archiver/archiver.py +0 -34
- atomicshop/archiver/search_in_archive.py +0 -250
- atomicshop/archiver/sevenz_app_w.py +0 -86
- atomicshop/archiver/sevenzs.py +0 -44
- atomicshop/archiver/zips.py +0 -293
- atomicshop/etw/dns_trace.py +0 -118
- atomicshop/etw/etw.py +0 -61
- atomicshop/file_types.py +0 -24
- atomicshop/mitm/engines/create_module_template_example.py +0 -13
- atomicshop/mitm/initialize_mitm_server.py +0 -240
- atomicshop/monitor/checks/hash.py +0 -44
- atomicshop/monitor/checks/hash_checks/file.py +0 -55
- atomicshop/monitor/checks/hash_checks/url.py +0 -62
- atomicshop/pbtkmultifile_argparse.py +0 -88
- atomicshop/permissions.py +0 -110
- atomicshop/process_poller.py +0 -237
- atomicshop/script_as_string_processor.py +0 -38
- atomicshop/ssh_scripts/process_from_ipv4.py +0 -37
- atomicshop/ssh_scripts/process_from_port.py +0 -27
- atomicshop/wrappers/_process_wrapper_curl.py +0 -27
- atomicshop/wrappers/_process_wrapper_tar.py +0 -21
- atomicshop/wrappers/dockerw/install_docker.py +0 -209
- atomicshop/wrappers/elasticsearchw/infrastructure.py +0 -265
- atomicshop/wrappers/elasticsearchw/install_elastic.py +0 -232
- atomicshop/wrappers/ffmpegw.py +0 -125
- atomicshop/wrappers/loggingw/checks.py +0 -20
- atomicshop/wrappers/nodejsw/install_nodejs.py +0 -139
- atomicshop/wrappers/process_wrapper_pbtk.py +0 -16
- atomicshop/wrappers/socketw/base.py +0 -59
- atomicshop/wrappers/socketw/get_process.py +0 -107
- atomicshop/wrappers/wslw.py +0 -191
- atomicshop-2.11.47.dist-info/RECORD +0 -251
- /atomicshop/{addons/mains → a_mains}/FACT/factw_fact_extractor_docker_image_main_sudo.py +0 -0
- /atomicshop/{addons → a_mains/addons}/PlayWrightCodegen.cmd +0 -0
- /atomicshop/{addons → a_mains/addons}/ScriptExecution.cmd +0 -0
- /atomicshop/{addons/mains → a_mains/addons}/inits/init_to_import_all_modules.py +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/ReadMe.txt +0 -0
- /atomicshop/{addons/mains → a_mains}/search_for_hyperlinks_in_docx.py +0 -0
- /atomicshop/{archiver → etws}/__init__.py +0 -0
- /atomicshop/{etw → etws/traces}/__init__.py +0 -0
- /atomicshop/{monitor/checks/hash_checks → mitm/statistic_analyzer_helper}/__init__.py +0 -0
- /atomicshop/{wrappers/nodejsw → permissions}/__init__.py +0 -0
- /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
- {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info/licenses}/LICENSE.txt +0 -0
- {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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def _get_list(change_monitor_instance):
|
|
13
|
+
class NetworkCheck:
|
|
45
14
|
"""
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6
|
+
class ProcessRunningCheck:
|
|
7
7
|
"""
|
|
8
|
-
|
|
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
|
-
|
|
16
|
-
|
|
11
|
+
def __init__(self, change_monitor_instance):
|
|
12
|
+
self.change_monitor_instance = change_monitor_instance
|
|
13
|
+
self.fetch_engine = psutilw.PsutilProcesses()
|
|
17
14
|
|
|
18
|
-
|
|
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
|
-
|
|
19
|
+
:param print_kwargs: Dictionary with the print arguments.
|
|
20
|
+
:return: List of dictionaries with the results of the cycle.
|
|
21
|
+
"""
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
result = list_of_dicts.is_value_exist_in_key(processes, 'cmdline', process_name)
|
|
23
|
+
return_list = list()
|
|
24
24
|
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
change_monitor_instance.fetch_engine = psutilw.PsutilProcesses()
|
|
48
|
+
:return: list of dicts, of new network sockets.
|
|
49
|
+
"""
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
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
|