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.

62 lines
14 KiB

4 years ago
  1. import unittest
  2. import mail
  3. import os
  4. mail_data = b'Delivered-To: ycolakoglu.bilisim@gmail.com\r\nReceived: by 2002:a4a:3b52:0:0:0:0:0 with SMTP id s79csp5499397oos;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nX-Received: by 2002:a62:5284:: with SMTP id g126mr36248899pfb.95.1571116620441;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nARC-Seal: i=1; a=rsa-sha256; t=1571116620; cv=none;\r\n d=google.com; s=arc-20160816;\r\n b=cpnYE9u9z+MntvqooyBpwsjspuZ1eIXZ0CbeDqM41EV6hYZhvVh94tWy55IyY/NxO/\r\n FaR81R1OC5eVt50vyEx1HHVSfF592GrexKhS5I54EDXF/4d8bbsruipRnw3HzSefmu5F\r\n 662POtR4sxcxAWfP0RSjecj8F6HzL/fPsf/zltB1E2mATNmvi55MJbyiXrkgSki7AsH2\r\n V0OTSSRbkei2a0jW0mFAf1aikYODSqxInejlIKB+L1fAWXVHrd/gw8Bb4HEFyzCBzx5O\r\n pX1qj4hCg2zZ9mq2gOyNjYpQiQPcRl4PeP6WS2FlDQHF1pvo/YIWIY/X9meRZU7OVhak\r\n pRKg==\r\nARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;\r\n h=to:from:subject:message-id:feedback-id:date:mime-version\r\n :dkim-signature;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=F6ssVJAjMg4eWB+FOYSxC6Z3QJ5AksZBZiNyyQJaLwbQawF+ENaOIYzOD4zzUWcK9U\r\n NEhcv9onqo9FLH1jl4bQcNV7f2oSfrf3eQvzR56E8JSemz/eH32uN4rnM/H7Q+Q9A4WB\r\n QSQaEnS7OOuUbx7Vb53yxJ+0+tKogaK+Io5APQ0psLW2i5/ZraPYS4uLfAgsqwPGLSxa\r\n lK2aYOcpqNSPnye3Ie2jib+jL44sW1vMhlfr46MoF28guVPpj0ByWy/m62HDwjKdVUap\r\n HBcvw2oEFLV3aiqxsifMlbin3W0IR+ZppnZkxMWs+bmNn8YcOvpSqZ5bZR2hnyOW8+Iy\r\n Trqg==\r\nARC-Authentication-Results: i=1; mx.google.com;\r\n dkim=pass header.i=@accounts.google.com header.s=20161025 header.b=yqMoB78r;\r\n spf=pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com;\r\n dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=accounts.google.com\r\nReturn-Path: <3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com>\r\nReceived: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73])\r\n by mx.google.com with SMTPS id m6sor19968531pgp.62.2019.10.14.22.17.00\r\n for <ycolakoglu.bilisim@gmail.com>\r\n (Google Transport Security);\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)\r\nReceived-SPF: pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73;\r\nAuthentication-Results: mx.google.com;\r\n dkim=pass header.i=@accounts.google.com header.s=20161025 header.b=yqMoB78r;\r\n spf=pass (google.com: domain of 3s1alxqgtaiars-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3S1alXQgTAIArs-vitp2eggsyrxw.ksskpi.gsq@gaia.bounces.google.com;\r\n dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=accounts.google.com\r\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=accounts.google.com; s=20161025;\r\n h=mime-version:date:feedback-id:message-id:subject:from:to;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=yqMoB78ruEfTrMV0UsPvCuTrOs+o++szTk6Tnw//IhMJ/jj2TJvAWQvuUXaHVQKb7p\r\n 1FYqRrqOWj+zSTv/xeHz2W6SnVvA7ThoE1QVbZKBX2zSDe/yG6NImw7luFE/D3zbQ4Xk\r\n mMg2AM3Vvttkz8krt6omolVeJab7luTChU6mfojgF3lcrkHL3l5w9Q6eUY7q8vOP4SmN\r\n RevtIe3vZw6T/ozfjbyD8ptEZHqrJ93KHrot3Oe4wg0sDkhdLY6eYfQnQAKuDQKnpLA3\r\n gMdeu+jDikTfhIKu99WQqoY5Rer9XGVedtaaAZFJ+BB11iEkc939LmH5W6bHXeGF/itd\r\n ldog==\r\nX-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n d=1e100.net; s=20161025;\r\n h=x-gm-message-state:mime-version:date:feedback-id:message-id:subject\r\n :from:to;\r\n bh=T4/J1/5TDNqRq8UWUiIGuzPe7Zv+PrrvC6tmCrrt0i4=;\r\n b=Ljo8+tiQogDE4ff31Fo4bq6GHH1n64neGOaFLYFqd/1dBBZhxLI+FJH9s+mYesbWoY\r\n 4/X77kHpwd5MDkmbkP/wsOdZe7MG9YpyucuWMJXRDWONkjl2PjTVLlNUJxLVFfj4P8WD\r\n fxF8iPKdjRiSxCuZXhU/FmpYtWacYjExUml3p
  5. class MailTest(unittest.TestCase):
  6. def test_from(self):
  7. mail_obj = mail.Mail(mail_data)
  8. self.assertEqual(mail_obj.header_data["From"], "Google <no-reply@accounts.google.com>")
  9. def test_received(self):
  10. mail_obj = mail.Mail(mail_data)
  11. self.assertEqual(mail_obj.header_data["Received"], 'by 2002:a4a:3b52:0:0:0:0:0 with SMTP id s79csp5499397oos;\r\n Mon, 14 Oct 2019 22:17:00 -0700 (PDT)')
  12. def test_date(self):
  13. mail_obj = mail.Mail(mail_data)
  14. self.assertEqual(mail_obj.header_data["Date"], "Tue, 15 Oct 2019 05:16:58 +0000 (GMT)")
  15. def test_mail_blacklist(self):
  16. mail_obj = mail.Mail(mail_data.replace(b"2002:a4a:3b52:0:0:0:0:0", b"unittest.malicious.com"))
  17. mail_obj.DOMAIN_COEFFICIENT = 2
  18. mail_obj.DOMAIN_THRESHOLD = 5
  19. mail_obj.check_blacklisted()
  20. self.assertTrue(mail_obj._spam)
  21. mail_obj = mail.Mail(mail_data.replace(b"no-reply@accounts.google.com", b"utest@malicious.com"))
  22. mail_obj.MAIL_COEFFICIENT = 2
  23. mail_obj.MAIL_THRESHOLD = 5
  24. mail_obj.check_blacklisted()
  25. self.assertTrue(mail_obj._spam)
  26. def test_domain_blacklist(self):
  27. mail_obj = mail.Mail(mail_data)
  28. mail_obj.DOMAIN_COEFFICIENT = 2
  29. mail_obj.DOMAIN_THRESHOLD = 5
  30. mail_obj.check_spam()
  31. self.assertTrue(mail_obj._spam)
  32. class MailBoxTest(unittest.TestCase):
  33. def test_mail_walk(self):
  34. mail_dir = os.path.join(os.getcwd(), "mails/<domain>/<user>")
  35. mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993)
  36. self.assertEqual(list(mailbox_obj.mails.keys()), ["mail_example"])
  37. def test_mail_parse(self):
  38. mail_dir = os.path.join(os.getcwd(), "mails/<domain>/<user>")
  39. mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993)
  40. self.assertEqual(mailbox_obj.mails["mail_example"][0].message, "Hello boi this is a test\n")
  41. def test_xss_check(self):
  42. mail_dir = os.path.join(os.getcwd(), "mails/<domain>/<user>")
  43. mailbox_obj = mail.MailBox("ycolakoglu.bilisim@gmail.com", "totallysecurepass", "imap.google.com", 993)
  44. mailbox_obj.check_spam()
  45. self.assertEqual()
  46. if __name__ == '__main__':
  47. MailTest.run()
  48. MailBoxTest.run()