├── LICENSE ├── README.md ├── pastemonitor.py ├── requirements.txt └── wordlist.txt /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 pixelbubble 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PasteMonitor 2 | Scrape Pastebin API to collect daily pastes, setup a wordlist and be alerted by email when you have a match. 3 | 4 | ## Description 5 | The PasteMonitor tool allows you to perform two main actions (for educational purposes only): 6 | 7 | - ### Download daily new public pastes 8 | ![image](https://user-images.githubusercontent.com/75697623/145390083-e1f8ca14-a0d1-4763-90a7-56634c87f20d.png) 9 | Average number of pastes per day: 1000-3000 (filetype: .txt) 10 | 11 | - ### Send automatic email alert 12 | You can setup a wordlist and be alerted by email when you have a match 13 | ![image](https://user-images.githubusercontent.com/75697623/145399396-e685c7c2-252b-4266-8f07-8934fab935d5.png) 14 | 15 | If your paste is no longer online, you can find it on your computer/server via the ID of your paste (here ID is "WJq2YxPg") 16 | ![image](https://user-images.githubusercontent.com/75697623/145396434-d3db83c0-4c43-4c6f-a8e1-9a57f063db25.png) 17 | 18 | ## Before start 19 | 20 | Before starting the tool, make sure to: 21 | - Get a [Pastebin PRO](https://pastebin.com/pro) account 22 | - Enter the IP address of your machine in the "[Your Account & Whitelisted IP](https://pastebin.com/doc_scraping_api)" section 23 | - Activate a mail account that can authorize a third party application (here we use a [Gmail account](https://www.google.com/intl/fr/gmail/about/)) 24 | - [Enable 2-step verification](https://myaccount.google.com/u/2/signinoptions/two-step-verification) 25 | - [Generate app password](https://myaccount.google.com/u/2/apppasswords) (for more help, see this [tutorial](https://ljmocic.medium.com/send-an-email-using-python-and-gmail-4ebc980eae9b)) 26 | 27 | Then, add to the code "pastemonitor.py": 28 | - Email credentials ("email", "password") 29 | - Email alert recipient ("receiver") 30 | 31 | ## Wordlist 32 | In the "wordlist.txt" file, add your keywords line by line. 33 | 34 | ## Prerequisite 35 | 36 | ```bash 37 | pip3 install -r requirements.txt 38 | ``` 39 | 40 | ## Usage 41 | 42 | ```bash 43 | python3 pastemonitor.py 44 | ``` 45 | 46 | ## Pastebin.com usage 47 | Visit the official Pastebin webpage [Scraping API](https://pastebin.com/doc_scraping_api). 48 | 49 | ## Contributing 50 | Feel free to clone this project. For major changes, please open an issue first to discuss what you would like to change. 51 | 52 | ## License 53 | [MIT](https://choosealicense.com/licenses/mit/) 54 | -------------------------------------------------------------------------------- /pastemonitor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | #Python libraries 4 | import requests 5 | import json 6 | import re 7 | from random import randint 8 | import os.path 9 | import time 10 | import smtplib 11 | from email.mime.text import MIMEText 12 | 13 | #Configure your personnel email account and the receiver account 14 | #From 15 | email = '' #To complete 16 | password = '' #To complete 17 | 18 | #To 19 | receiver = '' #To complete 20 | 21 | #Choose a working directory path 22 | pathDirectory = os.path.dirname(os.path.realpath(__file__)) 23 | 24 | #Color setup 25 | class bcolors: 26 | OKGREEN = '\033[92m' 27 | WARNING = '\033[93m' 28 | FAIL = '\033[91m' 29 | BOLD = '\033[1m' 30 | ENDC = '\033[0m' 31 | 32 | def printAscii(): 33 | """ 34 | ASCII Art 35 | """ 36 | print(""" 37 | ______ _ ___ ___ _ _ 38 | | ___ \ | | | \/ | (_) | 39 | | |_/ /_ _ ___| |_ ___| . . | ___ _ __ _| |_ ___ _ __ 40 | | __/ _` / __| __/ _ \ |\/| |/ _ \| '_ \| | __/ _ \| '__| 41 | | | | (_| \__ \ || __/ | | | (_) | | | | | || (_) | | 42 | \_| \__,_|___/\__\___\_| |_/\___/|_| |_|_|\__\___/|_| 43 | 44 | """) 45 | 46 | def checkPastebinAPIStatut(): 47 | """ 48 | This function check Pastebin API statut access : allowed / not allowed 49 | """ 50 | requestPastebinAPI = requests.get('https://scrape.pastebin.com/api_scraping.php') 51 | if requestPastebinAPI.status_code == 200: 52 | print(f"IP Access : Your IP address is {bcolors.OKGREEN}allowed{bcolors.ENDC} to connect to the Pastebin.com API") 53 | else: 54 | print(f"IP Access : Your IP address is {bcolors.FAIL}not allowed{bcolors.ENDC} to connect to the Pastebin.com API") 55 | print("Please visit this webpage: https://pastebin.com/doc_scraping_api ") 56 | print("Then, enter the IP address of your machine in section: 'Your Account & Whitelisted IP'") 57 | exit() 58 | 59 | def pastebinRequest(): 60 | #Create daily directory 61 | todayDate = time.strftime("%d-%m-%y") 62 | directory = todayDate 63 | if not os.path.exists(directory): 64 | os.makedirs(directory) 65 | directory = pathDirectory + "/" + todayDate 66 | 67 | #Pastebin request 68 | jsonResponse = requests.get("https://scrape.pastebin.com/api_scraping.php").json() 69 | for element in jsonResponse: 70 | scrape_url = element["scrape_url"] 71 | key = element["key"] 72 | request = requests.get(scrape_url) 73 | download = request.text 74 | filename = (str(key)+".txt") 75 | if os.path.isfile(filename) is True: 76 | pass 77 | else: 78 | savepath = directory + "/" 79 | savedPastePath = os.path.join(savepath, filename) 80 | print(savedPastePath) 81 | with open(savedPastePath, "w") as savedPasteFile: 82 | savedPasteFile.write(download) 83 | 84 | #Wordlist check 85 | with open("wordlist.txt", "r") as fd: 86 | lines = fd.read().splitlines() 87 | 88 | with open(savedPastePath, "r") as readPaste: 89 | readfile = readPaste.read() 90 | 91 | #Sending Email alert if match 92 | for line in lines: 93 | if line in readfile: 94 | subject = 'PASTEBIN ALERT' 95 | pastebinURL = re.findall("/([A-Za-z0-9]{8}).txt", str(savedPastePath)) 96 | textMessage = "This is an automatic email alert.\n We actually monitoring Pastebin and we have found a word in you wordlist (" + str(line) + ").\n You can visit the Pastebin webpage here: https://pastebin.com/" + str(''.join(pastebinURL)) 97 | message = MIMEText(textMessage) 98 | message['From'] = email 99 | message['To'] = receiver 100 | message['Subject'] = subject 101 | try: 102 | server = smtplib.SMTP_SSL('smtp.gmail.com', 465) 103 | server.ehlo() 104 | server.login(email, password ) 105 | server.sendmail(email, receiver, message.as_string()) 106 | server.close() 107 | 108 | print('Email sent!') 109 | except Exception as e: 110 | print(e) 111 | print('Something went wrong...') 112 | 113 | print("Sleeping time between 60-100 seconds") 114 | time.sleep(randint(60,100)) 115 | 116 | # Entry point of the script 117 | def main(): 118 | printAscii() 119 | checkPastebinAPIStatut() 120 | pastebinRequest() 121 | while True: 122 | pastebinRequest() 123 | 124 | if __name__ == '__main__': 125 | main() 126 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.32.2 2 | -------------------------------------------------------------------------------- /wordlist.txt: -------------------------------------------------------------------------------- 1 | mycompanyname 2 | mywebsitename 3 | gmail 4 | hotmail 5 | --------------------------------------------------------------------------------