-
Notifications
You must be signed in to change notification settings - Fork 564
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 byte/string extraction and unit tests #1339
Conversation
capa/features/extractors/viv/insn.py
Outdated
@@ -271,7 +271,7 @@ def extract_insn_bytes_features(fh: FunctionHandle, bb, ih: InsnHandle) -> Itera | |||
if capa.features.extractors.helpers.all_zeros(buf): | |||
continue | |||
|
|||
if f.vw.isProbablyString(v): | |||
if f.vw.isProbablyString(v) or f.vw.detectUnicode(v): |
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.
if f.vw.isProbablyString(v) or f.vw.detectUnicode(v): | |
if f.vw.isProbablyString(v) or f.vw.isProbablyUnicode(v): |
tests/fixtures.py
Outdated
# don't extract byte features for obvious strings | ||
("mimikatz", "function=0x40105D", capa.features.common.Bytes("SCardControl".encode("utf-16le")), False), | ||
("mimikatz", "function=0x40105D", capa.features.common.String("SCardControl"), True), | ||
("mimikatz", "function=0x40105D", capa.features.common.Bytes("SCardTransmit".encode("utf-16le")), False), | ||
("mimikatz", "function=0x40105D", capa.features.common.Bytes("ACR > ".encode("utf-16le")), False), | ||
("mimikatz", "function=0x40105D", capa.features.common.String("ACR > "), True), |
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.
👍🏼
if vw.isProbablyString(p) or vw.isProbablyUnicode(p): | ||
# don't deref strings that coincidentally are pointers | ||
return |
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.
e.g. ACS...
which would be 0x430041
(valid pointer) as seen in mimikatz at 0x493E30
tests/fixtures.py
Outdated
("mimikatz", "function=0x401517", capa.features.common.Bytes(binascii.unhexlify("CA3B0E000000F8AF47")), True), | ||
("mimikatz", "function=0x404414", capa.features.common.Bytes(binascii.unhexlify("0180000040EA4700")), True), |
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.
must test True features here!
Tests in IDA succeed. |
Thanks a lot @xusheng6! |
Glad to help! |
This PR fixes some unit tests that wrongly treat strings features as bytes features. It also fixes a bug in the IDA extractor that causes the old unit test to pass.
closes #1336 #1327
ref: #1338
Checklist