-
Notifications
You must be signed in to change notification settings - Fork 566
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
improve and fix various dynamic parts #1809
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,10 @@ | |
import capa.features.extractors.cape.thread | ||
import capa.features.extractors.cape.global_ | ||
import capa.features.extractors.cape.process | ||
from capa.exceptions import UnsupportedFormatError | ||
from capa.exceptions import EmptyReportError, UnsupportedFormatError | ||
from capa.features.common import Feature, Characteristic | ||
from capa.features.address import NO_ADDRESS, Address, AbsoluteVirtualAddress, _NoAddress | ||
from capa.features.extractors.cape.models import CapeReport | ||
from capa.features.extractors.cape.models import Static, CapeReport | ||
from capa.features.extractors.base_extractor import ( | ||
CallHandle, | ||
SampleHashes, | ||
|
@@ -85,10 +85,18 @@ def from_report(cls, report: Dict) -> "CapeExtractor": | |
if cr.info.version not in TESTED_VERSIONS: | ||
logger.warning("CAPE version '%s' not tested/supported yet", cr.info.version) | ||
|
||
# observed in 2.4-CAPE reports from capesandbox.com | ||
if cr.static is None and cr.target.file.pe is not None: | ||
cr.static = Static() | ||
cr.static.pe = cr.target.file.pe | ||
|
||
if cr.static is None: | ||
raise UnsupportedFormatError("CAPE report missing static analysis") | ||
|
||
if cr.static.pe is None: | ||
raise UnsupportedFormatError("CAPE report missing PE analysis") | ||
|
||
if len(cr.behavior.processes) == 0: | ||
raise EmptyReportError("CAPE did not capture any processes") | ||
Comment on lines
+99
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. such empty reports are fairly useless |
||
|
||
return cls(cr) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
from typing import Iterator | ||
|
||
from capa.features.address import DynamicCallAddress | ||
from capa.features.extractors.helpers import is_aw_function | ||
from capa.features.extractors.cape.models import Process | ||
from capa.features.extractors.base_extractor import CallHandle, ThreadHandle, ProcessHandle | ||
|
||
|
@@ -24,5 +25,22 @@ def get_calls(ph: ProcessHandle, th: ThreadHandle) -> Iterator[CallHandle]: | |
if call.thread_id != tid: | ||
continue | ||
|
||
addr = DynamicCallAddress(thread=th.address, id=call_index) | ||
yield CallHandle(address=addr, inner=call) | ||
for symbol in generate_symbols(call.api): | ||
call.api = symbol | ||
|
||
addr = DynamicCallAddress(thread=th.address, id=call_index) | ||
yield CallHandle(address=addr, inner=call) | ||
Comment on lines
+28
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've noticed we run into issues since CAPE reports only list the api (like
This is one way/part of handling this, maybe we can come up with a more generic way. |
||
|
||
|
||
def generate_symbols(symbol: str) -> Iterator[str]: | ||
""" | ||
for a given symbol name, generate variants. | ||
we over-generate features to make matching easier. | ||
""" | ||
|
||
# CreateFileA | ||
yield symbol | ||
|
||
if is_aw_function(symbol): | ||
# CreateFile | ||
yield symbol[:-1] |
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.
noticed that this may store the data instead, maybe there's a better way to handle 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.
please add a comment with a reference to such a report and CAPE version.
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.
Do we want to add all/many/few reports to capa testfiles?
I'm pulling down sandbox data for all our current testfile EXEs and DLLs.
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.
i think it would be good to have a fair collection, but not necessarily one for every sample.
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.
adding a few initially here: mandiant/capa-testfiles#217