class TestPastebinscraper(unittest.TestCase): def setUp(self) -> None: self.pastebinscraper = PastebinScraper() def test_empty(self): with self.assertRaises(PasteEmptyException): self.pastebinscraper._check_error("") def test_not_ready(self): with self.assertRaises(PasteNotReadyException): self.pastebinscraper._check_error( "File is not ready for scraping yet. Try again in 1 minute.") def test_deleted(self): with self.assertRaises(PasteDeletedException): self.pastebinscraper._check_error( "Error, we cannot find this paste.") def _check_ip_not_registered(self, ip_list): shell = "YOUR IP: {} DOES NOT HAVE ACCESS. VISIT: https://pastebin.com/doc_scraping_api TO GET ACCESS!" for ip in ip_list: with self.assertRaises(IPNotRegisteredError): self.pastebinscraper._check_error(shell.format(ip)) print("The following IP was not detected: {}".format(ip)) def test_ipv4_not_registered(self): """Test if the _check_error method detects different IPv4 addresses. It's okay to also detect invalid addresses where an octed is > 255)""" ipv4_test = [ "1.1.1.1", "10.1.5.6", "1.10.5.6", "1.1.50.6", "1.1.5.60", "1.1.50.60", "1.10.50.60", "10.10.50.60", "10.10.50.255", "10.10.255.255", "10.255.255.255", "255.255.255.255", "333.333.333.333" ] self._check_ip_not_registered(ipv4_test) def test_ipv6_not_registered(self): ipv6_test = [ "fe80::21d8:f50:c295:c4be", "2001:cdba:0000:0000:0000:0000:3257:9652", "2001:cdba:0:0:0:0:3257:9652", "2001:cdba::3257:9652", "2001:cdba::1222", "21DA:D3:0:2F3B:2AA:FF:FE28:9C5A", "2001:cdba::1:2:3:3257:9652", "FE80::8329", "FE80::FFFF:8329", "FE80::B3FF:FFFF:8329", "FE80::0202:B3FF:FFFF:8329", "FE80:0000:0000:0000:0202:B3FF:FFFF:8329" ] # TODO: IPv6 addresses with double colon AND full zero groups (of 16 bits) are currently not recognized by the used regex. An example address would # be: `FE80::0000:0000:0202:B3FF:FFFF:8329` self._check_ip_not_registered(ipv6_test)
def start(self): """Starts the pastepwn instance""" if self.__exception_event.is_set(): self.logger.error( "An exception occured. Aborting the start of PastePwn!") exit(1) if len(self.scraping_handler.scrapers) == 0: from pastepwn.scraping.pastebin import PastebinScraper pastebinscraper = PastebinScraper() self.add_scraper(pastebinscraper, True) self.scraping_handler.start() self.paste_dispatcher.start() self.action_handler.start()
def start(self): """Starts the pastepwn instance""" if self.__exception_event.is_set(): self.logger.error("An exception occured. Aborting the start of PastePwn!") exit(1) if len(self.scraping_handler.scrapers) == 0: from pastepwn.scraping.pastebin import PastebinScraper pastebinscraper = PastebinScraper() self.add_scraper(pastebinscraper, True) self.scraping_handler.start() self.paste_dispatcher.start() self.action_handler.start() for onstart_handler in self.onstart_handlers: try: onstart_handler() except Exception as e: self.logger.error("Onstart handler %s failed with error: %s. Pastepwn is still running." % (onstart_handler.__name__, e))
def setUp(self) -> None: self.pastebinscraper = PastebinScraper()
logfile_path = os.path.join(logdir_path, "logs", "pastepwn.log") if not os.path.exists(os.path.join(logdir_path, "logs")): os.makedirs(os.path.join(logdir_path, "logs")) logfile_handler = logging.handlers.WatchedFileHandler(logfile_path, "a", "utf-8") logger = logging.getLogger(__name__) logging.basicConfig( format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO, handlers=[logfile_handler, logging.StreamHandler()]) # Framework code database = MongoDB(ip="192.168.240.128") pastepwn = PastePwn(database) pastepwn.add_scraper(PastebinScraper()) # Generic action to send Telegram messages on new matched pastes telegram_action = TelegramAction(token="token", receiver="-1001348376474") mail_analyzer = MailAnalyzer(telegram_action) premium_analyzer = WordAnalyzer(telegram_action, "premium") pastepwn.add_analyzer(mail_analyzer) pastepwn.add_analyzer(premium_analyzer) pastepwn.start()