Skip to content

Commit

Permalink
Merge 732debb into bb51e3e
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmille committed Oct 8, 2019
2 parents bb51e3e + 732debb commit 6893890
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pastepwn/analyzers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .adobekeyanalyzer import AdobeKeyAnalyzer
from .facebookaccesstokenanalyzer import FacebookAccessTokenAnalyzer
from .base64analyzer import Base64Analyzer
from .awssecretkeyanalyzer import AWSSecretKeyAnalyzer

__all__ = (
'AlwaysTrueAnalyzer',
Expand Down Expand Up @@ -57,5 +58,6 @@
'PrivateKeyAnalyzer',
'EmailPasswordPairAnalyzer',
'FacebookAccessTokenAnalyzer',
'Base64Analyzer'
'Base64Analyzer',
'AWSSecretKeyAnalyzer'
)
2 changes: 2 additions & 0 deletions pastepwn/analyzers/adobekeyanalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def __init__(self, action):
:param action: Single action or list of actions to be executed when a paste matches
"""
# Tested Regex against https://pastebin.com/fxWBGf8t

regex = r"\b(?<!-)[0-9]{4}(-[0-9]{4}){5}\b(?!-)"


super().__init__(action, regex)
15 changes: 15 additions & 0 deletions pastepwn/analyzers/awssecretkeyanalyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from .regexanalyzer import RegexAnalyzer


class AWSSecretKeyAnalyzer(RegexAnalyzer):
"""
Analyzer to match AWS Secret Key via regex
Keys are 40 character alphanumeric with a few symbols /+=
"""
name = "AWSSecretKeyAnalyzer"

def __init__(self, actions):
regex = r"\b[A-Za-z0-9/+=]{40}\b"
super().__init__(actions, regex)
2 changes: 2 additions & 0 deletions pastepwn/analyzers/md5hashanalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ class MD5HashAnalyzer(RegexAnalyzer):
name = "MD5HashAnalyzer"

def __init__(self, actions):

regex = r"\b(?<!-)[a-f0-9]{32}\b(?!-)"

super().__init__(actions, regex)
65 changes: 65 additions & 0 deletions pastepwn/analyzers/tests/awssecretkeyanalyzer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
import unittest
from unittest import mock

from pastepwn.analyzers.awssecretkeyanalyzer import AWSSecretKeyAnalyzer


class TestAWSSecretKeyAnalyzer(unittest.TestCase):
def setUp(self):
self.analyzer = AWSSecretKeyAnalyzer(None)
self.paste = mock.Mock()

def test_match_positive(self):
"""Test if positives are recognized"""
# obtained by pastebin search
self.paste.body = "HrNMIhjZDnvkH5YGJpwjq0Flmj8H+dvURedLRjsO"
self.assertTrue(self.analyzer.match(self.paste))

# obtained by pastebin search
self.paste.body = "ZGBMmoyRxdhMObx0EuANS9FiS2kG5FwDVLH2XY7y"
self.assertTrue(self.analyzer.match(self.paste))

# obtained by pastebin search
self.paste.body = "kYKQ24NoNtmga55G7OVeY/kPAZ7xONl6FfmuXArc"
self.assertTrue(self.analyzer.match(self.paste))

# obtained by pastebin search
self.paste.body = "9cf95dacd226dcf43da376cdb6cbba7035218921"
self.assertTrue(self.analyzer.match(self.paste))

self.paste.body = "my super cool hash is 9cf95dacd226dcf43da376cdb6cbba7035218921 and here's some more text"
self.assertTrue(self.analyzer.match(self.paste))

self.paste.body = "AWS Secret Access Key [None]: HrNMIhjZDnvkH5YGJpwjq0Flmj8H+dvURedLRjsO"
self.assertTrue(self.analyzer.match(self.paste))

# Newline-separated valid hashes
self.paste.body = "ZGBMmoyRxdhMObx0EuANS9FiS2kG5FwDVLH2XY7y\nHrNMIhjZDnvkH5YGJpwjq0Flmj8H+dvURedLRjsO"
self.assertTrue(self.analyzer.match(self.paste))

def test_match_negative(self):
"""Test if negatives are not recognized"""
self.paste.body = ""
self.assertFalse(self.analyzer.match(self.paste))

self.paste.body = None
self.assertFalse(self.analyzer.match(self.paste))

# Invalid character '-'
self.paste.body = "9cf95dacd226dcf43da376cdb6cbb-7035218921"
self.assertFalse(self.analyzer.match(self.paste))

# MD5 Hash
self.paste.body = "9e107d9d372bb6826bd81d3542a419d6"
self.assertFalse(self.analyzer.match(self.paste))

# Invalid length
self.paste.body = "ZGBMmoyRxdhMObx0EuANS9FiS2kG5FwDVLH2XY7y1"
self.assertFalse(self.analyzer.match(self.paste))
self.paste.body = "ZGBMmoyRxdhMObx0EuANS9FiS2kG5FwDVLH2XY7"
self.assertFalse(self.analyzer.match(self.paste))


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

0 comments on commit 6893890

Please sign in to comment.