Skip to content
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

fix: demo extractor updated yara #62

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions demo_extractors/complex/complex.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from io import BytesIO
from typing import Dict, List, Optional
from typing import List, Optional

from maco import extractor, model, yara

from . import complex_utils
from complex import complex_utils


class Complex(extractor.Extractor):
Expand Down Expand Up @@ -50,7 +50,7 @@ def run(self, stream: BytesIO, matches: List[yara.Match]) -> Optional[model.Extr
other = complex_utils.getdata()["result"]
self.logger.debug("got data from lib")
# example - accessing yara strings
strings = {y[2].decode("utf8") for x in matches for y in x.strings}
strings = sorted({z.plaintext().decode("utf8") for x in matches for y in x.strings for z in y.instances})
self.logger.debug(f"{strings=}")
# construct model of results
tmp = model.ExtractorModel(family=self.family)
Expand Down
6 changes: 6 additions & 0 deletions tests/data/trigger_complex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
file to trigger demo extractors

self_trigger

Complex
Paradise
60 changes: 60 additions & 0 deletions tests/test_demo_extractors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import unittest

from maco import cli
from maco.collector import Collector


class TestDemoExtractors(unittest.TestCase):
def test_complex(self):
path_file = os.path.normpath(
os.path.join(__file__, "../data/trigger_complex.txt")
)
collector = Collector(os.path.join(__file__, "../../demo_extractors"))
self.assertEqual(
set(collector.extractors.keys()),
{
"Elfy",
"Nothing",
"Complex",
"LimitOther",
},
)

with open(path_file, "rb") as stream:
ret = cli.process_file(
collector,
path_file,
stream,
pretty=True,
force=False,
include_base64=False,
)
self.assertEqual(
ret,
{
"Complex": {
"family": "complex",
"version": "5",
"decoded_strings": sorted(["Paradise", "Complex"]),
"binaries": [
{
"datatype": "payload",
"encryption": {"algorithm": "something"},
"sha256": "1307990e6ba5ca145eb35e99182a9bec46531bc54ddf656a602c780fa0240dee",
"size": 9,
"hex_sample": "736F6D652064617461",
}
],
"http": [
{
"protocol": "https",
"hostname": "blarg5.com",
"path": "/malz/64",
"usage": "c2",
}
],
"encryption": [{"algorithm": "sha256"}],
}
},
)