Şu an yanlış pozitif çok verse de tespit oranı ClamAV’a kıyasla çok iyi fakat aşırı fazla karışık tespit mekanizması var. Tek takıldığım nokta gerçek zamanlı koruma yapımı. Açık kaynak olacak. Gerçek zamanlı koruma kodunu göstermeden önce neden python seçtiğimi anlatayım. Python’da API desteği çok iyi. Yavaş gözükse de optimize edince sorun kalmıyor. Kodlaması ve anlaşılması gayet kolay. Neyse meselemize dönelim. Ben kodu paylaşayım: `import os
import win32file
import win32con
import win32gui
import win32api
import win32process
from parseJson import ParseJson
import pygetwindow as gw
import pynput.mouse
import threading
from queue import Queue
FILE_ACTION_ADDED = 0x00000001
FILE_ACTION_REMOVED = 0x00000002
FILE_ACTION_MODIFIED = 0x00000003
def systemWatcher(XylentScanner, SYSTEM_DRIVE, thread_resume):
XYLENT_SCAN_CACHE = ParseJson(‘./config’, ‘xylent_scancache’, {})
XYLENT_CACHE_MAXSIZE = 500000 # 500KB
file_queue = Queue()
def on_mouse_click(x, y, button, pressed):
if pressed:
path_to_scan = get_file_path_from_click(x, y)
print(f"Mouse clicked at ({x}, {y}) on file: {path_to_scan}")
# Add file to the queue for processing in the main thread
file_queue.put(path_to_scan)
def get_file_path_from_click(x, y):
hwnd = win32gui.WindowFromPoint((x, y))
pid = win32process.GetWindowThreadProcessId(hwnd)[1]
handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ, False, pid)
return win32process.GetModuleFileNameEx(handle, 0)
def process_file_queue():
while thread_resume.is_set():
try:
path_to_scan = file_queue.get(timeout=1) # Timeout to avoid blocking indefinitely
print(f"Processing file: {path_to_scan}")
try:
if os.path.isfile(path_to_scan):
verdict = XylentScanner.scanFile(path_to_scan)
XYLENT_SCAN_CACHE.setVal(path_to_scan, verdict)
except Exception as e:
print(e)
print(f"Error scanning {path_to_scan}")
except Queue.Empty:
pass # Queue is empty, continue checking
if os.path.getsize(XYLENT_SCAN_CACHE.PATH) >= XYLENT_CACHE_MAXSIZE:
XYLENT_SCAN_CACHE.purge()
print("Purging")
def file_monitor():
while thread_resume.is_set():
# File monitoring
path_to_watch = SYSTEM_DRIVE + "\\"
hDir = win32file.CreateFile(
path_to_watch,
1,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,
None,
win32con.OPEN_EXISTING,
win32con.FILE_FLAG_BACKUP_SEMANTICS,
None
)
results = win32file.ReadDirectoryChangesW(
hDir,
1024,
True,
win32con.FILE_NOTIFY_CHANGE_FILE_NAME |
win32con.FILE_NOTIFY_CHANGE_DIR_NAME |
win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES |
win32con.FILE_NOTIFY_CHANGE_SIZE |
win32con.FILE_NOTIFY_CHANGE_LAST_WRITE |
win32con.FILE_NOTIFY_CHANGE_SECURITY |
FILE_ACTION_ADDED |
FILE_ACTION_MODIFIED |
FILE_ACTION_REMOVED,
None,
None
)
for action, file in results:
path_to_scan = os.path.join(path_to_watch, file)
print(path_to_scan) # Print the path for debugging purposes
# Add file to the queue for processing in the main thread
file_queue.put(path_to_scan)
if os.path.getsize(XYLENT_SCAN_CACHE.PATH) >= XYLENT_CACHE_MAXSIZE:
XYLENT_SCAN_CACHE.purge()
print("Purging")
mouse_listener = threading.Thread(target=lambda: pynput.mouse.Listener(on_click=on_mouse_click).start())
mouse_listener.start()
monitor_thread = threading.Thread(target=file_monitor)
monitor_thread.start()
process_queue_thread = threading.Thread(target=process_file_queue)
process_queue_thread.start()
mouse_listener.join() # Wait for mouse listener to finish (shouldn't happen in this case)
monitor_thread.join() # Wait for file monitor to finish
process_queue_thread.join() # Wait for file processing thread to finish
print("RTP waiting to start...")`Şimdi ben buna explorer.exe yani Windows Gezgininde olan mevcut bulunduğum klasörü tespit edip tarayacak veya tıkladığım dosyaları tarayacak. Bunu yapmaya çalıştım ama daha yeni geliştirdiğim için bitmedi. Başka dil kullanın diyorlar ama ben şunu fark ettim python'da gayet mümkünmüş. En kötü watchdog kullanırım gerçek zamanlı koruma için. Birde ClamAV dokümasyonuna girdim fakat şu an onu geliştirmiyorum. Şu an Xylent'i gelişitiriyorum. Bu konuyu açmamın sebebi bana yardım edecek birisini arıyorum.