-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfilehandler.py
61 lines (57 loc) · 1.49 KB
/
filehandler.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
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from dbhandler import *
from multiprocessing import Process,Manager
import time
import os
import os.path
from cdr import *
import pefile
class MyHandler(FileSystemEventHandler):
def on_any_event(self, event):
text=event.src_path
try:
time.sleep(2)
h=md5Checksum(text)
pos = getVT(h)
extension = os.path.splitext(text)[1]
print(extension)
if pos == -1:
insert_fe(text,h,event.event_type)
if extension==".exe":
try:
pe=pefile.PE(text)
if check_Imphash(pe.get_imphash()) != False :
print("Imp hash Malware found"+check_Imphash(h))
updatefhash(h,66,10,0)
except:
pass
elif pos < 4:
print("Not mailicious")
insert_fe(text,h,event.event_type)
updatefhash(h,66,pos,0)
elif pos > 4:
print("mailicious "+text)
insert_fe(text,h,event.event_type)
updatefhash(h,66,pos,0)
print("Malicius file Zipping..."+text)
zip_file(text)
if extension==".exe" and check_exe(text):
print("unsigned exe Zipping..."+text)
zip_file(text)
if extension==".pdf":
print("pdf added peforming CDR...")
cdr(text)
except Exception as e:
pass
def scan_path(path):
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=False)
observer.start()
try:
while True:
time.sleep(1)
except:
pass
observer.join()