Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBerserkers888 authored Jun 8, 2024
1 parent 77f451f commit 4d3d580
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/email_notifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

def send_email(subject, body):
sender_email = "[email protected]"
receiver_email = "[email protected]"
password = "your_password"

msg = MIMEMultipart()
msg["From"] = sender_email
msg["To"] = receiver_email
msg["Subject"] = subject

msg.attach(MIMEText(body, "plain"))

try:
server = smtplib.SMTP("smtp.example.com", 587)
server.starttls()
server.login(sender_email, password)
text = msg.as_string()
server.sendmail(sender_email, receiver_email, text)
server.quit()
print("Email sent successfully")
except Exception as e:
print(f"Failed to send email: {e}")

def notify_suspicious_process(process_name):
subject = "Suspicious Process Detected"
body = f"A suspicious process was detected and terminated: {process_name}"
send_email(subject, body)
24 changes: 24 additions & 0 deletions src/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import tkinter as tk
from tkinter import messagebox
import threading
from security_monitor import monitor_processes, stop_monitoring

def start_monitoring():
thread = threading.Thread(target=monitor_processes)
thread.start()
messagebox.showinfo("Information", "Monitoring started")

def stop_monitoring_gui():
stop_monitoring()
messagebox.showinfo("Information", "Monitoring stopped")

root = tk.Tk()
root.title("SecureProcessMonitor")

start_button = tk.Button(root, text="Start Monitoring", command=start_monitoring)
start_button.pack(pady=10)

stop_button = tk.Button(root, text="Stop Monitoring", command=stop_monitoring_gui)
stop_button.pack(pady=10)

root.mainloop()
38 changes: 38 additions & 0 deletions src/processmonitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import psutil
import time
from datetime import datetime
from email_notifier import notify_suspicious_process

suspicious_processes = ["powershell.exe", "ftp.exe"]
log_file = "security_monitor.log"
monitoring = True

def log_event(event):
with open(log_file, "a") as log:
log.write(f"{datetime.now()} - {event}\n")

def kill_process(process_name):
for proc in psutil.process_iter(['pid', 'name']):
if proc.info['name'].lower() == process_name:
proc.kill()
log_event(f"Killed process: {process_name}")
notify_suspicious_process(process_name)

def monitor_processes():
global monitoring
while monitoring:
for proc_name in suspicious_processes:
kill_process(proc_name)
time.sleep(1)

def stop_monitoring():
global monitoring
monitoring = False

if __name__ == "__main__":
try:
log_event("Started monitoring suspicious processes.")
monitor_processes()
except KeyboardInterrupt:
log_event("Stopped monitoring script.")
print("Stopping the monitoring script.")

0 comments on commit 4d3d580

Please sign in to comment.