-
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
66 additions
and
1 deletion.
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,14 @@ | ||
# -*- coding: utf-8 -*- | ||
from .regexanalyzer import RegexAnalyzer | ||
|
||
|
||
class BattleNetKeyAnalyzer(RegexAnalyzer): | ||
""" | ||
Analyzer to match battle.net keys via regex | ||
""" | ||
name = "BattleNetKeyAnalyzer" | ||
|
||
def __init__(self, actions): | ||
# battle.net activation page shows 4-4-4-4 format, but there are also codes in the 4-4-5-4-4 format which work | ||
regex = r"\b([A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}|[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{5}\-[A-Z0-9]{4}\-[A-Z0-9]{4})\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,49 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
from unittest import mock | ||
|
||
from pastepwn.analyzers.battlenetkeyanalyzer import BattleNetKeyAnalyzer | ||
|
||
|
||
class TestBattleNetKeyAnalyzer(unittest.TestCase): | ||
def setUp(self): | ||
self.analyzer = BattleNetKeyAnalyzer(None) | ||
self.paste = mock.Mock() | ||
|
||
def test_match_positive(self): | ||
"""Test if positives are recognized""" | ||
# working battlenet key in 4-4-5-4-4 format | ||
self.paste.body = "NGM5-XB9P-8TLTR-V8BH-QFSW" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# key in 4-4-4-4 format | ||
self.paste.body = "MB9C-LV3C-4RG8-FME8" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# part of a sentence | ||
self.paste.body = "Hey, I have your key right here: MB9C-LV3C-4RG8-FME8!" | ||
self.assertTrue(self.analyzer.match(self.paste)) | ||
|
||
# Newline seperated keys | ||
self.paste.body = "MB9C-LV3C-4RG8-FME8\nNGM5-XB9P-8TLTR-V8BH-QFSW" | ||
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 = "MB9AC-LV3C-4RG8-FME8" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
# Lower-case | ||
self.paste.body = "mb9c-lv3c-4rg8-fme8" | ||
self.assertFalse(self.analyzer.match(self.paste)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |