-
Notifications
You must be signed in to change notification settings - Fork 29
feat(malware-check): add whitespace check to detect excessive spacing and invisible characters #1086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/macaron/malware_analyzer/pypi_heuristics/sourcecode/white_spaces.py
Outdated
Show resolved
Hide resolved
…d invisible characters Signed-off-by: Amine <[email protected]>
Signed-off-by: Amine <[email protected]>
db0e35c
to
6978bd7
Compare
src/macaron/slsa_analyzer/checks/detect_malicious_metadata_check.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Ben Selwyn-Smith <[email protected]>
Signed-off-by: Amine <[email protected]>
…ackages (oracle#965) Include support for using Semgrep for analysis of source code to detect malicious code patterns, specified using Semgrep's YAML files. Signed-off-by: Carl Flottmann <[email protected]>
This PR allows Macaron to discover GitHub attestation. To retrieve these attestations, the SHA256 hash of the related artefact is required. Hashes are computed from local artefact files if available, or from downloaded ones otherwise. Signed-off-by: Ben Selwyn-Smith <[email protected]>
…acle#1096) This PR replaces the Go shared library previously used via C-bindings in Python with a standalone binary for the cuevalidator component. The binary can now be invoked as a subprocess, simplifying integration and improving portability. Signed-off-by: behnazh-w <[email protected]>
…e. (oracle#1102) The detail info containing inspector links now contains links as keys regardless of whether they are reachable, and includes a boolean value for reachability. Signed-off-by: Carl Flottmann <[email protected]>
…torial (oracle#1101) Signed-off-by: Carl Flottmann <[email protected]>
oracle#1097) Signed-off-by: Amine <[email protected]>
…d invisible characters Signed-off-by: Amine <[email protected]>
Signed-off-by: Amine <[email protected]>
Signed-off-by: Amine <[email protected]>
Signed-off-by: Amine <[email protected]>
tests/malware_analyzer/pypi/resources/sourcecode_samples/obfuscation/inline_imports.py
Show resolved
Hide resolved
languages: | ||
- python | ||
severity: WARNING | ||
pattern-regex: ' {50,}[^ ]+' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So with the previous iteration of this where this was written as a heuristic, there was a list of "invisible" characters that was used to match whitespace. This regex appears to use " "
as the whitespace matcher. Would this miss some of those other invisible characters, or does it capture all whitespace in general? I know that /s
in regex matches whitespace, how does it differ from this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I tried to extend it to also include Unicode invisibles (like \u200B, \uFEFF, \u00A0, etc.), it didn’t behave reliably when passed through the expected_results.json.
To solve this, I propose a preprocessing step:
- Replace all known invisible characters with a regular space before running the regex check.
…tion threshold Signed-off-by: Amine <[email protected]>
Summary
This PR adds a new heuristic that analyzes code to detect suspicious use of excessive spaces and invisible characters. It checks whether the amount of spacing and invisible Unicode characters exceeds a defined threshold.
Description of changes
WhiteSpaces
heuristic in a new Python module.heuristics.py
file.WhiteSpacesAnalyzer
heuristic.detect_malicious_metadata_check.py
to integrate and execute the new heuristic logic during analysis.Related issues
None
Checklist
verified
label should appear next to all of your commits on GitHub.