-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell91.py
305 lines (248 loc) · 15 KB
/
shell91.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
from PyQt6 import QtCore, QtGui, QtWidgets
from tkinter import filedialog
from PyQt6.QtWidgets import QFileDialog
from PyQt6.QtCore import (Qt, QTimer)
import hashlib
import requests
import datetime
import time
import json
import os
filenm = ''
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(884, 499)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setStyleSheet("background-color: qlineargradient(spread:pad, x1:0, y1:1, x2:1, y2:0, stop:0 rgba(142, 200, 195, 255), stop:1 rgba(255, 255, 255, 255));\n"
"background-color: rgb(32, 41, 64);")
self.centralwidget.setObjectName("centralwidget")
self.QuickScanB = QtWidgets.QPushButton(self.centralwidget,clicked = lambda:self.quickscan())
self.QuickScanB.setGeometry(QtCore.QRect(50, 270, 191, 101))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.QuickScanB.setFont(font)
self.QuickScanB.setStyleSheet("background-color: rgb(253, 167, 255);\n"
"border-radius : 15;")
self.QuickScanB.setObjectName("QuickScanB")
self.DeepScanB = QtWidgets.QPushButton(self.centralwidget,clicked = lambda:self.deepscan())
self.DeepScanB.setGeometry(QtCore.QRect(340, 270, 191, 101))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.DeepScanB.setFont(font)
self.DeepScanB.setStyleSheet("background-color: rgb(253, 167, 255);\n"
"border-radius : 15;")
self.DeepScanB.setFlat(False)
self.DeepScanB.setObjectName("DeepScanB")
self.ViewLogsB = QtWidgets.QPushButton(self.centralwidget,clicked = lambda:self.viewlogs())
self.ViewLogsB.setGeometry(QtCore.QRect(620, 270, 191, 101))
font = QtGui.QFont()
font.setPointSize(12)
font.setBold(True)
font.setWeight(75)
self.ViewLogsB.setFont(font)
self.ViewLogsB.setStyleSheet("background-color: rgb(253, 167, 255);\n"
"border-radius : 15;")
self.ViewLogsB.setObjectName("ViewLogsB")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(50, 30, 761, 71))
font = QtGui.QFont()
font.setPointSize(11)
font.setBold(False)
font.setWeight(50)
self.pushButton.setFont(font)
self.pushButton.setStyleSheet("background-color:rgb(85, 255, 255);\n"
"")
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(50, 160, 761, 71))
font = QtGui.QFont()
font.setPointSize(9)
self.label.setFont(font)
self.label.setStyleSheet("background-color: rgb(158, 255, 161);")
self.label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 884, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton.clicked.connect(self.clicker) # to initiate the file open dialog
def clicker(self):
global filenm
fname = filedialog.askopenfilename() # askopenfilenames also an option to handle multiple files
filenm = fname
def viewlogs(self):
os.startfile('C:/Users/Siddharth/Desktop/AV/LOGS.txt')
def MalwareDestroyer(self):
global filenm
#normally one would delete the suspicious file first, but for demonstrative purposes, no file deletion is being done
f = open(filenm,'rb')
data = f.read()
f.close()
bytes = len(data)
inc = int((bytes+2)/2)
fileNames = []
for i in range(0,bytes+1,inc):
fn1 = "file%s"%i
fileNames.append(fn1)
f = open(fn1,'wb')
f.write(data[i:i+inc])
f.close()
def Logger(self,line,MalYesorNo,scantype):
global filenm
tim = str(datetime.datetime.now())
if scantype == 'qs' :
with open("C:/Users/Siddharth/Desktop/AV/LOGS.txt",'a+') as f:
f.write("QuickScan ran at : "+ time.strftime("%a, %d %b %Y %H:%M:%S" + " . \n"))
#f.write("QuickScan ran at : "+ tim + "\n")
if MalYesorNo == True:
f.write("The file "+filenm+ " is suspected to be a malware! :( \n For a comprehensive check use the DeepScan \n ")
f.write("Malware details : " + line + " \n \n")
else :
f.write("The file "+filenm+ "is not suspected to be a malware! :) \n For a comprehensive check use DeepScan! \n \n \n")
elif scantype == 'ds':
with open("C:/Users/Siddharth/Desktop/AV/LOGS.txt",'a+') as f:
f.write("DeepScan ran at : " + time.strftime("%a, %d %b %Y %H:%M:%S" + " . \n"))
#f.write("Deepscan ran at : "+ tim +"\n")
if MalYesorNo == True:
f.write("The file "+filenm+" is highly likely to be malware! :( \n")
else :
f.write("The file "+filenm+" is safe! :) \n \n \n")
def deepscan(self):
connection = True
url = 'https://www.google.com'
timeout = 7
try :
request = requests.get(url = url,timeout = timeout)
except (requests.ConnectionError, requests.Timeout) as exception:
self.label.setText("OOPS, looks like you dont have an active internet connection! \n Try connecting to the internet, or try a quickscan!")
connection = False
if connection == True:
global filenm
key = 'a7c08c6918d3b21e88d037d82bff5f4d033b3cae0b425aa5d62342cf158c67ca' # or any other private key
result = None
if filenm == '':
self.label.setText("Oops! You have to select a file first and then scan!\nSelect a file using the above button and then click on any of the scans!")
else:
filenm = filenm.strip()
params = dict(apikey = key)
api_url = "https://www.virustotal.com/vtapi/v2/file/scan"
with open(filenm,'rb') as file:
files = dict(file=(filenm,file))
response = requests.post(api_url,files = files,params = params) # HTTPS POST request being made to submit the file to VirusTotal so that it can be parsed in their servers
if response.status_code == 200:
result = response.json() # will contain just some info that parsing has been successfull
result2 = None
api_url2 = 'https://www.virustotal.com/vtapi/v2/file/report'
params2 = dict(apikey = key, resource = result['sha1'])
response2 = requests.get(api_url2,params = params2) # HTTPS GET request to get the analysis of file which has been most recently parsed!
avlist = []
if response2.status_code == 200:
result2 = response2.json()
#for keys in result2['scans']:
# avlist.append(keys)
try:
if result2['positives'] > 0 :
self.MalwareDestroyer()
self.label.setText("YIKES! The file is most likely malware! \n DONT worry it's been nullified! \n For more information, read the LOGS")
self.label.setStyleSheet("background-color: rgb(255, 172, 164);") # label is now red
self.Logger('',True,'ds')
else :
self.label.setText("The file is SAFE! YAY!")
self.label.setStyleSheet("background-color: rgb(158, 255, 161);") # label is now red
self.Logger('',False,'ds')
except KeyError:
self.label.setText("Oops! Looks like something went wrong with the deep scan! \n CLick on the Deep Scan button 45s later and try again!")
def quickscan(self):
global filenm
print("quickscan is called!")
if filenm == '':
self.label.setText("Oops! You have to select a file first and then scan!\nSelect a file using the above button and then click on any of the scans!")
else:
h = hashlib.md5()
with open(filenm,'rb') as file:
while True:
chunk = file.read(h.block_size)
if not chunk:
break
h.update(chunk)
md5hash = h.hexdigest()
full = None
#lineno = 0
with open("C:/Users/Siddharth/Desktop/AV/HashLists/main.hdb") as f:
#full = f.read()
print("Hash file is opened!")
malpresent = False
for lineno,line in enumerate(f):
if md5hash in line :
malpresent = True
if malpresent == True :
self.MalwareDestroyer()
self.label.setText("MALWARE DETECTED! Do not worry, the file has been neutralised! \n Read LOGS for more details!")
self.label.setStyleSheet("background-color: rgb(255, 172, 164);") # label is now red
self.Logger(line,True,'qs')
else :
self.label.setText("YAAY! No malware detected! Read LOGS for more details!")
self.label.setStyleSheet("background-color: rgb(158, 255, 161);") # label is now red
print("logger is called!")
self.Logger('',False,'qs')
with open("C:/Users/Siddharth/Desktop/AV/HashLists/main.ldb") as f:
#full = f.read()
print("Hash file is opened!")
malpresent = False
for lineno,line in enumerate(f):
if md5hash in line :
malpresent = True
if malpresent == True :
self.MalwareDestroyer()
self.label.setText("MALWARE DETECTED! Do not worry, the file has been neutralised! \n Read LOGS for more details!")
self.label.setStyleSheet("background-color: rgb(255, 172, 164);") # label is now red
self.Logger(line,True,'qs')
else :
self.label.setText("YAAY! No malware detected! Read LOGS for more details!")
self.label.setStyleSheet("background-color: rgb(158, 255, 161);") # label is now red
print("logger is called!")
self.Logger('',False,'qs')
with open("C:/Users/Siddharth/Desktop/AV/HashLists/main.ldb") as f:
#full = f.read()
print("Hash file is opened!")
malpresent = False
for lineno,line in enumerate(f):
if md5hash in line :
malpresent = True
if malpresent == True :
self.MalwareDestroyer()
self.label.setText("MALWARE DETECTED! Do not worry, the file has been neutralised! \n Read LOGS for more details!")
self.label.setStyleSheet("background-color: rgb(255, 172, 164);") # label is now red
self.Logger(line,True,'qs')
else :
self.label.setText("YAAY! No malware detected! Read LOGS for more details!")
self.label.setStyleSheet("background-color: rgb(158, 255, 161);") # label is now red
print("logger is called!")
self.Logger('',False,'qs')
def retranslateUi(self, MainWindow): # generates the UI
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Garuda AV"))
self.QuickScanB.setText(_translate("MainWindow", "Quick Scan"))
self.DeepScanB.setText(_translate("MainWindow", "Deep Scan"))
self.ViewLogsB.setText(_translate("MainWindow", "View Logs"))
self.pushButton.setText(_translate("MainWindow", "CLICK TO SELECT FILE(S)"))
self.label.setText(_translate("MainWindow", "Select the file you want to scan by using the button above, and run a scan on it!"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec())