Kulyutmaz is a project developed for the regional TUBITAK competition's programming field thart aims to create a more advanced phishing e-mail detection algorithm using website content checking and a neural network that we have trained.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.7 KiB

4 years ago
  1. from mail import MailBox, Logger
  2. import time
  3. from threading import Thread
  4. from subprocess import Popen, PIPE
  5. import sys
  6. import json
  7. class MailWatcher(Thread):
  8. def __init__(self, account, interval, creds, sensitivity, thresh, logger):
  9. Thread.__init__(self)
  10. self.account = account
  11. self.interval = interval
  12. self.threshold = thresh
  13. self.creds = creds
  14. self.sensitivity = sensitivity
  15. self.running = True
  16. self.stopped = False
  17. self.logger = logger
  18. def run(self):
  19. mailbox_obj = MailBox(self.account["uname"], self.account["password"], self.account["server"], self.account["port"],self.creds, self.sensitivity, self.threshold, self.logger)
  20. while 1 and self.running:
  21. time.sleep(self.interval/100)
  22. mailbox_obj.refresh_new_mails()
  23. self.stopped = True
  24. def stop(self):
  25. self.running = False
  26. def thread_done(thread:MailWatcher):
  27. return thread.stopped
  28. conf = json.loads(sys.stdin.readline())
  29. workdir = sys.stdin.readline()
  30. threads = []
  31. loggers = []
  32. mysql_creds = {}
  33. main_log = Logger(workdir[:-1] + "/logs/main_process")
  34. main_log.info("Started main process")
  35. for i in conf:
  36. if i.startswith("mysql"):
  37. mysql_creds[i] = conf[i]
  38. for i in conf["accounts"]:
  39. loggers.append(Logger(workdir[:-1] + "/logs/" + i["uname"]))
  40. threads.append(MailWatcher(i, conf["refresh_millis"], mysql_creds, conf["sensitivity"], conf["threshold"], loggers[-1]))
  41. threads[-1].start()
  42. main_log.info("Created listeners")
  43. while str(input()) != "0":
  44. continue
  45. main_log.info("Detected interrupt. Stopping!")
  46. for thread in threads:
  47. thread.stop()
  48. main_log.info("Sent stop signal to all threads!")
  49. while not all(map(thread_done,threads)):
  50. continue
  51. main_log.info("All threads stopped!")
  52. for logger in loggers:
  53. logger.stop()
  54. exit(0)