Skip to content

Commit

Permalink
Merge a8bcd4c into 25b5313
Browse files Browse the repository at this point in the history
  • Loading branch information
d-Rickyy-b authored Oct 10, 2019
2 parents 25b5313 + a8bcd4c commit 9cf20ce
Show file tree
Hide file tree
Showing 24 changed files with 419 additions and 47 deletions.
82 changes: 42 additions & 40 deletions pastepwn/analyzers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,78 +1,80 @@
# -*- coding: utf-8 -*-
from .adobekeyanalyzer import AdobeKeyAnalyzer
from .alwaystrueanalyzer import AlwaysTrueAnalyzer
from .awsaccesskeyanalyzer import AWSAccessKeyAnalyzer
from .awssecretkeyanalyzer import AWSSecretKeyAnalyzer
from .awssessiontokenanalyzer import AWSSessionTokenAnalyzer
from .base64analyzer import Base64Analyzer
from .basicanalyzer import BasicAnalyzer
from .battlenetkeyanalyzer import BattleNetKeyAnalyzer
from .bcrypthashanalyzer import BcryptHashAnalyzer
from .creditcardanalyzer import CreditCardAnalyzer
from .databasedumpanalyzer import DatabaseDumpAnalyzer
from .dbconnstringanalyzer import DBConnAnalyzer
from .emailpasswordpairanalyzer import EmailPasswordPairAnalyzer
from .facebookaccesstokenanalyzer import FacebookAccessTokenAnalyzer
from .genericanalyzer import GenericAnalyzer
from .googleoauthkeyanalyzer import GoogleOAuthKeyAnalyzer
from .ibananalyzer import IBANAnalyzer
from .logicalanalyzers import AndAnalyzer
from .logicalanalyzers import LogicalBaseAnalyzer
from .logicalanalyzers import OrAnalyzer
from .mailanalyzer import MailAnalyzer
from .mailchimpapikeyanalyzer import MailChimpApiKeyAnalyzer
from .md5hashanalyzer import MD5HashAnalyzer
from .megalinkanalyzer import MegaLinkAnalyzer
from .microsoftkeyanalyzer import MicrosoftKeyAnalyzer
from .originkeyanalyzer import OriginKeyAnalyzer
from .pastebinurlanalyzer import PastebinURLAnalyzer
from .phonenumberanalyzer import PhoneNumberAnalyzer
from .privatekeyanalyzer import PrivateKeyAnalyzer
from .regexanalyzer import RegexAnalyzer
from .shahashanalyzer import SHAHashAnalyzer
from .slacktokenanalyzer import SlackTokenAnalyzer
from .slackwebhookanalyzer import SlackWebhookAnalyzer
from .steamkeyanalyzer import SteamKeyAnalyzer
from .stripeapikeyanalyzer import StripeApiKeyAnalyzer
from .uplaykeyanalyzer import UplayKeyAnalyzer
from .urlanalyzer import URLAnalyzer
from .wordanalyzer import WordAnalyzer
from .ibananalyzer import IBANAnalyzer
from .dbconnstringanalyzer import DBConnAnalyzer
from .privatekeyanalyzer import PrivateKeyAnalyzer
from .adobekeyanalyzer import AdobeKeyAnalyzer
from .facebookaccesstokenanalyzer import FacebookAccessTokenAnalyzer
from .base64analyzer import Base64Analyzer
from .slacktokenanalyzer import SlackTokenAnalyzer
from .mailchimpapikeyanalyzer import MailChimpApiKeyAnalyzer
from .stripeapikeyanalyzer import StripeApiKeyAnalyzer
from .awssecretkeyanalyzer import AWSSecretKeyAnalyzer
from .awsaccesskeyanalyzer import AWSAccessKeyAnalyzer
from .googleoauthkeyanalyzer import GoogleOAuthKeyAnalyzer
from .slackwebhookanalyzer import SlackWebhookAnalyzer
from .megalinkanalyzer import MegaLinkAnalyzer


__all__ = (
'AdobeKeyAnalyzer',
'AlwaysTrueAnalyzer',
'AndAnalyzer',
'AWSSecretKeyAnalyzer',
'AWSAccessKeyAnalyzer',
'AWSSessionTokenAnalyzer',
'Base64Analyzer',
'BasicAnalyzer',
'BattleNetKeyAnalyzer',
'BcryptHashAnalyzer',
'MD5HashAnalyzer',
'SHAHashAnalyzer',
'CreditCardAnalyzer',
'DatabaseDumpAnalyzer',
'DBConnAnalyzer',
'EmailPasswordPairAnalyzer',
'FacebookAccessTokenAnalyzer',
'GenericAnalyzer',
'GoogleOAuthKeyAnalyzer',
'IBANAnalyzer',
'LogicalBaseAnalyzer',
'MailAnalyzer',
'MailChimpApiKeyAnalyzer',
'MD5HashAnalyzer',
'MegaLinkAnalyzer',
'MicrosoftKeyAnalyzer',
"OrAnalyzer",
'OriginKeyAnalyzer',
'PastebinURLAnalyzer',
'RegexAnalyzer',
'URLAnalyzer',
'WordAnalyzer',
'IBANAnalyzer',
'DatabaseDumpAnalyzer',
'DBConnAnalyzer',
'PrivateKeyAnalyzer',
'PhoneNumberAnalyzer',
'OriginKeyAnalyzer',
'SteamKeyAnalyzer',
'UplayKeyAnalyzer',
'BattleNetKeyAnalyzer',
'MicrosoftKeyAnalyzer',
'AdobeKeyAnalyzer',
'DBConnAnalyzer',
'PrivateKeyAnalyzer',
'EmailPasswordPairAnalyzer',
'FacebookAccessTokenAnalyzer',
'Base64Analyzer',
'RegexAnalyzer',
'SHAHashAnalyzer',
'SlackTokenAnalyzer',
'MailChimpApiKeyAnalyzer',
'SlackWebhookAnalyzer',
'MegaLinkAnalyzer',
'AWSSecretKeyAnalyzer',
'AWSAccessKeyAnalyzer',
'GoogleOAuthKeyAnalyzer',
'StripeApiKeyAnalyzer'
'SteamKeyAnalyzer',
'StripeApiKeyAnalyzer',
'WordAnalyzer',
'UplayKeyAnalyzer',
'URLAnalyzer',
)
13 changes: 13 additions & 0 deletions pastepwn/analyzers/awssessiontokenanalyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from .regexanalyzer import RegexAnalyzer


class AWSSessionTokenAnalyzer(RegexAnalyzer):
"""
Analyzer to match AWS Session Token via regex
"""
name = "AWSSessionTokenAnalyzer"

def __init__(self, actions):
regex = r"((\\\"|'|`)?((i)?aws)?_?((i)?session)?_?((i)?token)?(\\\"|'|`)?\\\\s{0,50}(:|=>|=)\\\\s{0,50}(\\\"|'|`)?[A-Za-z0-9/+=]{16,}(\\\"|'|`)?)"
super().__init__(actions, regex)
10 changes: 4 additions & 6 deletions pastepwn/analyzers/basicanalyzer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from pastepwn.util import listify
import logging


class BasicAnalyzer(object):
Expand All @@ -11,13 +13,9 @@ def __init__(self, actions, identifier=None):
:param actions: A single action or a list of actions to be executed on every paste
:param identifier: The name or unique identifier for this specific analyzer
"""
if actions is None:
self.actions = []
elif isinstance(actions, list):
self.actions = actions
else:
self.actions = [actions]
self.actions = listify(actions)
self.identifier = identifier or self.name
self.logger = logging.getLogger(self.name)

def add_action(self, action):
"""
Expand Down
1 change: 1 addition & 0 deletions pastepwn/analyzers/googleoauthkeyanalyzer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from .regexanalyzer import RegexAnalyzer


Expand Down
7 changes: 7 additions & 0 deletions pastepwn/analyzers/logicalanalyzers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-

from .andanalyzer import AndAnalyzer
from .logicalbaseanalyzer import LogicalBaseAnalyzer
from .oranalyzer import OrAnalyzer

__all__ = ('LogicalBaseAnalyzer', 'AndAnalyzer', 'OrAnalyzer')
18 changes: 18 additions & 0 deletions pastepwn/analyzers/logicalanalyzers/andanalyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from .logicalbaseanalyzer import LogicalBaseAnalyzer


class AndAnalyzer(LogicalBaseAnalyzer):
"""Meta analyzer which matches a paste if all of the passed analyzers match that paste"""
name = "AndAnalyzer"

def match(self, paste):
"""Returns True if all of the passed analyzers matched"""
if len(self.analyzers) == 0:
return False

for analyzer in self.analyzers:
if not analyzer.match(paste):
return False

return True
45 changes: 45 additions & 0 deletions pastepwn/analyzers/logicalanalyzers/logicalbaseanalyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from pastepwn.analyzers.basicanalyzer import BasicAnalyzer
from pastepwn.util import listify


class LogicalBaseAnalyzer(BasicAnalyzer):
"""Meta analyzer used to combine analyzers via a logical operator"""
name = "LogicalBaseAnalyzer"

def __init__(self, actions, analyzers, merge_actions=False):
"""
Meta analyzer used to combine analyzers via a logical operator
:param actions: A single action or a list of actions to be executed on every paste
:param analyzers: A single analyzer or a list of analyzers used to match pastes
"""
super().__init__(actions)
self.analyzers = listify(analyzers)

if len(self.analyzers) == 0:
self.logger.warning("You have not specified any analyzers inside '{}'".format(self.name))

if merge_actions:
self._merge_actions()

def _merge_actions(self):
"""
Merges the actions of the passed analyzers into this meta analyzer
If merged, the actions will be executed if this meta analyzer matches
:return: None
"""
for analyzer in self.analyzers:
for action in analyzer.actions:
self.actions.append(action)

def add_analyzer(self, analyzer):
"""
Add a new analyzer to the list of analyzers
:param analyzer: A single analyzer used to match pastes
:return:
"""
self.analyzers.append(analyzer)

def match(self, paste):
"""Must be overridden by the subclasses"""
raise NotImplementedError("match() function must be overridden in the subclasses!")
15 changes: 15 additions & 0 deletions pastepwn/analyzers/logicalanalyzers/oranalyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from .logicalbaseanalyzer import LogicalBaseAnalyzer


class OrAnalyzer(LogicalBaseAnalyzer):
"""Meta analyzer which matches a paste if any of the passed analyzers match that paste"""
name = "OrAnalyzer"

def match(self, paste):
"""Returns True if all of the passed analyzers matched"""
for analyzer in self.analyzers:
if analyzer.match(paste):
return True

return False
Empty file.
54 changes: 54 additions & 0 deletions pastepwn/analyzers/logicalanalyzers/tests/andanalyzer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
import unittest
from unittest import mock

from pastepwn.analyzers import AndAnalyzer


class TestAndAnalyzer(unittest.TestCase):
def setUp(self):
self.obj = mock.Mock()
self.gt = mock.Mock()
self.gt.match = mock.Mock(return_value=True)

self.gf = mock.Mock()
self.gf.match = mock.Mock(return_value=False)

def test_match_positive(self):
self.obj.body = "Test"
analyzer = AndAnalyzer(None, [self.gt])
self.assertTrue(analyzer.match(self.obj))

analyzer = AndAnalyzer(None, [self.gt, self.gt, self.gt])
self.assertTrue(analyzer.match(self.obj))

# Check if the analyzer returns false if there is at least one false result
analyzer = AndAnalyzer([], [self.gt, self.gf])
self.assertFalse(analyzer.match(self.obj))

analyzer = AndAnalyzer([], [self.gf, self.gf])
self.assertFalse(analyzer.match(self.obj))

analyzer = AndAnalyzer([], [self.gf, self.gf, self.gf, self.gt])
self.assertFalse(analyzer.match(self.obj))

def test_negative(self):
self.obj.body = ""

analyzer = AndAnalyzer([], None)
self.assertFalse(analyzer.match(self.obj))

analyzer = AndAnalyzer([], [])
self.assertFalse(analyzer.match(self.obj))

def test_actions_present(self):
analyzer = AndAnalyzer(self.obj, None)
self.assertEqual([self.obj], analyzer.actions)

def test_analyzers_present(self):
analyzer = AndAnalyzer(None, self.obj)
self.assertEqual([self.obj], analyzer.analyzers)


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
import unittest
from unittest import mock

from pastepwn.analyzers.logicalanalyzers import LogicalBaseAnalyzer


class TestLogicalBaseAnalyzer(unittest.TestCase):
def setUp(self):
self.obj = mock.Mock()

def test_exception(self):
analyzer = LogicalBaseAnalyzer([], [])
self.assertRaises(NotImplementedError, analyzer.match, mock.Mock())

def test_actions_present(self):
analyzer = LogicalBaseAnalyzer(self.obj, None)
self.assertEqual([self.obj], analyzer.actions)

def test_analyzers_present(self):
analyzer = LogicalBaseAnalyzer(None, self.obj)
self.assertEqual([self.obj], analyzer.analyzers)

def test_merge_actions(self):
action1 = mock.Mock()
action2 = mock.Mock()
action3 = mock.Mock()

analyzer1 = mock.Mock()
analyzer1.actions = [action1, action2]
analyzer2 = mock.Mock()
analyzer2.actions = [action3]

analyzer = LogicalBaseAnalyzer(analyzers=[analyzer1, analyzer2], actions=[], merge_actions=True)
self.assertEqual(3, len(analyzer.actions), "Wrong amount of actions in LogicalBaseAnalyzer!")
self.assertEqual([action1, action2, action3], analyzer.actions, "Actions do not match!")


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 9cf20ce

Please sign in to comment.