Skip to content

Commit

Permalink
[ponicode-pull-request] Ponicode wrote new docstrings!
Browse files Browse the repository at this point in the history
  • Loading branch information
Ponicode-bot committed Nov 5, 2020
1 parent 9b2fee2 commit 9ce67a1
Show file tree
Hide file tree
Showing 104 changed files with 1,460 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pastepwn/actions/basicaction.py
Expand Up @@ -6,6 +6,12 @@ class BasicAction(object):
name = "BasicAction"

def __init__(self):
"""
Initialize the object
Args:
self: (todo): write your description
"""
pass

def perform(self, paste, analyzer_name=None, matches=None):
Expand Down
7 changes: 7 additions & 0 deletions pastepwn/actions/databaseaction.py
Expand Up @@ -7,6 +7,13 @@ class DatabaseAction(BasicAction):
name = "DatabaseAction"

def __init__(self, database):
"""
Initialize database
Args:
self: (todo): write your description
database: (str): write your description
"""
super().__init__()
self.database = database

Expand Down
12 changes: 12 additions & 0 deletions pastepwn/actions/emailaction.py
Expand Up @@ -15,6 +15,18 @@ class EmailAction(BasicAction):
name = "EmailAction"

def __init__(self, username, password, receiver, hostname, port=465, template=None):
"""
Initialize a new receiver.
Args:
self: (todo): write your description
username: (str): write your description
password: (str): write your description
receiver: (callable): write your description
hostname: (str): write your description
port: (int): write your description
template: (str): write your description
"""
super().__init__()
mail_regex = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
if username is None or not re.match(mail_regex, username):
Expand Down
16 changes: 16 additions & 0 deletions pastepwn/actions/genericaction.py
Expand Up @@ -7,8 +7,24 @@ class GenericAction(BasicAction):
name = "GenericAction"

def __init__(self, func):
"""
Initialize a function.
Args:
self: (todo): write your description
func: (callable): write your description
"""
super().__init__()
self.func = func

def perform(self, paste, analyzer_name=None, matches=None):
"""
Perform the given paste.
Args:
self: (todo): write your description
paste: (todo): write your description
analyzer_name: (str): write your description
matches: (todo): write your description
"""
self.func(paste)
17 changes: 17 additions & 0 deletions pastepwn/actions/ircaction.py
Expand Up @@ -16,6 +16,17 @@ class IrcAction(BasicAction):
name = "IrcAction"

def __init__(self, server=None, channel=None, port=6667, nick="pastepwn", template=None):
"""
Initialize the consumer.
Args:
self: (todo): write your description
server: (todo): write your description
channel: (todo): write your description
port: (int): write your description
nick: (str): write your description
template: (str): write your description
"""
super().__init__()
self.logger = logging.getLogger(__name__)
self._msg_queue = Queue()
Expand Down Expand Up @@ -204,6 +215,12 @@ def _send_message(self, msg):
self._msg_queue.put(msg)

def __del__(self):
"""
Stops the background thread.
Args:
self: (todo): write your description
"""
self._stop_event.set()
join_threads([self._thread])

Expand Down
15 changes: 15 additions & 0 deletions pastepwn/actions/logaction.py
Expand Up @@ -9,8 +9,23 @@ class LogAction(BasicAction):
name = "LogAction"

def __init__(self):
"""
Initialize the logger.
Args:
self: (todo): write your description
"""
super().__init__()
self.logger = logging.getLogger(__name__)

def perform(self, paste, analyzer_name=None, matches=None):
"""
Perform the given paste.
Args:
self: (todo): write your description
paste: (todo): write your description
analyzer_name: (str): write your description
matches: (todo): write your description
"""
self.logger.debug("New Paste matched: {0}".format(paste))
7 changes: 7 additions & 0 deletions pastepwn/actions/mispaction.py
Expand Up @@ -45,6 +45,13 @@ def __init__(self, url, access_key, transformer=None, attributes=None):

@staticmethod
def default_transformer(paste, analyzer_name=None):
"""
Create a default transformer
Args:
paste: (str): write your description
analyzer_name: (str): write your description
"""
timestamp = time.gmtime(int(paste.date))
attrs = []
# Build event
Expand Down
7 changes: 7 additions & 0 deletions pastepwn/actions/savejsonaction.py
Expand Up @@ -10,6 +10,13 @@ class SaveJSONAction(SaveFileAction):
name = "SaveJSONAction"

def __init__(self, path):
"""
Initialize the specified path.
Args:
self: (todo): write your description
path: (str): write your description
"""
super().__init__(path)

def perform(self, paste, analyzer_name=None, matches=None):
Expand Down
11 changes: 11 additions & 0 deletions pastepwn/actions/twitteraction.py
Expand Up @@ -20,6 +20,17 @@ def __init__(
access_token_secret=None,
template=None,
):
"""
Initialize a new token.
Args:
self: (todo): write your description
consumer_key: (str): write your description
consumer_secret: (str): write your description
access_token_key: (str): write your description
access_token_secret: (str): write your description
template: (str): write your description
"""
super().__init__()

self.logger = logging.getLogger(__name__)
Expand Down
7 changes: 7 additions & 0 deletions pastepwn/analyzers/awsaccesskeyanalyzer.py
Expand Up @@ -11,6 +11,13 @@ class AWSAccessKeyAnalyzer(RegexAnalyzer):
name = "AWSAccessKeyAnalyzer"

def __init__(self, actions):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
"""
# https://people.eecs.berkeley.edu/~rohanpadhye/files/key_leaks-msr15.pdf
regex = r"\b(?:A3T[A-Z0-9]|AKIA|AGPA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}\b"
super().__init__(actions, regex)
7 changes: 7 additions & 0 deletions pastepwn/analyzers/awssecretkeyanalyzer.py
Expand Up @@ -11,5 +11,12 @@ class AWSSecretKeyAnalyzer(RegexAnalyzer):
name = "AWSSecretKeyAnalyzer"

def __init__(self, actions):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
"""
regex = r"\b[A-Za-z0-9/+=]{40}\b"
super().__init__(actions, regex)
7 changes: 7 additions & 0 deletions pastepwn/analyzers/awssessiontokenanalyzer.py
Expand Up @@ -9,5 +9,12 @@ class AWSSessionTokenAnalyzer(RegexAnalyzer):
name = "AWSSessionTokenAnalyzer"

def __init__(self, actions):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
"""
regex = r"(?:(?:\\\"|'|`)?(?:i?aws)?_?(?:i?session)?_?(?:i?token)?(?:\\\"|'|`)?\\\\s{0,50}(?::|=>|=)\\\\s{0,50}(?:\\\"|'|`)?[A-Za-z0-9/+=]{16,}(?:\\\"|'|`)?)"
super().__init__(actions, regex)
7 changes: 7 additions & 0 deletions pastepwn/analyzers/azuresubscriptionkeyanalyzer.py
Expand Up @@ -11,6 +11,13 @@ class AzureSubscriptionKeyAnalyzer(RegexAnalyzer):
name = "AzureSubscriptionKeyAnalyzer"

def __init__(self, actions):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
"""
# https://docs.microsoft.com/en-us/azure/api-management/api-management-subscriptions
regex = r"\b[a-f0-9]{32}\b"
super().__init__(actions, regex)
8 changes: 8 additions & 0 deletions pastepwn/analyzers/base64analyzer.py
Expand Up @@ -7,6 +7,14 @@ class Base64Analyzer(RegexAnalyzer):
name = "Base64Analyzer"

def __init__(self, actions, min_len=1):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
min_len: (int): write your description
"""
regex = r"(?<![A-Za-z0-9+\/=])(?:[A-Za-z0-9+\/]{4})+(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?(?![A-Za-z0-9+\/=])"
self.min_len = min_len
super().__init__(actions, regex)
Expand Down
9 changes: 9 additions & 0 deletions pastepwn/analyzers/base64asciianalyzer.py
Expand Up @@ -9,6 +9,15 @@ class Base64AsciiAnalyzer(Base64Analyzer):
name = 'Base64AsciiAnalyzer'

def __init__(self, actions, min_len=1, decode=False):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
min_len: (int): write your description
decode: (str): write your description
"""
super().__init__(actions, min_len)
self.decode = decode

Expand Down
29 changes: 29 additions & 0 deletions pastepwn/analyzers/basicanalyzer.py
Expand Up @@ -54,12 +54,32 @@ def _check_action(self, action):
raise InvalidActionError(error_msg)

def __and__(self, other):
"""
Return a new dstream with the same elements.
Args:
self: (todo): write your description
other: (todo): write your description
"""
return MergedAnalyzer(self, and_analyzer=other)

def __or__(self, other):
"""
Shared version of self is_analyzer.
Args:
self: (todo): write your description
other: (todo): write your description
"""
return MergedAnalyzer(self, or_analyzer=other)

def __repr__(self):
"""
Return a unique identifier for a class.
Args:
self: (todo): write your description
"""
if self.identifier is None:
self.identifier = self.__class__.__name__
return self.identifier
Expand All @@ -73,6 +93,15 @@ class MergedAnalyzer(BasicAnalyzer):
name = "MergedAnalyzer"

def __init__(self, base_analyzer, and_analyzer=None, or_analyzer=None):
"""
Initialize the action.
Args:
self: (todo): write your description
base_analyzer: (todo): write your description
and_analyzer: (todo): write your description
or_analyzer: (todo): write your description
"""
self._base_analyzer = base_analyzer
self._and_analyzer = and_analyzer
self._or_analyzer = or_analyzer
Expand Down
7 changes: 7 additions & 0 deletions pastepwn/analyzers/battlenetkeyanalyzer.py
Expand Up @@ -9,6 +9,13 @@ class BattleNetKeyAnalyzer(RegexAnalyzer):
name = "BattleNetKeyAnalyzer"

def __init__(self, actions):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
"""
# 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)
7 changes: 7 additions & 0 deletions pastepwn/analyzers/bcrypthashanalyzer.py
Expand Up @@ -7,5 +7,12 @@ class BcryptHashAnalyzer(RegexAnalyzer):
name = "BcryptHashAnalyzer"

def __init__(self, actions):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
"""
regex = r"\$2[ayb]\$[\d]{2}\$[./A-Za-z0-9]{53}"
super().__init__(actions, regex)
7 changes: 7 additions & 0 deletions pastepwn/analyzers/dbconnstringanalyzer.py
Expand Up @@ -7,6 +7,13 @@ class DBConnAnalyzer(RegexAnalyzer):
name = "DBConnAnalyzer"

def __init__(self, actions):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
"""
# https:// should be ignored
regex = r"(\b(?!http(?:s)?\b)\w+[a-zA-Z]+:\/\/[a-zA-z0-9.:,\-@]+)"
super().__init__(actions, regex)
8 changes: 8 additions & 0 deletions pastepwn/analyzers/emailpasswordpairanalyzer.py
Expand Up @@ -9,6 +9,14 @@ class EmailPasswordPairAnalyzer(RegexAnalyzer):
name = "EmailPasswordPairAnalyzer"

def __init__(self, actions, min_amount=0):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
min_amount: (int): write your description
"""
super().__init__(actions, _EMAIL_PASSWORD_REGEX)
self.min_amount = min_amount

Expand Down
9 changes: 9 additions & 0 deletions pastepwn/analyzers/genericanalyzer.py
Expand Up @@ -9,6 +9,15 @@ class GenericAnalyzer(BasicAnalyzer):
name = "GenericAnalyzer"

def __init__(self, actions, match_func, verify_func=None):
"""
Initialize the actions.
Args:
self: (todo): write your description
actions: (todo): write your description
match_func: (todo): write your description
verify_func: (todo): write your description
"""
super().__init__(actions)

if match_func is None:
Expand Down
7 changes: 7 additions & 0 deletions pastepwn/analyzers/googleapikeyanalyzer.py
Expand Up @@ -6,6 +6,13 @@ class GoogleApiKeyAnalyzer(RegexAnalyzer):
"""Analyzer that matches Google API Keys via regex"""

def __init__(self, actions):
"""
Initialize actions.
Args:
self: (todo): write your description
actions: (todo): write your description
"""
# https://cloud.google.com/docs/authentication/api-keys
regex = r"\bAIza[0-9A-Za-z_-]{35}\b"
super().__init__(actions, regex)

0 comments on commit 9ce67a1

Please sign in to comment.