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

yara.Error: could not map file into memory #49

Closed
austinbyers opened this issue Aug 18, 2017 · 3 comments
Closed

yara.Error: could not map file into memory #49

austinbyers opened this issue Aug 18, 2017 · 3 comments
Labels
Milestone

Comments

@austinbyers
Copy link
Collaborator

austinbyers commented Aug 18, 2017

Some users are seeing the following error in the analyzer Lambda logs:

could not map file "/tmp/binaryalert_UUID" into memory: Error
Traceback (most recent call last):
File "/var/task/main.py", line 76, in analyze_lambda_handler
with binary_info.BinaryInfo(os.environ['S3_BUCKET_NAME'], s3_key, ANALYZER) as binary:
File "/var/task/binary_info.py", line 57, in __enter__
self.download_path, original_target_path=self.observed_path)
File "/var/task/yara_analyzer.py", line 52, in analyze
return self._rules.match(target_file, externals=self._yara_variables(original_target_path))
yara.Error: could not map file "/tmp/binaryalert_UUID" into memory

I have not been able to reproduce this locally, even with 20,000 YARA rules scanning a 10G file. Some theories:

  • The Lambda analyzers need more memory
  • Lambda handles virtual memory differently; YARA consumes tons of virtual memory even though the actual memory usage is fairly efficient
@austinbyers
Copy link
Collaborator Author

I've confirmed that this error can happen even with the max Lambda memory allocation (1.5 GB) and with any size input file. Perhaps the number / size of the YARA rules are to blame?

@austinbyers
Copy link
Collaborator Author

austinbyers commented Aug 19, 2017

I think I've tracked it down: a recent commit to Neo23x0/signature-base adds a new rule which includes a pe.imphash condition.

The YARA rules successfully compile and load in Lambda, but they fail with the memory mapping error when matching against most Windows binaries. My best guess is that this fails because of #30 (hash module not yet supported in BinaryAlert)

So the solution for now is to disable all rules which use pe.imphash. I will add a check to enforce this with unit tests since it is so hard to debug.

@austinbyers
Copy link
Collaborator Author

An easy way to disable the relevant rules files is to rename rules_file.yar to rules_file.yar.DISABLED. BinaryAlert only includes files ending in .yar or .yara, so these files will be excluded from the next deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant