-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This code is UNTESTED!
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import hashlib | ||
import os | ||
import vt | ||
|
||
|
||
def hash_file(file_path): | ||
# make a hash object | ||
h = hashlib.sha1() | ||
|
||
# open file for reading in binary mode | ||
with open(file_path,'rb') as file: | ||
# loop till the end of the file | ||
chunk = 0 | ||
while chunk != b'': | ||
# read only 1024 bytes at a time | ||
chunk = file.read(1024) | ||
h.update(chunk) | ||
|
||
# return the hex representation of digest | ||
return h.hexdigest() | ||
|
||
def scan_file(file_path): | ||
VT_API_KEY = os.environ.get("VT_API_KEY", default="") | ||
client = vt.Client(apikey=VT_API_KEY, agent='ACMAS') | ||
# file_hash = hash_file(file_path) | ||
file = client.get_object(file_hash) | ||
if file.last_analysis_stats['malicious'] > 0: | ||
return 'malicious' | ||
elif file.last_analysis_stats['suspicious'] > 0: | ||
return 'suspicious' | ||
elif file.last_analysis_stats['harmless'] > 0: | ||
with open(file_path, 'rb') as f: | ||
# Scan the file and block until it is scanned | ||
analysis = client.scan_file(f, wait_for_completion=True) | ||
|
||
# try: | ||
# analysis = client.scan_file(file_path, wait_for_completion=True) | ||
# return analysis | ||
# except vt.APIError as e: | ||
# print(e) | ||
# return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ django-dbbackup==4.0.2 | |
django_components | ||
|
||
psycopg2-binary==2.9.7 | ||
gunicorn==20.1.0 | ||
gunicorn==20.1.0 | ||
vt-py==0.17.5 |