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

smda: fix negative number extraction #851

Merged
merged 4 commits into from
Jan 3, 2022

Conversation

kn0wl3dge
Copy link
Contributor

SMDA extractor is extracting negative Number features as described in #430.

This is not compliant with the rule format described in capa documentation:

Note that capa treats all numbers as unsigned values. A negative number is not a valid feature value. To match a negative number you may specify its two's complement representation. For example, 0xFFFFFFF0 (-2) in a 32-bit file.
https://github.com/fireeye/capa-rules/blob/master/doc/format.md#number

This PR adds the following fixtures:

  • number(0x0): to check feature extraction for null number
  • number(0xFFFFFFFF): to check feature extraction for -1 number
  • number(0xFFFFFFF0): to check feature extraction for another negative number (-0x10 in this case)

The function extract_insn_number_features now converts the parsed smda number operands in its two's complement representation.

I also edited the show-features.py script to be able to compare the feature extraction of smda and vivisect. I think that it could be useful and it does not seem to cause any issue.

The documentation is not updated since I am just fixing a simple issue.

closes #430

Checklist

  • No CHANGELOG update needed
  • No new tests needed
  • No documentation update needed

Add fixtures to validate the following number features:
- number(0x0): to check feature extraction for null number
- number(0xFFFFFFFF): to check feature extraction for -1 number
- number(0xFFFFFFF0): to check feature extraction for negative number (-0x10 in this case)
SmdaInstruction operands are python `str` objects. SMDA number operands are signed integers.
This commit adds a converter to the SMDA number extractor.
The goal is to convert any signed number to the two’s complement representation with the correct bitness.
@@ -86,7 +86,7 @@ def main(argv=None):
argv = sys.argv[1:]

parser = argparse.ArgumentParser(description="Show the features that capa extracts from the given sample")
capa.main.install_common_args(parser, wanted={"format", "sample", "signatures"})
capa.main.install_common_args(parser, wanted={"format", "sample", "signatures", "backend"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, thanks

Comment on lines +416 to +426
("mimikatz", "function=0x401000", capa.features.insn.Number(0x0), True),
# insn/number: stack adjustments
("mimikatz", "function=0x40105D", capa.features.insn.Number(0xC), False),
("mimikatz", "function=0x40105D", capa.features.insn.Number(0x10), False),
# insn/number: bitness flavors
("mimikatz", "function=0x40105D", capa.features.insn.Number(0xFF), True),
("mimikatz", "function=0x40105D", capa.features.insn.Number(0xFF, bitness=BITNESS_X32), True),
("mimikatz", "function=0x40105D", capa.features.insn.Number(0xFF, bitness=BITNESS_X64), False),
# insn/number: negative
("mimikatz", "function=0x401553", capa.features.insn.Number(0xFFFFFFFF), True),
("mimikatz", "function=0x43e543", capa.features.insn.Number(0xFFFFFFF0), True),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding tests! this makes me confident that the fixes work as intended

Copy link
Collaborator

@williballenthin williballenthin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@williballenthin williballenthin merged commit 01b694b into mandiant:master Jan 3, 2022
@kn0wl3dge kn0wl3dge deleted the fix/430 branch January 3, 2022 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

smda: extracting negative Number features
2 participants