Skip to content

Commit

Permalink
Fixes #313: improved otxquery filehandling
Browse files Browse the repository at this point in the history
  • Loading branch information
3c7 committed Jan 22, 2019
1 parent 10ce484 commit 7fcb699
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion analyzers/OTXQuery/otxquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import urllib
import hashlib
import io
from cortexutils.analyzer import Analyzer


Expand Down Expand Up @@ -169,7 +170,14 @@ def run(self):
hashes = self.get_param('attachment.hashes', None)
if hashes is None:
filepath = self.get_param('file', None, 'File is missing')
hash = hashlib.sha256(open(filepath, 'r').read()).hexdigest();
sha256 = hashlib.sha256()
with io.open(filepath, 'rb') as fh:
while True:
data = fh.read(4096)
if not data:
break
sha256.update(data)
hash = sha256.hexdigest()
else:
# find SHA256 hash
hash = next(h for h in hashes if len(h) == 64)
Expand Down

0 comments on commit 7fcb699

Please sign in to comment.