Skip to content

Commit d555c54

Browse files
committed
refactor(heuristics): remove Unknown Organization heuristic
Signed-off-by: Amine <amine.raouane@enim.ac.ma>
1 parent ae021e1 commit d555c54

File tree

7 files changed

+11
-318
lines changed

7 files changed

+11
-318
lines changed

src/macaron/malware_analyzer/pypi_heuristics/heuristics.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ class Heuristics(str, Enum):
4343
#: Indicates that the package source code contains suspicious code patterns.
4444
SUSPICIOUS_PATTERNS = "suspicious_patterns"
4545

46-
#: Indicates that the package is associated with an unknown organization.
47-
UNKNOWN_ORGANIZATION = "unknown_organization"
48-
4946
#: Indicates that the package has minimal content.
5047
MINIMAL_CONTENT = "minimal_content"
5148

src/macaron/malware_analyzer/pypi_heuristics/metadata/minimal_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class MinimalContentAnalyzer(BaseHeuristicAnalyzer):
1919
"""Check whether the package has minimal content."""
2020

21-
FILES_THRESHOLD = 3
21+
FILES_THRESHOLD = 50
2222

2323
def __init__(self) -> None:
2424
super().__init__(

src/macaron/malware_analyzer/pypi_heuristics/metadata/unknown_organization.py

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/macaron/resources/trusted_organizations.txt

Lines changed: 0 additions & 119 deletions
This file was deleted.

src/macaron/slsa_analyzer/checks/detect_malicious_metadata_check.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from macaron.malware_analyzer.pypi_heuristics.metadata.source_code_repo import SourceCodeRepoAnalyzer
2727
from macaron.malware_analyzer.pypi_heuristics.metadata.typosquatting_presence import TyposquattingPresenceAnalyzer
2828
from macaron.malware_analyzer.pypi_heuristics.metadata.unchanged_release import UnchangedReleaseAnalyzer
29-
from macaron.malware_analyzer.pypi_heuristics.metadata.unknown_organization import UnknownOrganizationAnalyzer
3029
from macaron.malware_analyzer.pypi_heuristics.metadata.unsecure_description import UnsecureDescriptionAnalyzer
3130
from macaron.malware_analyzer.pypi_heuristics.metadata.wheel_absence import WheelAbsenceAnalyzer
3231
from macaron.malware_analyzer.pypi_heuristics.sourcecode.pypi_sourcecode_analyzer import PyPISourcecodeAnalyzer
@@ -361,7 +360,6 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
361360
WheelAbsenceAnalyzer,
362361
AnomalousVersionAnalyzer,
363362
TyposquattingPresenceAnalyzer,
364-
UnknownOrganizationAnalyzer,
365363
UnsecureDescriptionAnalyzer,
366364
MinimalContentAnalyzer,
367365
]
@@ -417,6 +415,12 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
417415
{Confidence.HIGH.value}::trigger(malware_high_confidence_4) :-
418416
quickUndetailed, forceSetup, failed({Heuristics.TYPOSQUATTING_PRESENCE.value}).
419417
418+
% Package released with dependency confusion .
419+
{Confidence.HIGH.value}::trigger(malware_high_confidence_5) :-
420+
passed({Heuristics.MINIMAL_CONTENT.value}),
421+
failed({Heuristics.ANOMALOUS_VERSION.value}),
422+
failed({Heuristics.UNSECURE_DESCRIPTION.value}).
423+
420424
% Package released recently with little detail, with multiple releases as a trust marker, but frequent and with
421425
% the same code.
422426
{Confidence.MEDIUM.value}::trigger(malware_medium_confidence_1) :-
@@ -430,14 +434,6 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
430434
quickUndetailed,
431435
failed({Heuristics.ONE_RELEASE.value}),
432436
failed({Heuristics.ANOMALOUS_VERSION.value}),
433-
failed({Heuristics.UNKNOWN_ORGANIZATION.value}),
434-
failed({Heuristics.UNSECURE_DESCRIPTION.value}).
435-
436-
% Package released with dependency confusion .
437-
{Confidence.HIGH.value}::trigger(malware_high_confidence_5) :-
438-
passed({Heuristics.MINIMAL_CONTENT.value}),
439-
failed({Heuristics.ANOMALOUS_VERSION.value}),
440-
failed({Heuristics.UNKNOWN_ORGANIZATION.value}),
441437
failed({Heuristics.UNSECURE_DESCRIPTION.value}).
442438
443439
% ----- Evaluation -----

tests/malware_analyzer/pypi/test_minimal_content.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_analyze_sufficient_files_pass(analyzer: MinimalContentAnalyzer, pypi_pa
2323
pypi_package_json.download_sourcecode.return_value = True
2424
pypi_package_json.package_sourcecode_path = "/fake/path"
2525
with patch("os.walk") as mock_walk:
26-
mock_walk.return_value = [("root", [], ["file1.py", "file2.py", "file3.py"])]
26+
mock_walk.return_value = [("root", [], [f"file{i}.py" for i in range(60)])]
2727
result, info = analyzer.analyze(pypi_package_json)
2828

2929
assert result == HeuristicResult.PASS
@@ -36,7 +36,7 @@ def test_analyze_exactly_threshold_files_pass(analyzer: MinimalContentAnalyzer,
3636
pypi_package_json.download_sourcecode.return_value = True
3737
pypi_package_json.package_sourcecode_path = "/fake/path"
3838
with patch("os.walk") as mock_walk:
39-
mock_walk.return_value = [("root", [], ["file1.py", "file2.py", "file3.py"])]
39+
mock_walk.return_value = [("root", [], [f"file{i}.py" for i in range(50)])]
4040
result, info = analyzer.analyze(pypi_package_json)
4141

4242
assert result == HeuristicResult.PASS
@@ -84,8 +84,8 @@ def test_analyze_download_failed_raises_error(analyzer: MinimalContentAnalyzer,
8484
(0, HeuristicResult.FAIL),
8585
(1, HeuristicResult.FAIL),
8686
(2, HeuristicResult.FAIL),
87-
(3, HeuristicResult.PASS),
88-
(10, HeuristicResult.PASS),
87+
(55, HeuristicResult.PASS),
88+
(70, HeuristicResult.PASS),
8989
],
9090
)
9191
def test_analyze_various_file_counts(

tests/malware_analyzer/pypi/test_unknown_organization.py

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)