summaryrefslogtreecommitdiff
path: root/fbin-scanner.py
diff options
context:
space:
mode:
Diffstat (limited to 'fbin-scanner.py')
-rw-r--r--fbin-scanner.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/fbin-scanner.py b/fbin-scanner.py
index 37639c1..3867bac 100644
--- a/fbin-scanner.py
+++ b/fbin-scanner.py
@@ -38,6 +38,7 @@ except OSError:
logger.error('Cannot acquire lock; another process is running')
sys.exit(1)
+
def get_report(dbfile, digest, fileobj):
logger.info('Fetching file report')
params = {
@@ -78,25 +79,27 @@ def get_report(dbfile, digest, fileobj):
return data
logger.warning('Unknown response: %s', data)
+
def main():
- storage = importlib.import_module(current_app.config.get('STORAGE_MODULE', 'fbin.file_storage.filesystem')).Storage(current_app)
- files = deque(db.session.query(File).filter(File.scanned == False).all())
+ storage = importlib.import_module(current_app.config.get('STORAGE_MODULE', 'fbin.file_storage.filesystem')) \
+ .Storage(current_app)
+ files = deque(db.session.query(File).filter(File.scanned == False).all()) # noqa: E712
while len(files):
dbfile = files.pop()
if not dbfile.size:
logger.info('Ignoring file %s/%s due to unknown size', dbfile.filename, dbfile.hash)
continue
- if dbfile.size > 32*10**6:
+ if dbfile.size > 32 * 10**6:
logger.info('Ignoring file %s/%s due to size (%s)', dbfile.filename, dbfile.hash, dbfile.formatted_size)
continue
logger.info('Checking file %s/%s (%s)', dbfile.filename, dbfile.hash, dbfile.formatted_size)
try:
with storage.temp_file(dbfile) as f:
h = hashlib.sha256()
- chunk = f.read(2**10*16)
+ chunk = f.read(2**10 * 16)
while chunk:
h.update(chunk)
- chunk = f.read(2**10*16)
+ chunk = f.read(2**10 * 16)
f.seek(0)
digest = h.hexdigest()
logger.info('SHA-256: %s', digest)
@@ -107,7 +110,7 @@ def main():
db.session.add(dbfile)
db.session.commit()
continue
- except:
+ except Exception:
logger.exception('Failed to get report for %s/%s', dbfile.filename, dbfile.hash)
# Most likely an error from virustotal, so just break here and retry later.
break
@@ -122,6 +125,7 @@ def main():
time.sleep(FILE_DELAY)
logger.info('No more files to scan')
+
app = Flask('scanner')
with app.app_context():
app.config.from_pyfile(args.config_file)