How to use the pastepwn.analyzers.basicanalyzer.BasicAnalyzer function in pastepwn

To help you get started, we’ve selected a few pastepwn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github d-Rickyy-b / pastepwn / pastepwn / analyzers / wordanalyzer.py View on Github external
# -*- coding: utf-8 -*-
from .basicanalyzer import BasicAnalyzer


class WordAnalyzer(BasicAnalyzer):
    """Analyzer to match the content of a paste by words"""
    name = "WordAnalyzer"

    def __init__(self, actions, words, blacklist=None, case_sensitive=False):
        super().__init__(actions, "{0} ({1})".format(self.name, words))

        if words is None:
            self.words = []
        elif isinstance(words, list):
            self.words = words
        else:
            self.words = [words]

        self.blacklist = blacklist or []
        self.case_sensitive = case_sensitive
github d-Rickyy-b / pastepwn / pastepwn / analyzers / regexanalyzer.py View on Github external
# -*- coding: utf-8 -*-
import re

from .basicanalyzer import BasicAnalyzer


class RegexAnalyzer(BasicAnalyzer):
    """Analyzer to match the content of a paste via regular expressions"""
    name = "RegexAnalyzer"

    def __init__(self, actions, regex, flags=0):
        super().__init__(actions)
        self.regex = re.compile(regex, flags)

    def match(self, paste):
        """Match the content of a paste via regex. Return true if regex matches"""
        if paste is None:
            return False

        paste_content = paste.body or ""
        return self.regex.search(paste_content) is not None
github d-Rickyy-b / pastepwn / pastepwn / analyzers / pastetitleanalyzer.py View on Github external
# -*- coding: utf-8 -*-
import re

from .basicanalyzer import BasicAnalyzer


class PasteTitleAnalyzer(BasicAnalyzer):
    """Analyzer to match Paste titles via regex"""
    name = "PasteTitleAnalyzer"

    def __init__(self, actions, regex, flags=0, blacklist=None):
        super().__init__(actions, self.name)
        self.regex = re.compile(regex, flags)
        self.blacklist = blacklist or []

    def match(self, paste):
        """Match the title of a paste via regex. Return true if regex matches"""
        paste_title = paste.title or ""
        return self.regex.findall(paste_title)
github d-Rickyy-b / pastepwn / pastepwn / analyzers / alwaystrueanalyzer.py View on Github external
# -*- coding: utf-8 -*-
from .basicanalyzer import BasicAnalyzer


class AlwaysTrueAnalyzer(BasicAnalyzer):
    """Analyzer which always matches a paste to perform actions on every paste"""
    name = "AlwaysTrueAnalyzer"

    def __init__(self, action):
        super().__init__(action)

    def match(self, paste):
        """Always returns True to match every paste available"""
        return True
github d-Rickyy-b / pastepwn / pastepwn / analyzers / basicanalyzer.py View on Github external
self.logger.error(error_msg)
            raise InvalidActionError(error_msg)

    def __and__(self, other):
        return MergedAnalyzer(self, and_analyzer=other)

    def __or__(self, other):
        return MergedAnalyzer(self, or_analyzer=other)

    def __repr__(self):
        if self.identifier is None:
            self.identifier = self.__class__.__name__
        return self.identifier


class MergedAnalyzer(BasicAnalyzer):
    """
    Combination class to combine multiple analyzers into a single one
    Doesn't need to be created manually - use the binary operators (& and |) to combine multiple analyzers.
    """
    name = "MergedAnalyzer"

    def __init__(self, base_analyzer, and_analyzer=None, or_analyzer=None):
        self._base_analyzer = base_analyzer
        self._and_analyzer = and_analyzer
        self._or_analyzer = or_analyzer

        if self._and_analyzer:
            actions = base_analyzer.actions + self._and_analyzer.actions
            identifier = "({} && {})".format(base_analyzer.identifier, self._and_analyzer)
        elif self._or_analyzer:
            actions = base_analyzer.actions + self._or_analyzer.actions
github d-Rickyy-b / pastepwn / pastepwn / analyzers / urlanalyzer.py View on Github external
# -*- coding: utf-8 -*-
import re
import urllib.error
import urllib.request

from .basicanalyzer import BasicAnalyzer


class URLAnalyzer(BasicAnalyzer):
    """
    This analyzer detects url-like patterns using regex,
    and then optionally attempts to verify that they can
    be resolved.
    """
    name = "URLAnalyzer"

    def __init__(self, actions, regex, resolve=False):
        super().__init__(actions, regex)
        self.regex = re.compile(regex)
        self.resolve = resolve  # Should we try to resolve the URLs?

    def _resolve_url(self, url):
        """
        A helper method that tries to resolve a given URL.
        Returns False if the URL cannot be resolved.
github d-Rickyy-b / pastepwn / pastepwn / analyzers / genericanalyzer.py View on Github external
# -*- coding: utf-8 -*-
import logging

from .basicanalyzer import BasicAnalyzer


class GenericAnalyzer(BasicAnalyzer):
    """Analyzer to pass a function pointer to, in order to create an analyzer on the fly"""
    name = "GenericAnalyzer"

    def __init__(self, actions, match_func):
        super().__init__(actions)

        if match_func is None:
            raise ValueError("Function to be called cannot be None")
        elif not callable(match_func):
            raise ValueError("Function you provided isn't callable")

        self.match_func = match_func

    def match(self, paste):
        """Run the passed function and return its return value"""
        try: