-
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
2 changed files
with
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
from .regexanalyzer import RegexAnalyzer | ||
|
||
|
||
class EpicKeyAnalyzer(RegexAnalyzer): | ||
"""Analyzer to match Epic Licensing Keys""" | ||
|
||
def __init__(self, action): | ||
""" | ||
Analyzer to match Epic Licensing Keys | ||
:param action: Single action or list of actions to be executed when a paste matches | ||
""" | ||
# Applied general A-Z or 0-9 based on example provided | ||
# Regex can be adjusted if certain characters are not valid | ||
regex = r"(([A-Z0-9]{5}\-){3}([A-Z0-9]{5}))" | ||
|
||
super().__init__(action, 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,57 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.epickeyanalyzer import EpicKeyAnalyzer | ||
|
||
|
||
class TestEpicKeyAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = EpicKeyAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
"""Test if positives are recognized""" | ||
# Epic key dump | ||
self.paste.body = "1GZJQ-DW7QX-SB4DC-THDW2" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# Epic key dump | ||
self.paste.body = "KWETC-MK13P-4DO0N-VHT62" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# Epic key dump | ||
self.paste.body = "MB9KG-TGXBJ-X8OXE-J7PIF" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# Epic key dump | ||
self.paste.body = "OMYCF-Q9VYL-4FQEG-8F3XV" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# part of a sentence | ||
self.paste.body = "Look it's FORTNITE! UGCTH-FH42S-OH98G-QHFZA" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# Newline seperated Epic keys | ||
self.paste.body = "87C6Y-XIV2I-C3RJZ-B1SVZ\nQ8AQT-APT3F-MO7QU-KPE96" | ||
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 in section | ||
self.paste.body = "Q8A5QT-APFT3F-MO74QU-KPEL96" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# No separator | ||
self.paste.body = "OAPMCSEU6N7FFZ72AM5E" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |