Skip to content

Commit

Permalink
Merge pull request #105 from mikek2/steam-keys
Browse files Browse the repository at this point in the history
Added steam key analyzer
fixes #96
  • Loading branch information
d-Rickyy-b authored Oct 6, 2019
2 parents cf40629 + 2e6194b commit 1806078
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pastepwn/analyzers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .dbconnstringanalyzer import DBConnAnalyzer
from .privatekeyanalyzer import PrivateKeyAnalyzer
from .phonenumberanalyzer import PhoneNumberAnalyzer
from .steamkeyanalyzer import SteamKeyAnalyzer

__all__ = (
'AlwaysTrueAnalyzer',
Expand All @@ -34,5 +35,6 @@
'DatabaseDumpAnalyzer',
'DBConnAnalyzer',
'PrivateKeyAnalyzer',
'PhoneNumberAnalyzer'
'PhoneNumberAnalyzer',
'SteamKeyAnalyzer'
)
13 changes: 13 additions & 0 deletions pastepwn/analyzers/steamkeyanalyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from .regexanalyzer import RegexAnalyzer


class SteamKeyAnalyzer(RegexAnalyzer):
"""
Analyzer to match steam keys via regex
"""
name = "SteamKeyAnalyzer"

def __init__(self, actions):
regex = r"\b[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}\b"
super().__init__(actions, regex)
57 changes: 57 additions & 0 deletions pastepwn/analyzers/tests/steamkeyanalyzer_test.py
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.steamkeyanalyzer import SteamKeyAnalyzer


class TestSteamKeyAnalyzer(unittest.TestCase):
def setUp(self):
self.analyzer = SteamKeyAnalyzer(None)
self.paste = mock.Mock()

def test_match_positive(self):
"""Test if positives are recognized"""
# steam key dump
self.paste.body = "EZFNY-7GECB-94WRD"
self.assertTrue(self.analyzer.match(self.paste))

# steam key dump
self.paste.body = "10NL7-7E8VK-ZUSOD"
self.assertTrue(self.analyzer.match(self.paste))

# steam key dump
self.paste.body = "CB6AW-XHHB1-IANNO"
self.assertTrue(self.analyzer.match(self.paste))

# steam key dump
self.paste.body = "E4XJ8-2MRI0-RX4I5"
self.assertTrue(self.analyzer.match(self.paste))

# part of a sentence
self.paste.body = "Hey, I have your key right here: EL0SY-DC710-X0C5W!"
self.assertTrue(self.analyzer.match(self.paste))

# Newline seperated steam key
self.paste.body = "E4XJ8-2MRI0-RX4I5\nCIZ36-WD38P-QZI6U"
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 = "CBCB6AW-XHHB1-IANNO"
self.assertFalse(self.analyzer.match(self.paste))

# Lower-case
self.paste.body = "e4xj8-2mri0-rx4i5"
self.assertFalse(self.analyzer.match(self.paste))


if __name__ == '__main__':
unittest.main()

0 comments on commit 1806078

Please sign in to comment.