atomicshop 2.15.11__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/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/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/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/enums.py +2 -2
- atomicshop/basics/exceptions.py +5 -1
- atomicshop/basics/list_of_classes.py +29 -0
- atomicshop/basics/multiprocesses.py +374 -50
- atomicshop/basics/strings.py +72 -3
- atomicshop/basics/threads.py +14 -0
- atomicshop/basics/tracebacks.py +13 -3
- atomicshop/certificates.py +153 -52
- atomicshop/config_init.py +11 -6
- atomicshop/console_user_response.py +7 -14
- atomicshop/consoles.py +9 -0
- atomicshop/datetimes.py +1 -1
- atomicshop/diff_check.py +3 -3
- atomicshop/dns.py +128 -3
- atomicshop/etws/_pywintrace_fix.py +17 -0
- atomicshop/etws/trace.py +40 -42
- atomicshop/etws/traces/trace_dns.py +56 -44
- atomicshop/etws/traces/trace_tcp.py +130 -0
- atomicshop/file_io/csvs.py +27 -5
- atomicshop/file_io/docxs.py +34 -17
- atomicshop/file_io/file_io.py +31 -17
- atomicshop/file_io/jsons.py +49 -0
- atomicshop/file_io/tomls.py +139 -0
- atomicshop/filesystem.py +616 -291
- atomicshop/get_process_list.py +3 -3
- 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 -80
- 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 +136 -40
- atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +265 -83
- atomicshop/monitor/checks/dns.py +1 -1
- atomicshop/networks.py +671 -0
- atomicshop/on_exit.py +39 -9
- 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 -42
- atomicshop/process.py +24 -6
- atomicshop/process_poller/process_pool.py +0 -1
- atomicshop/process_poller/simple_process_pool.py +204 -5
- atomicshop/python_file_patcher.py +1 -1
- atomicshop/python_functions.py +27 -75
- atomicshop/speech_recognize.py +8 -0
- atomicshop/ssh_remote.py +158 -172
- atomicshop/system_resource_monitor.py +61 -47
- atomicshop/system_resources.py +8 -8
- atomicshop/tempfiles.py +1 -2
- atomicshop/urls.py +6 -0
- atomicshop/venvs.py +28 -0
- atomicshop/versioning.py +27 -0
- atomicshop/web.py +98 -27
- 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/const.py +97 -47
- atomicshop/wrappers/ctyping/etw_winapi/etw_functions.py +178 -49
- 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 +2 -2
- 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/githubw.py +537 -54
- atomicshop/wrappers/loggingw/consts.py +1 -1
- atomicshop/wrappers/loggingw/filters.py +23 -0
- atomicshop/wrappers/loggingw/formatters.py +12 -0
- atomicshop/wrappers/loggingw/handlers.py +214 -107
- atomicshop/wrappers/loggingw/loggers.py +19 -0
- atomicshop/wrappers/loggingw/loggingw.py +860 -22
- atomicshop/wrappers/loggingw/reading.py +134 -112
- atomicshop/wrappers/mongodbw/mongo_infra.py +31 -0
- atomicshop/wrappers/mongodbw/mongodbw.py +1324 -36
- 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 +37 -1
- atomicshop/wrappers/psutilw/psutil_networks.py +85 -0
- atomicshop/wrappers/pyopensslw.py +9 -2
- atomicshop/wrappers/pywin32w/cert_store.py +116 -0
- atomicshop/wrappers/pywin32w/win_event_log/fetch.py +174 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_create.py +3 -105
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_terminate.py +3 -57
- 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 +491 -182
- 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 +11 -7
- 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 +1 -1
- 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.15.11.dist-info → atomicshop-3.10.5.dist-info}/METADATA +31 -51
- atomicshop-3.10.5.dist-info/RECORD +306 -0
- {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info}/WHEEL +1 -1
- atomicshop/_basics_temp.py +0 -101
- atomicshop/a_installs/win/fibratus.py +0 -9
- atomicshop/a_installs/win/mongodb.py +0 -9
- atomicshop/a_installs/win/pycharm.py +0 -9
- 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/__pycache__/install_fibratus_windows.cpython-312.pyc +0 -0
- atomicshop/addons/mains/__pycache__/msi_unpacker.cpython-312.pyc +0 -0
- 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/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/file_types.py +0 -24
- atomicshop/mitm/config_editor.py +0 -37
- atomicshop/mitm/engines/create_module_template_example.py +0 -13
- atomicshop/mitm/initialize_mitm_server.py +0 -268
- atomicshop/pbtkmultifile_argparse.py +0 -88
- atomicshop/permissions.py +0 -151
- 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/fibratusw/install.py +0 -81
- atomicshop/wrappers/mongodbw/infrastructure.py +0 -53
- atomicshop/wrappers/mongodbw/install_mongodb.py +0 -190
- atomicshop/wrappers/msiw.py +0 -149
- atomicshop/wrappers/nodejsw/install_nodejs.py +0 -139
- atomicshop/wrappers/process_wrapper_pbtk.py +0 -16
- atomicshop/wrappers/psutilw/networks.py +0 -45
- atomicshop/wrappers/pycharmw.py +0 -81
- atomicshop/wrappers/socketw/base.py +0 -59
- atomicshop/wrappers/socketw/get_process.py +0 -107
- atomicshop/wrappers/wslw.py +0 -191
- atomicshop-2.15.11.dist-info/RECORD +0 -302
- /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 → 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 → a_mains/addons}/process_list/compile.cmd +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.dll +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.exp +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.lib +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/process_list.cpp +0 -0
- /atomicshop/{archiver → permissions}/__init__.py +0 -0
- /atomicshop/{wrappers/fibratusw → web_apis}/__init__.py +0 -0
- /atomicshop/wrappers/{nodejsw → pywin32w/wmis}/__init__.py +0 -0
- /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
- {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info/licenses}/LICENSE.txt +0 -0
- {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info}/top_level.txt +0 -0
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import os.path
|
|
2
|
-
import subprocess
|
|
3
|
-
import time
|
|
4
|
-
from typing import Literal
|
|
5
|
-
|
|
6
|
-
from .. import githubw, msiw
|
|
7
|
-
from ... import filesystem
|
|
8
|
-
from ...print_api import print_api
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
DEFAULT_INSTALLATION_EXE_PATH = r"C:\Program Files\Fibratus\Bin\fibratus.exe"
|
|
12
|
-
WAIT_SECONDS_FOR_EXECUTABLE_TO_APPEAR_AFTER_INSTALLATION: float = 10
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def install_fibratus(
|
|
16
|
-
installation_file_download_directory: str = None,
|
|
17
|
-
place_to_download_file: Literal['working', 'temp', 'script'] = 'temp',
|
|
18
|
-
remove_file_after_installation: bool = False
|
|
19
|
-
):
|
|
20
|
-
"""
|
|
21
|
-
Download latest release from GitHub and install Fibratus.
|
|
22
|
-
:param installation_file_download_directory: Directory to download the installation file. If None, the download
|
|
23
|
-
directory will be automatically determined, by the 'place_to_download_file' parameter.
|
|
24
|
-
:param place_to_download_file: Where to download the installation file.
|
|
25
|
-
'working' is the working directory of the script.
|
|
26
|
-
'temp' is the temporary directory.
|
|
27
|
-
'script' is the directory of the script.
|
|
28
|
-
:param remove_file_after_installation: Whether to remove the installation file after installation.
|
|
29
|
-
:return:
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
if not installation_file_download_directory:
|
|
33
|
-
installation_file_download_directory = filesystem.get_download_directory(
|
|
34
|
-
place=place_to_download_file, script_path=__file__)
|
|
35
|
-
|
|
36
|
-
github_wrapper = githubw.GitHubWrapper(user_name='rabbitstack', repo_name='fibratus')
|
|
37
|
-
fibratus_setup_file_path: str = github_wrapper.download_latest_release(
|
|
38
|
-
target_directory=installation_file_download_directory,
|
|
39
|
-
string_pattern='*fibratus-*-amd64.msi',
|
|
40
|
-
exclude_string='slim')
|
|
41
|
-
|
|
42
|
-
# Install the MSI file
|
|
43
|
-
msiw.install_msi(
|
|
44
|
-
msi_path=fibratus_setup_file_path, exit_on_error=True, as_admin=True)
|
|
45
|
-
|
|
46
|
-
count = 0
|
|
47
|
-
while count != WAIT_SECONDS_FOR_EXECUTABLE_TO_APPEAR_AFTER_INSTALLATION:
|
|
48
|
-
if os.path.isfile(DEFAULT_INSTALLATION_EXE_PATH):
|
|
49
|
-
break
|
|
50
|
-
count += 1
|
|
51
|
-
time.sleep(1)
|
|
52
|
-
|
|
53
|
-
if count == WAIT_SECONDS_FOR_EXECUTABLE_TO_APPEAR_AFTER_INSTALLATION:
|
|
54
|
-
message = \
|
|
55
|
-
(f"Fibratus installation failed. The executable was not found after "
|
|
56
|
-
f"{str(WAIT_SECONDS_FOR_EXECUTABLE_TO_APPEAR_AFTER_INSTALLATION)} seconds.\n"
|
|
57
|
-
f"{DEFAULT_INSTALLATION_EXE_PATH}")
|
|
58
|
-
print_api(message, color="red")
|
|
59
|
-
|
|
60
|
-
result = None
|
|
61
|
-
# Check if the installation was successful
|
|
62
|
-
try:
|
|
63
|
-
result = subprocess.run([DEFAULT_INSTALLATION_EXE_PATH], capture_output=True, text=True)
|
|
64
|
-
except FileNotFoundError:
|
|
65
|
-
print_api("Fibratus executable not found.", color="red")
|
|
66
|
-
|
|
67
|
-
if result:
|
|
68
|
-
if result.returncode == 0:
|
|
69
|
-
print_api("Fibratus installed successfully. Please restart.", color="green")
|
|
70
|
-
else:
|
|
71
|
-
print_api("Fibratus installation failed.", color="red")
|
|
72
|
-
print_api(result.stderr)
|
|
73
|
-
raise Exception("Fibratus installation failed.")
|
|
74
|
-
else:
|
|
75
|
-
print_api("Fibratus executable not found.", color="red")
|
|
76
|
-
|
|
77
|
-
# Wait for the installation to finish before removing the file.
|
|
78
|
-
time.sleep(5)
|
|
79
|
-
|
|
80
|
-
if remove_file_after_installation:
|
|
81
|
-
filesystem.remove_file(fibratus_setup_file_path)
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
from typing import Union
|
|
2
|
-
|
|
3
|
-
from pymongo import MongoClient
|
|
4
|
-
import pymongo.errors
|
|
5
|
-
|
|
6
|
-
from ... import get_process_list, filesystem
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
WHERE_TO_SEARCH_FOR_MONGODB_EXE: str = 'C:\\Program Files\\MongoDB\\Server\\'
|
|
10
|
-
MONGODB_EXE_NAME: str = 'mongod.exe'
|
|
11
|
-
MONGODB_DEFAULT_URI: str = 'mongodb://localhost:27017/'
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class MongoDBNoConnectionError(Exception):
|
|
15
|
-
pass
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def test_connection(
|
|
19
|
-
uri: str = MONGODB_DEFAULT_URI,
|
|
20
|
-
raise_exception: bool = False
|
|
21
|
-
) -> bool:
|
|
22
|
-
try:
|
|
23
|
-
client = MongoClient(uri)
|
|
24
|
-
client.admin.command('ping')
|
|
25
|
-
return True
|
|
26
|
-
except pymongo.errors.ServerSelectionTimeoutError:
|
|
27
|
-
if raise_exception:
|
|
28
|
-
raise MongoDBNoConnectionError(f"Could not connect to the MongoDB server on: ")
|
|
29
|
-
return False
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def is_service_running() -> bool:
|
|
33
|
-
"""
|
|
34
|
-
Check if the MongoDB service is running.
|
|
35
|
-
:return: bool, True if the MongoDB service is running, False otherwise.
|
|
36
|
-
"""
|
|
37
|
-
current_processes: dict = (
|
|
38
|
-
get_process_list.GetProcessList(get_method='pywin32', connect_on_init=True).get_processes())
|
|
39
|
-
|
|
40
|
-
for pid, process_info in current_processes.items():
|
|
41
|
-
if MONGODB_EXE_NAME in process_info['name']:
|
|
42
|
-
return True
|
|
43
|
-
|
|
44
|
-
return False
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def is_installed() -> Union[str, None]:
|
|
48
|
-
"""
|
|
49
|
-
Check if MongoDB is installed.
|
|
50
|
-
:return: string if MongoDB executable is found, None otherwise.
|
|
51
|
-
"""
|
|
52
|
-
|
|
53
|
-
return filesystem.find_file(MONGODB_EXE_NAME, WHERE_TO_SEARCH_FOR_MONGODB_EXE)
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import requests
|
|
3
|
-
from typing import Union
|
|
4
|
-
import argparse
|
|
5
|
-
import subprocess
|
|
6
|
-
|
|
7
|
-
from ... import urls, web, permissions
|
|
8
|
-
from ...print_api import print_api
|
|
9
|
-
from .. import msiw
|
|
10
|
-
from . import infrastructure
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
MONGODB_DOWNLOAD_PAGE_URL: str = 'https://www.mongodb.com/try/download/community'
|
|
14
|
-
COMPASS_INSTALLATION_SCRIPT_URL: str = \
|
|
15
|
-
'https://raw.githubusercontent.com/mongodb/mongo/master/src/mongo/installer/compass/Install-Compass.ps1'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class MongoDBWebPageNoSuccessCodeError(Exception):
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class MongoDBNoDownloadLinksError(Exception):
|
|
23
|
-
pass
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class MongoDBNoDownloadLinkForWindowsError(Exception):
|
|
27
|
-
pass
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class MongoDBInstallationError(Exception):
|
|
31
|
-
pass
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def get_latest_mongodb_download_url(
|
|
35
|
-
no_rc_version: bool = True,
|
|
36
|
-
major_specific: int = None
|
|
37
|
-
):
|
|
38
|
-
response = requests.get(MONGODB_DOWNLOAD_PAGE_URL)
|
|
39
|
-
|
|
40
|
-
if response.status_code != 200:
|
|
41
|
-
raise MongoDBWebPageNoSuccessCodeError("Failed to load the download page.")
|
|
42
|
-
|
|
43
|
-
urls_in_page: list = urls.find_urls_in_text(response.text)
|
|
44
|
-
if not urls_in_page:
|
|
45
|
-
raise MongoDBNoDownloadLinksError("Could not find the download link for MongoDB Community Server.")
|
|
46
|
-
|
|
47
|
-
windows_urls: list = []
|
|
48
|
-
for url in urls_in_page:
|
|
49
|
-
if 'windows' in url and 'x86_64' in url and url.endswith('.msi'):
|
|
50
|
-
if no_rc_version and '-rc' in url:
|
|
51
|
-
continue
|
|
52
|
-
windows_urls.append(url)
|
|
53
|
-
|
|
54
|
-
if major_specific:
|
|
55
|
-
for url in windows_urls:
|
|
56
|
-
if f'-{major_specific}.' in url:
|
|
57
|
-
windows_urls = [url]
|
|
58
|
-
break
|
|
59
|
-
|
|
60
|
-
if not windows_urls:
|
|
61
|
-
raise MongoDBNoDownloadLinkForWindowsError(
|
|
62
|
-
"Could not find the download link for MongoDB Community Server for Windows x86_64.")
|
|
63
|
-
|
|
64
|
-
# Return the latest URL only.
|
|
65
|
-
return windows_urls[0]
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def parse_args():
|
|
69
|
-
parser = argparse.ArgumentParser(description='Install MongoDB Community Server.')
|
|
70
|
-
parser.add_argument(
|
|
71
|
-
'-nr', '--no-rc', action='store_true', help='Do not download release candidate versions.')
|
|
72
|
-
parser.add_argument(
|
|
73
|
-
'-m', '--major', type=int, help='Download the latest version of the specified major version.')
|
|
74
|
-
parser.add_argument(
|
|
75
|
-
'-c', '--compass', action='store_true', help='Install MongoDB Compass.')
|
|
76
|
-
parser.add_argument(
|
|
77
|
-
'-f', '--force', action='store_true', help='Force the installation even if MongoDB is already installed.')
|
|
78
|
-
|
|
79
|
-
return parser.parse_args()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def download_install_latest_main(
|
|
83
|
-
no_rc_version: bool = False,
|
|
84
|
-
major_specific: int = None,
|
|
85
|
-
compass: bool = False,
|
|
86
|
-
force: bool = False
|
|
87
|
-
):
|
|
88
|
-
"""
|
|
89
|
-
Download and install the latest version of MongoDB Community Server.
|
|
90
|
-
:param no_rc_version: bool, if True, the latest non-RC version will be downloaded.
|
|
91
|
-
:param major_specific: int, if set, the latest version of the specified major version will be downloaded.
|
|
92
|
-
:param compass: bool, if True, MongoDB Compass will be installed.
|
|
93
|
-
:param force: bool, if True, MongoDB will be installed even if it is already installed.
|
|
94
|
-
:return:
|
|
95
|
-
"""
|
|
96
|
-
|
|
97
|
-
args = parse_args()
|
|
98
|
-
|
|
99
|
-
# Set the args only if they were used.
|
|
100
|
-
if args.no_rc:
|
|
101
|
-
no_rc_version = args.no_rc
|
|
102
|
-
if args.major:
|
|
103
|
-
major_specific = args.major
|
|
104
|
-
if args.compass:
|
|
105
|
-
compass = args.compass
|
|
106
|
-
if args.force:
|
|
107
|
-
force = args.force
|
|
108
|
-
|
|
109
|
-
if not permissions.is_admin():
|
|
110
|
-
print_api("This function requires administrator privileges.", color='red')
|
|
111
|
-
return 1
|
|
112
|
-
|
|
113
|
-
if infrastructure.is_service_running():
|
|
114
|
-
print_api("MongoDB service is running - already installed.", color='blue')
|
|
115
|
-
|
|
116
|
-
if not force:
|
|
117
|
-
return 0
|
|
118
|
-
else:
|
|
119
|
-
print_api("MongoDB is service is not running.")
|
|
120
|
-
|
|
121
|
-
mongo_is_installed: Union[str, None] = infrastructure.is_installed()
|
|
122
|
-
if infrastructure.is_installed():
|
|
123
|
-
message = f"MongoDB is installed in: {mongo_is_installed}\n" \
|
|
124
|
-
f"The service is not running. Fix the service or use the 'force' parameter to reinstall."
|
|
125
|
-
print_api(message, color='yellow')
|
|
126
|
-
|
|
127
|
-
if not force:
|
|
128
|
-
return 0
|
|
129
|
-
|
|
130
|
-
print_api("Fetching the latest MongoDB download URL...")
|
|
131
|
-
mongo_installer_url = get_latest_mongodb_download_url(no_rc_version=no_rc_version, major_specific=major_specific)
|
|
132
|
-
|
|
133
|
-
print_api(f"Downloading MongoDB installer from: {mongo_installer_url}")
|
|
134
|
-
installer_file_path: str = web.download(mongo_installer_url)
|
|
135
|
-
|
|
136
|
-
print_api("Installing MongoDB...")
|
|
137
|
-
try:
|
|
138
|
-
msiw.install_msi(
|
|
139
|
-
installer_file_path,
|
|
140
|
-
silent_no_gui=True,
|
|
141
|
-
no_restart=True,
|
|
142
|
-
terminate_required_processes=True,
|
|
143
|
-
create_log_near_msi=True,
|
|
144
|
-
scan_log_for_errors=True,
|
|
145
|
-
additional_args='ADDLOCAL="ServerService"'
|
|
146
|
-
)
|
|
147
|
-
except msiw.MsiInstallationError as e:
|
|
148
|
-
print_api(f'{e} Exiting...', color='red')
|
|
149
|
-
return 1
|
|
150
|
-
|
|
151
|
-
# Check if MongoDB is installed.
|
|
152
|
-
message: str = ''
|
|
153
|
-
mongo_is_installed = infrastructure.is_installed()
|
|
154
|
-
if not mongo_is_installed:
|
|
155
|
-
message += "MongoDB Executable not found.\n"
|
|
156
|
-
|
|
157
|
-
if not infrastructure.is_service_running():
|
|
158
|
-
message += "MongoDB service is not running.\n"
|
|
159
|
-
|
|
160
|
-
if message:
|
|
161
|
-
message += f"MSI Path: {installer_file_path}"
|
|
162
|
-
print_api(message, color='red')
|
|
163
|
-
return 1
|
|
164
|
-
else:
|
|
165
|
-
success_message: str = f"MongoDB installed successfully to: {mongo_is_installed}\n" \
|
|
166
|
-
f"Service is running."
|
|
167
|
-
print_api(success_message, color='green')
|
|
168
|
-
|
|
169
|
-
# Clean up the installer file
|
|
170
|
-
if os.path.exists(installer_file_path):
|
|
171
|
-
os.remove(installer_file_path)
|
|
172
|
-
print_api("Cleaned up the installer file.")
|
|
173
|
-
|
|
174
|
-
if not compass:
|
|
175
|
-
return 0
|
|
176
|
-
|
|
177
|
-
# It doesn't matter what you do with the MSI it will not install Compass, only if you run it manually.
|
|
178
|
-
# So we will use installation script from their GitHub.
|
|
179
|
-
print_api("Downloading MongoDB Compass installation script...")
|
|
180
|
-
compass_script_path: str = web.download(COMPASS_INSTALLATION_SCRIPT_URL)
|
|
181
|
-
|
|
182
|
-
print_api("Installing MongoDB Compass from script...")
|
|
183
|
-
subprocess.run(["powershell", "-ExecutionPolicy", "Bypass", "-File", compass_script_path])
|
|
184
|
-
|
|
185
|
-
# Clean up the installer file
|
|
186
|
-
if os.path.exists(compass_script_path):
|
|
187
|
-
os.remove(compass_script_path)
|
|
188
|
-
print_api("Cleaned up the Compass installer file.")
|
|
189
|
-
|
|
190
|
-
return 0
|
atomicshop/wrappers/msiw.py
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import subprocess
|
|
2
|
-
import sys
|
|
3
|
-
|
|
4
|
-
from ..print_api import print_api
|
|
5
|
-
from .. import permissions
|
|
6
|
-
from ..import get_process_list
|
|
7
|
-
from .psutilw import processes
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ERROR_CODES = {
|
|
11
|
-
'1603': 'The App is already installed or Insufficient permissions',
|
|
12
|
-
'1619': 'This installation package could not be opened. Verify that the package exists and that you can '
|
|
13
|
-
'install it manually, also check the installation command line switches'
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class MsiInstallationError(Exception):
|
|
18
|
-
pass
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def get_current_msiexec_processes(msi_file_path: str = None) -> dict:
|
|
22
|
-
"""
|
|
23
|
-
Get the current msiexec processes.
|
|
24
|
-
:param msi_file_path: string, OPTIONAL path to the MSI file to check in the command line.
|
|
25
|
-
:return: list of dicts, each key represents a pid and its values are process name and cmdline.
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
current_processes: dict = (
|
|
29
|
-
get_process_list.GetProcessList(get_method='pywin32', connect_on_init=True).get_processes())
|
|
30
|
-
|
|
31
|
-
current_msiexec_dict: dict = {}
|
|
32
|
-
for pid, process_info in current_processes.items():
|
|
33
|
-
if 'msiexec.exe' in process_info['name']:
|
|
34
|
-
if msi_file_path:
|
|
35
|
-
if msi_file_path in process_info['cmdline']:
|
|
36
|
-
current_msiexec_dict[pid] = process_info
|
|
37
|
-
else:
|
|
38
|
-
current_msiexec_dict[pid] = process_info
|
|
39
|
-
|
|
40
|
-
return current_msiexec_dict
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def wait_for_msiexec_processes_to_finish(msi_file_path: str):
|
|
44
|
-
"""
|
|
45
|
-
Wait for the msiexec processes to finish.
|
|
46
|
-
:param msi_file_path: string, path to the MSI file.
|
|
47
|
-
:return:
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
current_msiexec: dict = get_current_msiexec_processes(msi_file_path)
|
|
51
|
-
current_pid = list(current_msiexec.keys())[0]
|
|
52
|
-
|
|
53
|
-
result_code = processes.wait_for_process(current_pid)
|
|
54
|
-
if result_code != 0:
|
|
55
|
-
raise Exception(f"MSI Installation failed. Return code: {result_code}")
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def install_msi(
|
|
59
|
-
msi_path,
|
|
60
|
-
silent_no_gui: bool = False,
|
|
61
|
-
silent_progress_bar: bool = False,
|
|
62
|
-
no_restart: bool = False,
|
|
63
|
-
terminate_required_processes: bool = False,
|
|
64
|
-
additional_args: str = None,
|
|
65
|
-
create_log_near_msi: bool = False,
|
|
66
|
-
log_file_path: str = None,
|
|
67
|
-
scan_log_for_errors: bool = False,
|
|
68
|
-
# as_admin=True,
|
|
69
|
-
print_kwargs: dict = None):
|
|
70
|
-
"""
|
|
71
|
-
Install an MSI file silently.
|
|
72
|
-
:param msi_path: str, path to the MSI file.
|
|
73
|
-
:param silent_no_gui: bool, whether to run the installation silently, without showing GUI.
|
|
74
|
-
:param silent_progress_bar: bool, whether to show a progress bar during silent installation.
|
|
75
|
-
:param no_restart: bool, whether to restart the computer after installation.
|
|
76
|
-
:param terminate_required_processes: bool, whether to terminate processes that are required by the installation.
|
|
77
|
-
:param additional_args: str, additional arguments to pass to the msiexec command.
|
|
78
|
-
:param create_log_near_msi: bool, whether to create a log file near the MSI file.
|
|
79
|
-
If the msi file located in 'c:\\path\\to\\file.msi', the log file will be created in 'c:\\path\\to\\file.log'.
|
|
80
|
-
The log options that will be used: /l*v c:\\path\\to\\file.log
|
|
81
|
-
:param log_file_path: str, path to the log file. Even if 'create_log_near_msi' is False, you can specify a custom
|
|
82
|
-
path for the log file, and it will be created.
|
|
83
|
-
The log options that will be used: /l*v c:\\path\\to\\file.log
|
|
84
|
-
:param scan_log_for_errors: bool, whether to scan the log file for errors in case of failure.
|
|
85
|
-
# :param as_admin: bool, whether to run the installation as administrator.
|
|
86
|
-
:param print_kwargs: dict, print_api kwargs.
|
|
87
|
-
:return:
|
|
88
|
-
"""
|
|
89
|
-
|
|
90
|
-
if not permissions.is_admin():
|
|
91
|
-
raise PermissionError("This function requires administrator privileges.")
|
|
92
|
-
|
|
93
|
-
if silent_progress_bar and silent_no_gui:
|
|
94
|
-
raise ValueError("silent_progress_bar and silent_no_gui cannot be both True.")
|
|
95
|
-
|
|
96
|
-
if create_log_near_msi and log_file_path:
|
|
97
|
-
raise ValueError("create_log_near_msi and log_file_path cannot be both set.")
|
|
98
|
-
|
|
99
|
-
if create_log_near_msi:
|
|
100
|
-
log_file_path = msi_path.replace('.msi', '.log')
|
|
101
|
-
|
|
102
|
-
if scan_log_for_errors and not log_file_path:
|
|
103
|
-
raise ValueError("[scan_log_for_errors] is set, but [log_file_path] or [create_log_near_msi] is not set.")
|
|
104
|
-
|
|
105
|
-
# Define the msiexec command
|
|
106
|
-
command = f'msiexec /i "{msi_path}"'
|
|
107
|
-
|
|
108
|
-
if silent_no_gui:
|
|
109
|
-
command = f"{command} /qn"
|
|
110
|
-
if silent_progress_bar:
|
|
111
|
-
command = f"{command} /qb"
|
|
112
|
-
if no_restart:
|
|
113
|
-
command = f"{command} /norestart"
|
|
114
|
-
|
|
115
|
-
if log_file_path:
|
|
116
|
-
command = f"{command} /l*v {log_file_path}"
|
|
117
|
-
|
|
118
|
-
if terminate_required_processes:
|
|
119
|
-
command = f"{command} REBOOT=ReallySuppress"
|
|
120
|
-
|
|
121
|
-
if additional_args:
|
|
122
|
-
if additional_args.startswith(' '):
|
|
123
|
-
additional_args = additional_args[1:]
|
|
124
|
-
command = f"{command} {additional_args}"
|
|
125
|
-
|
|
126
|
-
# if as_admin:
|
|
127
|
-
# command = permissions.get_command_to_run_as_admin_windows(command)
|
|
128
|
-
|
|
129
|
-
# Run the command
|
|
130
|
-
result = subprocess.run(command, capture_output=True, text=True)
|
|
131
|
-
|
|
132
|
-
# Check the result
|
|
133
|
-
if result.returncode == 0:
|
|
134
|
-
print_api("MSI Installation completed.", color="green", **(print_kwargs or {}))
|
|
135
|
-
else:
|
|
136
|
-
message = (f"Installation failed. Return code: {result.returncode}\n{ERROR_CODES.get(str(result.returncode), '')}\n"
|
|
137
|
-
f"MSI path: {msi_path}\nCommand: {command}\nOutput: {result.stdout}\nError: {result.stderr}")
|
|
138
|
-
|
|
139
|
-
if scan_log_for_errors:
|
|
140
|
-
with open(log_file_path, 'r', encoding='utf-16 le') as f:
|
|
141
|
-
log_content = f.read()
|
|
142
|
-
if 'error' in log_content.lower():
|
|
143
|
-
# Get the error text of the lines that contain 'error'.
|
|
144
|
-
error_lines = [line for line in log_content.split('\n') if 'error' in line.lower()]
|
|
145
|
-
for line in error_lines:
|
|
146
|
-
message += f"\n{line}"
|
|
147
|
-
|
|
148
|
-
print_api(message, color="red", **(print_kwargs or {}))
|
|
149
|
-
raise MsiInstallationError("MSI Installation Failed.")
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import subprocess
|
|
2
|
-
import requests
|
|
3
|
-
|
|
4
|
-
from ...basics import booleans
|
|
5
|
-
from .. import githubw, ubuntu_terminal
|
|
6
|
-
from ...print_api import print_api
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def is_nodejs_installed():
|
|
10
|
-
"""
|
|
11
|
-
The function will check if Node.js is installed.
|
|
12
|
-
:return: bool.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
try:
|
|
16
|
-
# Run the command 'node -v'
|
|
17
|
-
result = subprocess.run(['node', '-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
18
|
-
|
|
19
|
-
# Check if the command was successful
|
|
20
|
-
if result.returncode == 0:
|
|
21
|
-
message = f"Node.js installed. Version: {result.stdout.strip()}"
|
|
22
|
-
print_api(message, color='green')
|
|
23
|
-
return True
|
|
24
|
-
else:
|
|
25
|
-
print_api("Node.js is not installed.")
|
|
26
|
-
return False
|
|
27
|
-
except FileNotFoundError:
|
|
28
|
-
print_api("Node command not found. Node.js is not installed.")
|
|
29
|
-
return False
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def get_nodejs_latest_version_number(
|
|
33
|
-
by_github_api: bool = True,
|
|
34
|
-
_by_nodejs_website: bool = False,
|
|
35
|
-
get_major: bool = False
|
|
36
|
-
) -> str:
|
|
37
|
-
"""
|
|
38
|
-
The function will get the latest version number of Node.js.
|
|
39
|
-
:param by_github_api: bool, if True, the function will get the version number using the GitHub API.
|
|
40
|
-
Limitations: rate limits apply.
|
|
41
|
-
:param _by_nodejs_website: bool, if True, the function will get the version number using the Node.js website.
|
|
42
|
-
Limitations: the website structure can change and the json file is relatively large.
|
|
43
|
-
This is only for reference, it is not tested.
|
|
44
|
-
:param get_major: bool, if True, the function will return only the major version number string.
|
|
45
|
-
:return: str.
|
|
46
|
-
"""
|
|
47
|
-
|
|
48
|
-
if by_github_api and _by_nodejs_website:
|
|
49
|
-
raise ValueError("Only one of the arguments can be True.")
|
|
50
|
-
elif not by_github_api and not _by_nodejs_website:
|
|
51
|
-
raise ValueError("At least one of the arguments must be True.")
|
|
52
|
-
|
|
53
|
-
latest_version = ''
|
|
54
|
-
if by_github_api:
|
|
55
|
-
github_wrapper = githubw.GitHubWrapper('nodejs', 'node')
|
|
56
|
-
latest_version = github_wrapper.get_the_latest_release_version_number()
|
|
57
|
-
elif _by_nodejs_website:
|
|
58
|
-
url = "https://nodejs.org/dist/index.json"
|
|
59
|
-
response = requests.get(url)
|
|
60
|
-
versions = response.json()
|
|
61
|
-
latest_version = versions[0]['version'] # Assuming the first one is the latest.
|
|
62
|
-
|
|
63
|
-
if get_major:
|
|
64
|
-
latest_version = latest_version.replace('v', '')
|
|
65
|
-
latest_version = latest_version.split('.')[0]
|
|
66
|
-
|
|
67
|
-
return latest_version
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def install_nodejs_ubuntu(
|
|
71
|
-
install_latest_version: bool = False,
|
|
72
|
-
install_lts: bool = True,
|
|
73
|
-
install_by_version_number: str = None,
|
|
74
|
-
force_install: bool = False
|
|
75
|
-
):
|
|
76
|
-
"""
|
|
77
|
-
The function will install Node.js on Ubuntu.
|
|
78
|
-
|
|
79
|
-
:param install_latest_version: bool, if True, the function will install the latest version of Node.js.
|
|
80
|
-
:param install_lts: bool, if True, the function will install the LTS version of Node.js.
|
|
81
|
-
:param install_by_version_number: str, the version number of Node.js to install.
|
|
82
|
-
:param force_install: bool, if True, the function will install Node.js even if it is already installed.
|
|
83
|
-
|
|
84
|
-
:return:
|
|
85
|
-
"""
|
|
86
|
-
|
|
87
|
-
booleans.check_3_booleans_when_only_1_can_be_true(
|
|
88
|
-
(install_latest_version, 'install_latest_version'),
|
|
89
|
-
(install_lts, 'install_lts'),
|
|
90
|
-
(install_by_version_number, 'install_by_version_number')
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
# Check if Node.js is already installed.
|
|
94
|
-
if is_nodejs_installed():
|
|
95
|
-
if not force_install:
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
# NodeSource is listed as source under official Node.js GitHub repository:
|
|
99
|
-
# https://github.com/nodejs/node?tab=readme-ov-file#current-and-lts-releases
|
|
100
|
-
print_api("Adding NodeSource repository...")
|
|
101
|
-
|
|
102
|
-
# Fetch and execute the NodeSource repository setup script.
|
|
103
|
-
if install_latest_version:
|
|
104
|
-
install_by_version_number: str = get_nodejs_latest_version_number(get_major=True)
|
|
105
|
-
|
|
106
|
-
command: str = ''
|
|
107
|
-
if install_latest_version or install_by_version_number:
|
|
108
|
-
command = f"curl -fsSL https://deb.nodesource.com/setup_{install_by_version_number}.x | sudo -E bash -"
|
|
109
|
-
elif install_lts:
|
|
110
|
-
command = "curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -"
|
|
111
|
-
|
|
112
|
-
_ = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
|
|
113
|
-
|
|
114
|
-
ubuntu_terminal.update_system_packages()
|
|
115
|
-
ubuntu_terminal.install_packages(['nodejs'])
|
|
116
|
-
|
|
117
|
-
# Check if Node.js is installed.
|
|
118
|
-
is_nodejs_installed()
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def install_npm_package_ubuntu(package_name: str, sudo: bool = True):
|
|
122
|
-
"""
|
|
123
|
-
The function will install a npm package on Ubuntu.
|
|
124
|
-
:param package_name: str, the name of the package to install.
|
|
125
|
-
:param sudo: bool, if True, the function will use sudo.
|
|
126
|
-
NPM commands require sudo to install global packages.
|
|
127
|
-
:return:
|
|
128
|
-
"""
|
|
129
|
-
|
|
130
|
-
# Check if Node.js is installed.
|
|
131
|
-
if not is_nodejs_installed():
|
|
132
|
-
return
|
|
133
|
-
|
|
134
|
-
command = f"npm install -g {package_name}"
|
|
135
|
-
|
|
136
|
-
if sudo:
|
|
137
|
-
command = f"sudo {command}"
|
|
138
|
-
|
|
139
|
-
_ = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from atomicshop.process import execute_with_live_output
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def execute_pbtk(pbtk_path: str, file_path: str, target_directory: str) -> None:
|
|
5
|
-
"""
|
|
6
|
-
The function receives file path and target filesystem directory to extract the files.
|
|
7
|
-
|
|
8
|
-
:param pbtk_path: full path to pbtk file.
|
|
9
|
-
:param file_path: full path to binary file.
|
|
10
|
-
:param target_directory: The directory on the filesystem to extract files.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
cmd: str = f'python "{pbtk_path}" "{file_path}" "{target_directory}"'
|
|
14
|
-
print(f'Scanning: {file_path}')
|
|
15
|
-
|
|
16
|
-
output_list = execute_with_live_output(cmd=cmd)
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
from typing import Union
|
|
2
|
-
import shlex
|
|
3
|
-
|
|
4
|
-
import psutil
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def get_process_using_port(port: int) -> Union[dict, None]:
|
|
8
|
-
"""
|
|
9
|
-
Function to find the process using the port.
|
|
10
|
-
:param port: Port number.
|
|
11
|
-
:return: dict['pid', 'name', 'cmdline'] or None.
|
|
12
|
-
"""
|
|
13
|
-
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
|
14
|
-
try:
|
|
15
|
-
connections = proc.connections(kind='inet')
|
|
16
|
-
for conn in connections:
|
|
17
|
-
if conn.laddr.port == port:
|
|
18
|
-
cmdline = proc.info['cmdline']
|
|
19
|
-
if not cmdline:
|
|
20
|
-
cmdline = '<EMPTY: TRY RUNNING AS ADMIN>'
|
|
21
|
-
else:
|
|
22
|
-
cmdline = shlex.join(cmdline)
|
|
23
|
-
return {
|
|
24
|
-
'pid': proc.info['pid'],
|
|
25
|
-
'name': proc.info['name'],
|
|
26
|
-
'cmdline': cmdline
|
|
27
|
-
}
|
|
28
|
-
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
|
29
|
-
pass
|
|
30
|
-
return None
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def get_processes_using_port_list(ports: list) -> Union[dict, None]:
|
|
34
|
-
"""
|
|
35
|
-
Function to find the process using the port.
|
|
36
|
-
:param ports: List of port numbers.
|
|
37
|
-
:return: dict[port: {'pid', 'name', 'cmdline'}] or None.
|
|
38
|
-
"""
|
|
39
|
-
port_process_map = {}
|
|
40
|
-
for port in ports:
|
|
41
|
-
process_info = get_process_using_port(port)
|
|
42
|
-
if process_info:
|
|
43
|
-
port_process_map[port] = process_info
|
|
44
|
-
|
|
45
|
-
return port_process_map
|