-
Notifications
You must be signed in to change notification settings - Fork 0
/
virus-scanner.py
81 lines (73 loc) · 3.19 KB
/
virus-scanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import hashlib
import os
from pathlib import Path
import pyfiglet
from colorama import Fore, init
from virustotal_python import Virustotal
init(convert=True)
try:
with open('VirusTotal_APIKey.txt') as f:
data = f.readlines()
f.close()
APIKey = ''.join(data)
except:
createfile = open("VirusTotal_APIKey.txt", "a")
print(Fore.LIGHTYELLOW_EX, "[Warning] Enter your VirusTotal API Key \n")
APIKeyInput = input("")
createfile.truncate(0)
createfile.writelines(APIKeyInput)
createfile.close()
print(Fore.WHITE)
os.system('cls' if os.name == 'nt' else 'clear')
while(1):
ascii_banner = pyfiglet.figlet_format("VIRUS SCANNER BY AKHIL BINU")
print(Fore.CYAN + ascii_banner)
print(Fore.MAGENTA, "[Antivirus Scanner] - Created by Akhil Binu \n \n")
print(Fore.WHITE)
BUF_SIZE = 65536
sha1 = hashlib.sha1()
sha256 = hashlib.sha256()
print("Enter path of a file to scan")
FilePath = input("")
print("\n")
with open(FilePath, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
sha1.update(data)
sha256.update(data)
SHA1_of_file = sha1.hexdigest()
SHA256_of_file = sha256.hexdigest()
print("File Name: ", Path(FilePath).stem)
print("SHA1: ", SHA1_of_file)
print("SHA256: ", SHA256_of_file)
try:
with Virustotal(API_KEY=APIKey, API_VERSION="v3") as vtotal:
resp = vtotal.request(f"files/{SHA256_of_file}")
serverresponse = str(resp.data)
print("Scan Results: \n")
if((serverresponse.count("'category': 'malicious'")) >= 5):
print(Fore.LIGHTRED_EX, "This file is flagged by ", (serverresponse.count(
"'category': 'malicious'")), " antivirus as malicious")
elif((serverresponse.count("'category': 'malicious'")) >= 2):
print(Fore.LIGHTYELLOW_EX, "This file is flagged by ", (serverresponse.count(
"'category': 'malicious'")), " antivirus as malicious")
elif((serverresponse.count("'category': 'malicious'")) == 1):
print(Fore.LIGHTWHITE_EX, "This file is flagged by ", (serverresponse.count(
"'category': 'malicious'")), " antivirus as malicious")
else:
print(Fore.LIGHTGREEN_EX, "This file is flagged by ", (serverresponse.count(
"'category': 'malicious'")), " antivirus as malicious")
print(Fore.WHITE)
except:
print("File not found in VirusTotal, sending it for analysis...")
with Virustotal(API_KEY=APIKey, API_VERSION="v3") as vtotal:
FilePathConverted = {"file": (os.path.basename(FilePath), open(
os.path.abspath(FilePath).replace("\\\\", "\\"), "rb"))}
resp = vtotal.request(
"files", files=FilePathConverted, method="POST")
serverresponse = str(resp.data)
print("File successfully sent for analysis, re-scan it to get results")
wait = input("Press any key to continue \n")
os.system('cls' if os.name == 'nt' else 'clear')