Skip to content

Commit

Permalink
Merge pull request #140 from Ideneal/GoogleOAuthKeyAnalyzer
Browse files Browse the repository at this point in the history
Implemented Google OAuth Key Analyzer
  • Loading branch information
d-Rickyy-b committed Oct 8, 2019
2 parents 4951f2f + 67bddc6 commit 6c87802
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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 .googleoauthkeyanalyzer import GoogleOAuthKeyAnalyzer
from .slackwebhookanalyzer import SlackWebhookAnalyzer

__all__ = (
Expand Down Expand Up @@ -59,5 +60,6 @@
'EmailPasswordPairAnalyzer',
'FacebookAccessTokenAnalyzer',
'Base64Analyzer',
'GoogleOAuthKeyAnalyzer',
'SlackWebhookAnalyzer'
)
8 changes: 8 additions & 0 deletions pastepwn/analyzers/googleoauthkeyanalyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .regexanalyzer import RegexAnalyzer


class GoogleOAuthKeyAnalyzer(RegexAnalyzer):

def __init__(self, actions):
regex = r"[0-9]+-[0-9A-Za-z_]{32}\.apps\.googleusercontent\.com"
super().__init__(actions, regex)
57 changes: 57 additions & 0 deletions pastepwn/analyzers/tests/googleoauthkeyanalyzer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import unittest
from unittest import mock

from pastepwn.analyzers.googleoauthkeyanalyzer import GoogleOAuthKeyAnalyzer


class TestGoogleOAuthKeyAnalyzer(unittest.TestCase):

def setUp(self):
self.analyzer = GoogleOAuthKeyAnalyzer(None)
self.paste = mock.Mock()

def test_match_positive(self):
"""Test if positives are recognized"""
# google key dump
self.paste.body = "6243-jhgcawesuycgaweiufyugfaiwyesfbaw.apps.googleusercontent.com"
self.assertTrue(self.analyzer.match(self.paste))

# google key dump
self.paste.body = "6243-IUFHERIUFHASOEIRUFGHDOZIFUGVDHSF.apps.googleusercontent.com"
self.assertTrue(self.analyzer.match(self.paste))

# google key dump
self.paste.body = "6243-18723612873612873621367128736128.apps.googleusercontent.com"
self.assertTrue(self.analyzer.match(self.paste))

# google key dump
self.paste.body = "1-jhgcawesuycgaweiufyugfaiwyesfbaw.apps.googleusercontent.com"
self.assertTrue(self.analyzer.match(self.paste))

# google key dump
self.paste.body = "6242345234234234234234234233-jhgcawesuycgaweiufyugfaiwyesfbaw.apps.googleusercontent.com"
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 length
self.paste.body = "6243-jhgcawesuycgaweiufyugfaisfbaw.apps.googleusercontent.com"
self.assertFalse(self.analyzer.match(self.paste))

# Invalid numbers
self.paste.body = "-jhgcawesuycgaweiufyugfaiwyesfbaw.apps.googleusercontent.com"
self.assertFalse(self.analyzer.match(self.paste))

# Invalid domain
self.paste.body = "6243-jhgcawesuycgaweiufyugfaiwyesfbaw.apps.google.com"
self.assertFalse(self.analyzer.match(self.paste))


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

0 comments on commit 6c87802

Please sign in to comment.