-
Notifications
You must be signed in to change notification settings - Fork 116
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 ScanCapa, Add Tests, Add Elf #277
Changes from 8 commits
74db14a
c27fff9
15a9b2c
f267531
b338df0
e4f6813
1e6a580
f37c93a
d943661
f2e3333
ffee10e
7df787f
63edbd3
d2cae20
47ece62
645a726
6d1848c
bf06b57
d5c642a
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ cryptography==3.4.7 | |
docker==5.0.0 | ||
eml-parser>=1.17 | ||
esprima==4.0.1 | ||
flare-capa==4.0.1 | ||
formulas==1.2.2 | ||
git+https://github.com/jshlbrd/python-entropy.git # v0.11 as of this freeze (package installed as 'entropy') | ||
grpcio-tools==1.42.0 | ||
|
@@ -25,11 +26,11 @@ oletools==0.56.1 | |
opencv-contrib-python==4.6.0.66 | ||
opencv-python==4.6.0.66 | ||
openpyxl==3.0.9 | ||
pefile==2019.4.18 | ||
pefile | ||
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. @ryanohoro Do we want to pin a 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. There's a dependency conflict with flare-capa that pip identified. It was automatically resolved by pip when I removed the pin. I'm not sure which version it picks, though I can go back and check which one pip picked. 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. Added a pin version suggested by pip. |
||
pgpdump3==1.5.2 | ||
py-tlsh==4.7.2 | ||
pycdlib==1.13.0 | ||
pyelftools==0.27 | ||
pyelftools==0.28 | ||
pygments==2.9.0 | ||
pylzma==0.5.0 | ||
pytesseract==0.3.7 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from pathlib import Path | ||
from pytest_unordered import unordered | ||
from unittest import TestCase, mock | ||
|
||
from strelka.scanners.scan_capa import ScanCapa as ScanUnderTest | ||
from strelka.tests import run_test_scan | ||
|
||
|
||
def test_scan_capa_dotnet(mocker): | ||
""" | ||
Pass: Sample event matches output of scanner. | ||
Failure: Unable to load file or sample event fails to match. | ||
""" | ||
|
||
test_scan_event = { | ||
"elapsed": mock.ANY, | ||
"flags": [], | ||
"matches": unordered(["contains PDB path", "compiled to the .NET platform"]), | ||
"mitre_ids": [], | ||
"mitre_techniques": [], | ||
} | ||
|
||
scanner_event = run_test_scan( | ||
mocker=mocker, | ||
scan_class=ScanUnderTest, | ||
fixture_path=Path(__file__).parent / "fixtures/test.exe", | ||
) | ||
|
||
TestCase.maxDiff = None | ||
TestCase().assertDictEqual(test_scan_event, scanner_event) | ||
|
||
|
||
def test_scan_capa_elf(mocker): | ||
""" | ||
Pass: Sample event matches output of scanner. | ||
Failure: Unable to load file or sample event fails to match. | ||
""" | ||
|
||
test_scan_event = { | ||
"elapsed": mock.ANY, | ||
"flags": [], | ||
"matches": [], | ||
"mitre_ids": [], | ||
"mitre_techniques": [], | ||
} | ||
|
||
scanner_event = run_test_scan( | ||
mocker=mocker, | ||
scan_class=ScanUnderTest, | ||
fixture_path=Path(__file__).parent / "fixtures/test.elf", | ||
) | ||
|
||
TestCase.maxDiff = None | ||
TestCase().assertDictEqual(test_scan_event, scanner_event) | ||
|
||
|
||
def test_scan_capa_pe_xor(mocker): | ||
""" | ||
Pass: Sample event matches output of scanner. | ||
Failure: Unable to load file or sample event fails to match. | ||
""" | ||
|
||
test_scan_event = { | ||
"elapsed": mock.ANY, | ||
"flags": [], | ||
"matches": unordered([ | ||
"encode data using XOR", | ||
"contains PDB path", | ||
"contain a resource (.rsrc) section", | ||
"parse PE header", | ||
"contain loop", | ||
]), | ||
"mitre_ids": unordered(["T1129", "T1027"]), | ||
"mitre_techniques": unordered( | ||
[ | ||
"Execution::Shared Modules", | ||
"Defense Evasion::Obfuscated Files or Information", | ||
] | ||
), | ||
} | ||
|
||
scanner_event = run_test_scan( | ||
mocker=mocker, | ||
scan_class=ScanUnderTest, | ||
fixture_path=Path(__file__).parent / "fixtures/test_xor.exe", | ||
) | ||
|
||
TestCase.maxDiff = None | ||
TestCase().assertDictEqual(test_scan_event, scanner_event) |
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.
Are we using
flare-capa
in this PR?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.
Yes. We switched from the binary release (which I think is just a python binary wrapper) to the python module release which is flare-capa in pip. It's still called from subprocess.POpen very similarly though. I was attempting to close #159 and used Method #2 for installation.
It turns out that capa isn't really built to be imported as a module into a script, the main script is a bit of a monolith and it wasn't obvious how to use it the way we want (not documented for that either).