Example #1
0
    def __init__(self, database=None, proxies=None):
        self.logger = logging.getLogger(__name__)
        self.database = database
        self.paste_queue = Queue()
        self.action_queue = Queue()
        self.__exception_event = Event()
        self.__request = Request(proxies)  # initialize singleton

        # Usage of ipify to get the IP - Uses the X-Forwarded-For Header which might
        # lead to issues with proxies
        ip = self.__request.get("https://api.ipify.org")
        self.logger.info("Your public IP is {0}".format(ip))

        self.scraping_handler = ScrapingHandler(paste_queue=self.paste_queue,
                                                exception_event=self.__exception_event)
        self.paste_dispatcher = PasteDispatcher(paste_queue=self.paste_queue,
                                                action_queue=self.action_queue,
                                                exception_event=self.__exception_event)
        self.action_handler = ActionHandler(action_queue=self.action_queue,
                                            exception_event=self.__exception_event)

        if self.database is not None:
            # Save every paste to the database with the AlwaysTrueAnalyzer
            self.logger.info("Database provided! Storing pastes in there.")
            database_action = DatabaseAction(self.database)
            always_true = AlwaysTrueAnalyzer(database_action)
            self.add_analyzer(always_true)
        else:
            self.logger.info("No database provided!")
Example #2
0
    def __init__(self,
                 database=None,
                 proxies=None,
                 store_all_pastes=True,
                 ip_version=None):
        """
        Basic PastePwn object handling the connection to pastebin and all the analyzers and actions
        :param database: Database object extending AbstractDB
        :param proxies: Dict of proxies as defined in the requests documentation
        :param store_all_pastes: Bool to decide if all pastes should be stored into the db
        :param ip_version: The IP version pastepwn should use (4|6)
        """
        self.logger = logging.getLogger(__name__)
        self.is_idle = False
        self.database = database
        self.paste_queue = Queue()
        self.action_queue = Queue()
        self.error_handlers = []
        self.onstart_handlers = []
        self.__exception_event = Event()
        self.__request = Request(proxies)  # initialize singleton

        # We are trying to enforce a certain version of the Internet Protocol
        enforce_ip_version(ip_version)

        # Usage of ipify to get the IP - Uses the X-Forwarded-For Header which might
        # lead to issues with proxies
        try:
            ip = self.__request.get("https://api.ipify.org")
        except Exception as e:
            ip = None
            self.logger.warning(
                "Could not fetch public IP via ipify: {0}".format(e))

        if ip:
            self.logger.info("Your public IP is {0}".format(ip))

        self.scraping_handler = ScrapingHandler(
            paste_queue=self.paste_queue,
            exception_event=self.__exception_event)
        self.paste_dispatcher = PasteDispatcher(
            paste_queue=self.paste_queue,
            action_queue=self.action_queue,
            exception_event=self.__exception_event)
        self.action_handler = ActionHandler(
            action_queue=self.action_queue,
            exception_event=self.__exception_event)

        if self.database is not None and store_all_pastes:
            # Save every paste to the database with the AlwaysTrueAnalyzer
            self.logger.info("Database provided! Storing pastes in there.")
            database_action = DatabaseAction(self.database)
            always_true = AlwaysTrueAnalyzer(database_action)
            self.add_analyzer(always_true)
        elif store_all_pastes:
            self.logger.info("No database provided!")
        else:
            self.logger.info("Not storing all pastes!")