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
Create capa2yara.py #561
Create capa2yara.py #561
Conversation
btw, it's a weekend project and the code quality is rather ermmm average. it's totally fine if you take this as a POC and rewrite it properly from your codebase (if we find enough use for the result ;) |
I'm ok with merging once the code style matches (unless someone else objects, of course), for that please run:
|
isort --profile black --length-sort --line-width 120 black -l 120
Thank you very much! |
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 this is a great script to include in the capa repository. As it gets some use (and any bug fixes) we can bring minor characteristics (line length, globals, etc.) into line with the rest of the capa code; however, in the meantime, its much more valuable to get this into the hands of others.
Thanks @ruppde for the hard work here! I hope you'll continue to contribute as you update the script, have new ideas, etc.
today = str(datetime.date.today()) | ||
|
||
# create unique variable names for each rule in case somebody wants to move/copy stuff around later | ||
var_names = ["".join(letters) for letters in itertools.product(string.ascii_lowercase, repeat=3)] |
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.
alternatively, rather than realizing the generator into a concrete list, could use just the generator, and call next(var_names)
when fetching the next term.
upside is that there is less upfront computation and memory overhead.
this is just an FYI, no need to change here.
regex = re.sub(r"(?<!\\)/", r"\/", regex) | ||
|
||
# capa uses python regex which accepts /reg(|.exe)/ but yaras regex engine doesn't not => fix it | ||
# /reg(|.exe)/ => /reg(.exe)?/ |
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.
thanks for the explanations here, they're really helpful.
Co-authored-by: Willi Ballenthin <willi.ballenthin@gmail.com>
@williballenthin @mr-tz sure & thanks for capa and the rules! |
Nice idea @ruppde! btw, changelog entry is missing. I'll add it! (There will be soon a GitHub Action to avoid we forget this: #457 (comment)) |
@Ana06 no, I can't get credit for the idea, someone else wrote "capa rules are a mixture of the OpenIOC, Yara, and YAML formats." ;) |
see mandiant/capa-rules#384