Skip to content

Commit 2d1f872

Browse files
Fix encoding on file reads, improve robustness, and minor typos (#2411)
1 parent 76c7edb commit 2d1f872

17 files changed

Lines changed: 36 additions & 24 deletions

‎artemis/modules/admin_panel_login_bruter.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,23 @@ def read_file(file: IO[str]) -> List[str]:
2626

2727
COMMON_FAILURE_MESSAGES: List[str]
2828
with open(
29-
os.path.join(os.path.dirname(__file__), "data", "admin_panel_login_bruter", "common_failure_messages.txt")
29+
os.path.join(os.path.dirname(__file__), "data", "admin_panel_login_bruter", "common_failure_messages.txt"),
30+
encoding="utf-8",
3031
) as f:
3132
COMMON_FAILURE_MESSAGES = read_file(f)
3233

3334
LOGOUT_MESSAGES: List[str]
34-
with open(os.path.join(os.path.dirname(__file__), "data", "admin_panel_login_bruter", "logout_messages.txt")) as f:
35+
with open(
36+
os.path.join(os.path.dirname(__file__), "data", "admin_panel_login_bruter", "logout_messages.txt"),
37+
encoding="utf-8",
38+
) as f:
3539
LOGOUT_MESSAGES = read_file(f)
3640

3741
COMMON_LOGIN_PATHS: List[str]
38-
with open(os.path.join(os.path.dirname(__file__), "data", "admin_panel_login_bruter", "common_login_paths.txt")) as f:
42+
with open(
43+
os.path.join(os.path.dirname(__file__), "data", "admin_panel_login_bruter", "common_login_paths.txt"),
44+
encoding="utf-8",
45+
) as f:
3946
COMMON_LOGIN_PATHS = read_file(f)
4047

4148

‎artemis/modules/api_scanner.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def scan(self, target_api_specification: str) -> Dict[str, Any]:
9999

100100
subprocess.call(offat_cmd)
101101

102-
with open(output_file) as f:
102+
with open(output_file, encoding="utf-8") as f:
103103
file_contents = f.read()
104104

105105
report: Dict[str, Any] = json.loads(file_contents)

‎artemis/modules/base/base_newer_version_comparer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs): # type: ignore
2121
)
2222

2323
endoflife_data_path = Path(self.endoflife_data_folder) / "products" / (self.software_name + ".md")
24-
with open(endoflife_data_path, "r") as f:
24+
with open(endoflife_data_path, "r", encoding="utf-8") as f:
2525
self.endoflife_data = next(yaml.load_all(f, yaml.SafeLoader))
2626

2727
def _parse_version(self, version: str) -> semver.VersionInfo:

‎artemis/modules/bruter.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def read_paths_from_file(file: IO[str]) -> List[str]:
3333
)
3434

3535
for file_name in os.listdir(CHOSEN_BRUTER_LISTS_PATH):
36-
with open(os.path.join(CHOSEN_BRUTER_LISTS_PATH, file_name)) as f:
36+
with open(os.path.join(CHOSEN_BRUTER_LISTS_PATH, file_name), encoding="utf-8") as f:
3737
for item in read_paths_from_file(f):
3838
FILENAMES_TO_SCAN.add(item)
3939

‎artemis/modules/classifier.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def get_ip_prefixes_for_asn(asn: str) -> List[str]:
3434
raise RIPEAccessException(f"Error connecting to RIPEstat API.\nASN: {asn}\nError code: {response.status_code}")
3535
except Exception as err:
3636
raise RIPEAccessException(f"Error connecting to RIPEstat API.\nASN: {asn}\nError: {err}")
37-
return None
3837

3938

4039
@load_risk_class.load_risk_class(load_risk_class.LoadRiskClass.LOW)

‎artemis/modules/data/api_scanner_data.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from os.path import dirname
22
from typing import Dict, List
33

4-
with open(f"{dirname(__file__)}/swagger.txt", "r") as f:
4+
with open(f"{dirname(__file__)}/swagger.txt", "r", encoding="utf-8") as f:
55
COMMON_SPEC_PATHS: List[str] = f.read().splitlines()
66
COMMON_SPEC_PATHS = [payload.strip() for payload in COMMON_SPEC_PATHS if not payload.startswith("#")]
77

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from os.path import dirname
22

3-
with open(f"{dirname(__file__)}/lfi_detector_payloads.txt", "r") as f:
3+
with open(f"{dirname(__file__)}/lfi_detector_payloads.txt", "r", encoding="utf-8") as f:
44
lines = f.read().splitlines()
55
LFI_PAYLOADS = [line.strip() for line in lines if not line.startswith("#")]
66

7-
with open(f"{dirname(__file__)}/rce_payloads.txt", "r") as f:
7+
with open(f"{dirname(__file__)}/rce_payloads.txt", "r", encoding="utf-8") as f:
88
lines = f.read().splitlines()
99
RCE_PAYLOADS = [line.strip() for line in lines if not line.startswith("#")]

‎artemis/modules/domain_expiration_scanner.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DomainExpirationScanner(ArtemisBase):
3030

3131
def run(self, current_task: Task) -> None:
3232
# If the task originated from an IP-based one, that means, that we are scanning a domain that came from reverse DNS search.
33-
# Close expiry date of sych domains is not actually related to scanned IP ranges, therefore let's skip it.
33+
# Close expiry date of such domains is not actually related to scanned IP ranges, therefore let's skip it.
3434
if has_ip_range(current_task):
3535
return
3636

‎artemis/modules/humble.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
9292

9393
def run(self, current_task: Task) -> None:
9494
if Config.Miscellaneous.CUSTOM_USER_AGENT:
95-
with open("/humble/additional/user_agents.txt", "w") as f:
95+
with open("/humble/additional/user_agents.txt", "w", encoding="utf-8") as f:
9696
f.write(f"1.- {Config.Miscellaneous.CUSTOM_USER_AGENT}\n")
9797
else:
9898
# Reset back to the original content

‎artemis/modules/joomla_extensions.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
import json
33
import subprocess
4+
import sys
45

56
from karton.core import Task
67

@@ -25,7 +26,7 @@ def run(self, current_task: Task) -> None:
2526
url = current_task.get_payload("url")
2627

2728
command = [
28-
"python",
29+
sys.executable,
2930
"/joomla-scanner/myscanner.py",
3031
"-u",
3132
url,

0 commit comments

Comments
 (0)