Add PyArmor obfuscation detection heuristic#672
Open
stevenelliottjr wants to merge 1 commit intoDataDog:mainfrom
Open
Add PyArmor obfuscation detection heuristic#672stevenelliottjr wants to merge 1 commit intoDataDog:mainfrom
stevenelliottjr wants to merge 1 commit intoDataDog:mainfrom
Conversation
Adds a new Semgrep rule to detect packages that use PyArmor obfuscation, which is commonly used by malware to hide malicious code. Detects the following PyArmor patterns: - __pyarmor__() bootstrap code - pytransform runtime imports (PyArmor < 8.0) - pyarmor_runtime package imports (PyArmor >= 8.0) - __armor_enter__/__armor_exit__ bytecode markers - check_armored() and @assert_armored verification functions Closes DataDog#533
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new Semgrep rule to detect malicious packages that use PyArmor obfuscation, which is a common technique used by malware to hide malicious code from static analysis.
pyarmor.ymlrule that detects PyArmor obfuscation patternsDetection Coverage
The rule detects the following PyArmor patterns:
Bootstrap Code:
__pyarmor__(__name__, __file__, b'...')- main obfuscation wrapperLegacy PyTransform (PyArmor < 8.0):
from pytransform import pyarmor_runtimeimport pytransformpyarmor_runtime()callsModern Runtime (PyArmor >= 8.0):
from pyarmor_runtime import __pyarmor__from pyarmor_runtime_XXXXXX import __pyarmor__Bytecode Markers:
__armor_enter__/__armor_exit____pyarmor_enter__/__pyarmor_exit__Verification Functions:
check_armored()@assert_armored()Example Detection
Test Plan
pytest tests/core/test_sourcecode_analyzer.py) - all passCloses #533