From 858f191319db2adb1d81e791cf2beb807ffee6f4 Mon Sep 17 00:00:00 2001 From: funilrys Date: Thu, 3 Oct 2019 17:36:34 +0200 Subject: [PATCH 1/2] Introduction of the mail:password analyzer. This patch fix https://github.com/d-Rickyy-b/pastepwn/issues/82 Also: * Edition of the mail analyzer in order to share its pattern. --- pastepwn/analyzers/mailanalyzer.py | 4 +- pastepwn/analyzers/mailpasswordanalyzer.py | 15 ++++ .../analyzers/tests/mailpasswordanalyzer.py | 68 +++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 pastepwn/analyzers/mailpasswordanalyzer.py create mode 100644 pastepwn/analyzers/tests/mailpasswordanalyzer.py diff --git a/pastepwn/analyzers/mailanalyzer.py b/pastepwn/analyzers/mailanalyzer.py index fcc736e..52fca72 100644 --- a/pastepwn/analyzers/mailanalyzer.py +++ b/pastepwn/analyzers/mailanalyzer.py @@ -5,8 +5,8 @@ class MailAnalyzer(RegexAnalyzer): """Analyzer to match on email addresses via regex""" name = "MailAnalyzer" + pattern = r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)" def __init__(self, actions): # Regex taken from http://emailregex.com/ - regex = r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)" - super().__init__(actions, regex) + super().__init__(actions, self.pattern) diff --git a/pastepwn/analyzers/mailpasswordanalyzer.py b/pastepwn/analyzers/mailpasswordanalyzer.py new file mode 100644 index 0000000..3b030ce --- /dev/null +++ b/pastepwn/analyzers/mailpasswordanalyzer.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from .mailanalyzer import MailAnalyzer +from .regexanalyzer import RegexAnalyzer + + +class MailPasswordAnalyzer(RegexAnalyzer): + """ + Analyzer to match an email and password pair. + """ + + name = "EmailPasswordAnalyzer" + + def __init__(self, actions): + regex = MailAnalyzer.pattern + ":(.*)" + super().__init__(actions, regex) diff --git a/pastepwn/analyzers/tests/mailpasswordanalyzer.py b/pastepwn/analyzers/tests/mailpasswordanalyzer.py new file mode 100644 index 0000000..87b6154 --- /dev/null +++ b/pastepwn/analyzers/tests/mailpasswordanalyzer.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +import unittest +from unittest import mock + +from pastepwn.analyzers.mailpasswordanalyzer import MailPasswordAnalyzer + + +class TestDBConnAnalyzer(unittest.TestCase): + def setUp(self): + self.analyzer = MailPasswordAnalyzer(None) + self.paste = mock.Mock() + + def test_match_positive(self): + """Test if positives are recognized""" + + positives = [ + "thesaxmaniac@hotmail.com:neverhood", + "ledzepln1@aol.com:stairway", + "kelsean75@hotmail.com:computer1elray8379@gmail.com:josh8598", + "mekim45@hotmail.com:mullins74", + "jjenkins19@yahoo.com:faster", + "r_m_vincent@yahoo.com:soling12", + "deadally@hotmail.com:balajaga1", + "Choas23@gmail.com:8KlAs432", + "jefftrey@yahoo.com:tanqueray", + "syntex05@mac.com:kobela87", + "michaelbarbra@hotmail.com:2177", + "mcginnis_98@yahoo.com:bentley", + "majikcityqban82@gmail.com:tinpen39", + "pekanays@yahoo.com:warriors", + "g_vanmeter@yahoo.com:torbeet", + "rrothn@yahoo.com:rebsopjul3", + "apryle_douglas@yahoo.com:campbell", + "estocanam2@gmail.com:Firebird1@", + "Samirenzer@yahoo.com:pepper0120", + "davebialik@gmail.com:tr1ang1e", + "kellyjames@atmc.net:ginnyanna", + "Kennedy123@aol.com:Edmonia1", + "rcstanley@ms.metrocast.net:jjba1304", + "this_isatest@example.org:hello,world" + "this-is-another-thest@müller-beispiel.de", + ] + + for positive in positives: + self.paste.body = positive + self.assertTrue( + self.analyzer.match(self.paste), f"{positive} do not match." + ) + + def test_match_negative(self): + """Test if negatives are not recognized""" + + negatives = [ + "", + None, + "test@example.org", + "example@:hello", + "example@example:hello", + "hello:test@example.org", + ] + + for negative in negatives: + self.paste.body = negative + self.assertFalse(self.analyzer.match(self.paste), f"{negative} matches.") + + +if __name__ == "__main__": + unittest.main() From a97358e1308dbc9e5c070bd669e5a27a80e005df Mon Sep 17 00:00:00 2001 From: funilrys Date: Thu, 3 Oct 2019 17:48:42 +0200 Subject: [PATCH 2/2] Fix https://github.com/d-Rickyy-b/pastepwn/pull/84#discussion_r331113929 --- pastepwn/analyzers/tests/mailpasswordanalyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pastepwn/analyzers/tests/mailpasswordanalyzer.py b/pastepwn/analyzers/tests/mailpasswordanalyzer.py index 87b6154..9e8723e 100644 --- a/pastepwn/analyzers/tests/mailpasswordanalyzer.py +++ b/pastepwn/analyzers/tests/mailpasswordanalyzer.py @@ -5,7 +5,7 @@ from pastepwn.analyzers.mailpasswordanalyzer import MailPasswordAnalyzer -class TestDBConnAnalyzer(unittest.TestCase): +class TestMailPasswordAnalyzer(unittest.TestCase): def setUp(self): self.analyzer = MailPasswordAnalyzer(None) self.paste = mock.Mock()