Skip to content

Commit

Permalink
Implemented Google OAuth Key Analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ideneal committed Oct 8, 2019
1 parent bb51e3e commit fbfb8bf
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pastepwn/analyzers/__init__.py
Expand Up @@ -28,6 +28,7 @@
from .adobekeyanalyzer import AdobeKeyAnalyzer
from .facebookaccesstokenanalyzer import FacebookAccessTokenAnalyzer
from .base64analyzer import Base64Analyzer
from .googleoauthkeyanalyzer import GoogleOAuthKeyAnalyzer

__all__ = (
'AlwaysTrueAnalyzer',
Expand Down Expand Up @@ -57,5 +58,6 @@
'PrivateKeyAnalyzer',
'EmailPasswordPairAnalyzer',
'FacebookAccessTokenAnalyzer',
'Base64Analyzer'
'Base64Analyzer',
'GoogleOAuthKeyAnalyzer'
)
8 changes: 8 additions & 0 deletions pastepwn/analyzers/googleoauthkeyanalyzer.py
@@ -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
@@ -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 fbfb8bf

Please sign in to comment.