From be22f553583a06622889b8cd542772143d70ac61 Mon Sep 17 00:00:00 2001 From: Sam Sneed <163201376+sam-sneed@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:19:20 -0500 Subject: [PATCH] fix the fix to hopefully finally fix the bug --- main.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 8c565fc..303898b 100644 --- a/main.py +++ b/main.py @@ -174,15 +174,6 @@ def monitor_cpu_gpu_usage(): time.sleep(5) -def realtime_av(): - while True: - try: - print("Realtime AntiMalware active") - kill_suspicious_processes() - except Exception as e: - print(f"Error in realtimeAV: {e}") - time.sleep(1) # Check for malware every second - def get_gpu_usage(): gpus = tf.config.list_physical_devices('GPU') if gpus: @@ -304,6 +295,30 @@ def thread_counter(): print(f"Active anti-malware threads: {threading.active_count()}") time.sleep(10) # Prints active count of Anti-Malware threads every 10 seconds. +# Similar to "kill_suspicious_processes" but just the essentials (for optimization.) +def realtime_av(): + while True: + for proc in psutil.process_iter(['pid', 'name', 'cmdline']): + try: + proc_name = proc.info['name'].lower() + cmdline = " ".join(proc.info['cmdline']).lower() + + if proc_name in mining_processes and proc_name not in bypassed_processes: + print(f"Terminating suspicious mining process: {proc.info['name']} (PID: {proc.info['pid']})") + proc.terminate() + proc.wait() + + # Scan files for malware as they launch and kill if potentially malicious. + for file_path in proc.info.get('cmdline', []): + if os.path.isfile(file_path): + if scan_for_malware(file_path): + print(f"Terminating potentially malicious process {proc.info['name']} (PID: {proc.info['pid']} NOW...") + proc.terminate() + proc.wait() + except (psutil.NoSuchProcess, psutil.AccessDenied) as e: + print(f"Error terminating process: {e}") + time.sleep(1) + # Start Monitoring in Threads threads = [ threading.Thread(target=start_file_system_monitor),