Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduction of the mail:password analyzer. #84

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Owner

@d-Rickyy-b d-Rickyy-b Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to do from pastepwn.analyzers import MailPasswordAnalyzer if you add the analyzer to the package init file



class TestDBConnAnalyzer(unittest.TestCase):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this one 🙈 .

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."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And as you stated in your comment, this somehow fails on Python 3.5 and earlier (see Travis). Maybe you can change it so that it does work with python 3.4 at least.

"{0} do not match.".format(positive) should work.

)

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()