-
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.
- Loading branch information
Showing
3 changed files
with
79 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,16 @@ | ||
# -*- coding: utf-8 -*- | ||
from .regexanalyzer import RegexAnalyzer | ||
|
||
|
||
class AzureSubscriptionKeyAnalyzer(RegexAnalyzer): | ||
""" | ||
Analyzer to match Azure subscription key via regex | ||
Keys are 32 character alphanumeric (lower case) | ||
""" | ||
name = "AzureSubscriptionKeyAnalyzer" | ||
|
||
def __init__(self, actions): | ||
# https://docs.microsoft.com/en-us/azure/api-management/api-management-subscriptions | ||
regex = r"\b[a-f0-9]{32}\b" | ||
super().__init__(actions, regex) |
61 changes: 61 additions & 0 deletions
61
pastepwn/analyzers/tests/azuresubscriptionkeyanalyzer_test.py
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.azuresubscriptionkeyanalyzer import AzureSubscriptionKeyAnalyzer | ||
|
||
|
||
class TestAzureSubscriptionKeyAnalyzer(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.analyzer = AzureSubscriptionKeyAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
"""Test if positives are recognized""" | ||
# google key dump | ||
self.paste.body = "74796abfc83c49bba7458746266abd28" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# google key dump | ||
self.paste.body = "00000000000000000000000000000000" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# google key dump | ||
self.paste.body = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# google key dump | ||
self.paste.body = "a32324343543bcdea32324343543bcde" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# key appearing in the middle of a string | ||
self.paste.body = "my azure key is: a32324343543bcdea32324343543bcde, aaaa" | ||
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 characters | ||
self.paste.body = "aaaaaaaaaaaaaaa-aaaaaaaaaaaaaaaa" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Invalid casing | ||
self.paste.body = "AAAAAAAABBBB11111111111111111111" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Invalid length | ||
self.paste.body = "AAAAAAAAAA" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Invalid length | ||
self.paste.body = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |