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

#92 Ability to Add Files to Extraction #96

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions malduck/extractor/extract_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def __init__(self, parent: ExtractManager) -> None:
self.globals: Dict[str, Any] = {}
self.parent = parent #: Bound ExtractManager instance
self.family = None #: Matched family
self.files = {}
c3rb3ru5d3d53c marked this conversation as resolved.
Show resolved Hide resolved

def on_extractor_error(
self, exc: Exception, extractor: Extractor, method_name: str
Expand Down
19 changes: 19 additions & 0 deletions malduck/extractor/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inspect
import logging
from typing import List, cast
from hashlib import sha256

from ..procmem import ProcessMemory, ProcessMemoryELF, ProcessMemoryPE

Expand Down Expand Up @@ -329,6 +330,7 @@ def is_it_really_evil(self, p):
yara_rules = () #: Names of Yara rules for which handle_match is called
family = None #: Extracted malware family, automatically added to "family" key for strong extraction methods
overrides = [] #: Family match overrides another match e.g. citadel overrides zeus
files = {}

def __init__(self, parent):
self.parent = parent
Expand All @@ -352,6 +354,15 @@ def push_config(self, config):
"""
return self.parent.push_config(config, self)

def push_file(self, data: bytes, filename=''):
"""
Push file to files object
"""
self.files[sha256(data).hexdigest()] = {
c3rb3ru5d3d53c marked this conversation as resolved.
Show resolved Hide resolved
'filename': filename,
'data': data
}

@property
def matched(self):
"""
Expand All @@ -361,6 +372,14 @@ def matched(self):
"""
return self.parent.family is not None

@property
def collected_files(self):
"""
Shows collected files so far (useful in "final" extractors)
:rtype: dict
"""
return self.parent.files

@property
def collected_config(self):
"""
Expand Down