-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(plugins/crypto_hints)!: Use AnalysisPluginV0
- Loading branch information
Showing
3 changed files
with
48 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
from analysis.YaraPluginBase import YaraBasePlugin | ||
import io | ||
|
||
import pydantic | ||
import typing | ||
|
||
class AnalysisPlugin(YaraBasePlugin): | ||
NAME = 'crypto_hints' | ||
DESCRIPTION = 'find indicators of specific crypto algorithms' | ||
DEPENDENCIES = [] # noqa: RUF012 | ||
VERSION = '0.1.1' | ||
FILE = __file__ | ||
from analysis.plugin import addons, compat | ||
from analysis.plugin import AnalysisPluginV0 | ||
|
||
|
||
class AnalysisPlugin(AnalysisPluginV0, compat.AnalysisBasePluginAdapterMixin): | ||
class Schema(pydantic.BaseModel): | ||
matches: typing.List[dict] | ||
|
||
def __init__(self): | ||
metadata = AnalysisPluginV0.MetaData( | ||
name='crypto_hints', | ||
description='find indicators of specific crypto algorithms', | ||
version='0.2.0', | ||
Schema=AnalysisPlugin.Schema, | ||
) | ||
super().__init__(metadata=metadata) | ||
|
||
self._yara = addons.Yara(plugin=self) | ||
|
||
def summarize(self, result): | ||
return [match['rule'] for match in result.matches] | ||
|
||
def analyze(self, file_handle: io.FileIO, virtual_file_path: str, analyses: dict) -> Schema: | ||
del virtual_file_path, analyses | ||
return AnalysisPlugin.Schema( | ||
matches=[compat.yara_match_to_dict(m) for m in self._yara.match(file_handle)], | ||
) |
This file contains 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
This file contains 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