def setUp(self): rand_text = list() for _ in range(3): rand_text.append(''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8))) p = {"scrape_url": "https://scrape.pastebin.com/api_scrape_item.php?i=" + rand_text[0], "full_url": "https://pastebin.com/" + rand_text[0], "date": "1442911802", "key": rand_text[0], "size": "890", "expire": "1442998159", "title": "Once we all know when we goto function", "syntax": "java", "user": "******", "body": rand_text[1:], } self.p = p self.paste = Paste(p.get("key"), p.get("title"), p.get("user"), p.get("size"), p.get("date"), p.get("expire"), p.get("syntax"), p.get("scrape_url"), p.get("full_url")) self.database = MongoDB(collectionname="pastepwn_test")
class MongoDBTest(unittest.TestCase): def setUp(self): rand_text = [] for _ in range(3): rand_text.append("".join( random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8))) p = { "scrape_url": "https://scrape.pastebin.com/api_scrape_item.php?i=" + rand_text[0], "full_url": "https://pastebin.com/" + rand_text[0], "date": "1442911802", "key": rand_text[0], "size": "890", "expire": "1442998159", "title": "Once we all know when we goto function", "syntax": "java", "user": "******", "body": rand_text[1:], } self.p = p self.paste = Paste(p.get("key"), p.get("title"), p.get("user"), p.get("size"), p.get("date"), p.get("expire"), p.get("syntax"), p.get("scrape_url"), p.get("full_url")) self.database = MongoDB(collectionname="pastepwn_test") def tearDown(self): self.database.db.drop_collection("pastepwn_test") def test_insert_same_key(self): # Insert a paste two times with the same body for body_text in self.p.get("body"): self.paste.set_body(body_text) self.database.store(self.paste) stored_paste = self.database.get(self.p.get("key")) comparison = self.p.get("body")[1] self.assertEqual(stored_paste.next().get("body"), comparison)
from pastepwn.analyzers import MailAnalyzer, WordAnalyzer from pastepwn.database import MongoDB # Setting up the logging logdir_path = os.path.dirname(os.path.abspath(__file__)) 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) # 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()