-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add gcp api key analyzer * add gcp api key analyzer
- Loading branch information
1 parent
b010cb5
commit 635a5e4
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
from .regexanalyzer import RegexAnalyzer | ||
|
||
|
||
class GoogleApiKeyAnalyzer(RegexAnalyzer): | ||
|
||
def __init__(self, actions): | ||
# https://cloud.google.com/docs/authentication/api-keys | ||
regex = r"\bAIza[0-9A-Za-z_-]{35}\b" | ||
super().__init__(actions, regex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.googleapikeyanalyzer import GoogleApiKeyAnalyzer | ||
|
||
|
||
class TestGoogleApiKeyAnalyzer(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.analyzer = GoogleApiKeyAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
"""Test if positives are recognized""" | ||
# google key dump | ||
self.paste.body = "AIzaSyCTmst6SvsOAQanZKNt-2pt6nuLoFf2kSA" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# google key dump | ||
self.paste.body = "AIzaSyBKNst9JE89f4lHuNXQFTUgZKh8VZpvR6M" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# google key dump | ||
self.paste.body = "AIzammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# google key dump | ||
self.paste.body = "AIza00000000000000000000000000000000000" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# key in the middle of a string | ||
self.paste.body = "api key: AIza00000000000000000000000000000000000" | ||
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 start | ||
self.paste.body = "aiza00000000000000000000000000000000000" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Invalid start | ||
self.paste.body = "000000000000000000000000000000000000000" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Invalid length | ||
self.paste.body = "AIzammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Invalid length | ||
self.paste.body = "AIzammmmmmmmm" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |