Skip to content

Commit

Permalink
Introduction of the mail:password analyzer.
Browse files Browse the repository at this point in the history
This patch fix #82

Also:
  * Edition of the mail analyzer in order to share its pattern.
  • Loading branch information
funilrys committed Oct 3, 2019
1 parent 641afb3 commit 858f191
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pastepwn/analyzers/mailanalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions pastepwn/analyzers/mailpasswordanalyzer.py
Original file line number Diff line number Diff line change
@@ -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)
68 changes: 68 additions & 0 deletions pastepwn/analyzers/tests/mailpasswordanalyzer.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 858f191

Please sign in to comment.