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

Python exception when trying to create a rule that involves counting strings #241

Closed
D4nch3n opened this issue Aug 18, 2020 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@D4nch3n
Copy link

D4nch3n commented Aug 18, 2020

Description

When attempting to count the number of occurrences of a string in the file context, capa crashes with an exception when trying to create a new Feature() object.

Steps to Reproduce

  1. Create a capa rule with the following:
rule:
  meta:
    name: test
    namespace: test
    scope: file
  features:
    - count(string("This program cannot be run in DOS mode")): 1
  1. Run this rule against any PE fle using the -r option

Expected behavior:

Either display whether the file matched the given count rule, or display a message saying that count isn't supported in the file scope.

Actual behavior:

Capa crashes with the following exception:

image

Versions

capa 1.1.0 for linux (running on ubuntu 18.04)

Additional Information

None

@Ana06
Copy link
Member

Ana06 commented Aug 18, 2020

This also fails with function scope:

rule:
  meta:
    name: test
    namespace: test
    scope: function
  features:
    - count(string("This program cannot be run in DOS mode")): 1

And it fails in current master as well.

So, it looks like a bug. Thanks for reporting it @D4nch3n! 👍

@Ana06 Ana06 added the bug Something isn't working label Aug 18, 2020
@williballenthin
Copy link
Collaborator

Looks like this is a bug in parsing the rule, rather than evaluating it.

@williballenthin
Copy link
Collaborator

I think this is because StringFactory has a required argument description but when it is invoked here the description is not provided - hence the TypeError.

I think we can fix this by making StringFactory description a kwarg with default value.

@williballenthin
Copy link
Collaborator

@D4nch3n note: strings don't have surrounding quotes, so "This program..." doesn't do what you think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants