File size: 13,601 Bytes
3a7f06a
 
 
 
1
2
3
4
{"nwo":"Critical-Start\/pastebin_scraper","sha":"196270249b0706bbeaf27fc2df379e4a2bb9fb5e","path":"pastebin_scraper.py","language":"python","identifier":"monitor","parameters":"()","argument_list":"","return_statement":"","docstring":"monitor() - Main function... creates and starts threads","docstring_summary":"monitor() - Main function... creates and starts threads","docstring_tokens":["monitor","()","-","Main","function","...","creates","and","starts","threads"],"function":"def monitor():\n    '''\n    monitor() - Main function... creates and starts threads\n\n    '''\n    import argparse\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"-v\", \"--verbose\", help=\"more verbose\", action=\"store_true\")\n    args = parser.parse_args()\n    level = logging.INFO\n    if args.verbose:\n        level = logging.DEBUG\n    #logging to both stdout and file\n    file_handler = logging.FileHandler(log_file)\n    handlers = [file_handler]\n    if PRINT_LOG:\n        stdout_handler = logging.StreamHandler(sys.stdout)\n        handlers.append(stdout_handler)\n    logging.basicConfig(\n        level=level,\n        format='%(asctime)s [%(levelname)s] %(message)s',\n        handlers=handlers\n    )\n    logging.info('Monitoring...')\n    paste_lock = threading.Lock()\n\n    pastebin_thread = threading.Thread(target=Pastebin().monitor, args=[paste_lock])\n\n    # changed threading to not be in a for loop\n    # we're only monitoring one site now - Moe\n    pastebin_thread.daemon = True\n    pastebin_thread.start()\n\n    # Let threads run\n    try:\n        while(1):\n            sleep(5)\n    except KeyboardInterrupt:\n        logging.warning('Stopped.')","function_tokens":["def","monitor","(",")",":","import","argparse","parser","=","argparse",".","ArgumentParser","(",")","parser",".","add_argument","(","\"-v\"",",","\"--verbose\"",",","help","=","\"more verbose\"",",","action","=","\"store_true\"",")","args","=","parser",".","parse_args","(",")","level","=","logging",".","INFO","if","args",".","verbose",":","level","=","logging",".","DEBUG","#logging to both stdout and file","file_handler","=","logging",".","FileHandler","(","log_file",")","handlers","=","[","file_handler","]","if","PRINT_LOG",":","stdout_handler","=","logging",".","StreamHandler","(","sys",".","stdout",")","handlers",".","append","(","stdout_handler",")","logging",".","basicConfig","(","level","=","level",",","format","=","'%(asctime)s [%(levelname)s] %(message)s'",",","handlers","=","handlers",")","logging",".","info","(","'Monitoring...'",")","paste_lock","=","threading",".","Lock","(",")","pastebin_thread","=","threading",".","Thread","(","target","=","Pastebin","(",")",".","monitor",",","args","=","[","paste_lock","]",")","# changed threading to not be in a for loop","# we're only monitoring one site now - Moe","pastebin_thread",".","daemon","=","True","pastebin_thread",".","start","(",")","# Let threads run","try",":","while","(","1",")",":","sleep","(","5",")","except","KeyboardInterrupt",":","logging",".","warning","(","'Stopped.'",")"],"url":"https:\/\/github.com\/Critical-Start\/pastebin_scraper\/blob\/196270249b0706bbeaf27fc2df379e4a2bb9fb5e\/pastebin_scraper.py#L17-L55"}
{"nwo":"Critical-Start\/pastebin_scraper","sha":"196270249b0706bbeaf27fc2df379e4a2bb9fb5e","path":"lib\/Paste.py","language":"python","identifier":"Paste.__init__","parameters":"(self)","argument_list":"","return_statement":"","docstring":"class Paste: Generic \"Paste\" object to contain attributes of a standard paste","docstring_summary":"class Paste: Generic \"Paste\" object to contain attributes of a standard paste","docstring_tokens":["class","Paste",":","Generic","Paste","object","to","contain","attributes","of","a","standard","paste"],"function":"def __init__(self):\n        '''\n        class Paste: Generic \"Paste\" object to contain attributes of a standard paste\n\n        '''\n        self.emails = 0\n        self.hashes = 0\n        self.num_emails = 0\n        self.num_hashes = 0\n        self.text = None\n        self.type = None\n        self.sites = None\n        self.db_keywords = 0.0\n        self.author = None","function_tokens":["def","__init__","(","self",")",":","self",".","emails","=","0","self",".","hashes","=","0","self",".","num_emails","=","0","self",".","num_hashes","=","0","self",".","text","=","None","self",".","type","=","None","self",".","sites","=","None","self",".","db_keywords","=","0.0","self",".","author","=","None"],"url":"https:\/\/github.com\/Critical-Start\/pastebin_scraper\/blob\/196270249b0706bbeaf27fc2df379e4a2bb9fb5e\/lib\/Paste.py#L7-L20"}
{"nwo":"Critical-Start\/pastebin_scraper","sha":"196270249b0706bbeaf27fc2df379e4a2bb9fb5e","path":"lib\/Paste.py","language":"python","identifier":"Paste.match","parameters":"(self)","argument_list":"","return_statement":"return self.type","docstring":"Matches the paste against a series of regular expressions to determine if the paste is 'interesting'\n\n        Sets the following attributes:\n                self.emails\n                self.hashes\n                self.num_emails\n                self.num_hashes\n                self.db_keywords\n                self.type","docstring_summary":"Matches the paste against a series of regular expressions to determine if the paste is 'interesting'","docstring_tokens":["Matches","the","paste","against","a","series","of","regular","expressions","to","determine","if","the","paste","is","interesting"],"function":"def match(self):\n        '''\n        Matches the paste against a series of regular expressions to determine if the paste is 'interesting'\n\n        Sets the following attributes:\n                self.emails\n                self.hashes\n                self.num_emails\n                self.num_hashes\n                self.db_keywords\n                self.type\n\n        '''\n        # Get the amount of emails\n        self.emails = list(set(regexes['email'].findall(self.text)))\n        self.hashes = regexes['hash32'].findall(self.text) #might identify multiple types of hashes\n        self.num_emails = len(self.emails)\n        self.num_hashes = len(self.hashes)\n        if self.num_emails > 0:\n            self.sites = list(set([re.search('@(.*)$', email).group(1).lower() for email in self.emails]))\n        for regex in regexes['db_keywords']:\n            if regex.search(self.text):\n                logging.debug('\\t[+] ' + regex.search(self.text).group(1))\n                self.db_keywords += round(1\/float(len(regexes['db_keywords'])), 2)\n        for regex in regexes['blacklist']:\n            if regex.search(self.text):\n                logging.debug('\\t[-] ' + regex.search(self.text).group(1))\n                self.db_keywords -= round(1.25 * (1\/float(len(regexes['db_keywords']))), 2)\n        if (self.num_emails >= settings.EMAIL_THRESHOLD) or (self.num_hashes >= settings.HASH_THRESHOLD) or (self.db_keywords >= settings.DB_KEYWORDS_THRESHOLD):\n            self.type = 'db_dump'\n        if regexes['cisco_hash'].search(self.text) or regexes['cisco_pass'].search(self.text):\n            self.type = 'cisco'\n        if regexes['honeypot'].search(self.text):\n            self.type = 'honeypot'\n        if regexes['google_api'].search(self.text):\n            self.type = 'google_api'\n        if regexes['pgp_private'].search(self.text):\n            self.type = 'pgp_private'\n        if regexes['ssh_private'].search(self.text):\n            self.type = 'ssh_private'\n        for regex in regexes['banlist']:\n            if regex.search(self.text):\n                self.type = None\n                break\n        return self.type","function_tokens":["def","match","(","self",")",":","# Get the amount of emails","self",".","emails","=","list","(","set","(","regexes","[","'email'","]",".","findall","(","self",".","text",")",")",")","self",".","hashes","=","regexes","[","'hash32'","]",".","findall","(","self",".","text",")","#might identify multiple types of hashes","self",".","num_emails","=","len","(","self",".","emails",")","self",".","num_hashes","=","len","(","self",".","hashes",")","if","self",".","num_emails",">","0",":","self",".","sites","=","list","(","set","(","[","re",".","search","(","'@(.*)$'",",","email",")",".","group","(","1",")",".","lower","(",")","for","email","in","self",".","emails","]",")",")","for","regex","in","regexes","[","'db_keywords'","]",":","if","regex",".","search","(","self",".","text",")",":","logging",".","debug","(","'\\t[+] '","+","regex",".","search","(","self",".","text",")",".","group","(","1",")",")","self",".","db_keywords","+=","round","(","1","\/","float","(","len","(","regexes","[","'db_keywords'","]",")",")",",","2",")","for","regex","in","regexes","[","'blacklist'","]",":","if","regex",".","search","(","self",".","text",")",":","logging",".","debug","(","'\\t[-] '","+","regex",".","search","(","self",".","text",")",".","group","(","1",")",")","self",".","db_keywords","-=","round","(","1.25","*","(","1","\/","float","(","len","(","regexes","[","'db_keywords'","]",")",")",")",",","2",")","if","(","self",".","num_emails",">=","settings",".","EMAIL_THRESHOLD",")","or","(","self",".","num_hashes",">=","settings",".","HASH_THRESHOLD",")","or","(","self",".","db_keywords",">=","settings",".","DB_KEYWORDS_THRESHOLD",")",":","self",".","type","=","'db_dump'","if","regexes","[","'cisco_hash'","]",".","search","(","self",".","text",")","or","regexes","[","'cisco_pass'","]",".","search","(","self",".","text",")",":","self",".","type","=","'cisco'","if","regexes","[","'honeypot'","]",".","search","(","self",".","text",")",":","self",".","type","=","'honeypot'","if","regexes","[","'google_api'","]",".","search","(","self",".","text",")",":","self",".","type","=","'google_api'","if","regexes","[","'pgp_private'","]",".","search","(","self",".","text",")",":","self",".","type","=","'pgp_private'","if","regexes","[","'ssh_private'","]",".","search","(","self",".","text",")",":","self",".","type","=","'ssh_private'","for","regex","in","regexes","[","'banlist'","]",":","if","regex",".","search","(","self",".","text",")",":","self",".","type","=","None","break","return","self",".","type"],"url":"https:\/\/github.com\/Critical-Start\/pastebin_scraper\/blob\/196270249b0706bbeaf27fc2df379e4a2bb9fb5e\/lib\/Paste.py#L22-L66"}
{"nwo":"Critical-Start\/pastebin_scraper","sha":"196270249b0706bbeaf27fc2df379e4a2bb9fb5e","path":"lib\/Pastebin.py","language":"python","identifier":"Pastebin.update","parameters":"(self)","argument_list":"","return_statement":"","docstring":"update(self) - Fill Queue with new Pastebin IDs","docstring_summary":"update(self) - Fill Queue with new Pastebin IDs","docstring_tokens":["update","(","self",")","-","Fill","Queue","with","new","Pastebin","IDs"],"function":"def update(self):\n        '''update(self) - Fill Queue with new Pastebin IDs'''\n        logging.info('Retrieving Pastebin ID\\'s')\n        new_pastes = []\n        raw = None\n        while not raw:\n            try:\n                raw = urllib.request.urlopen(\"https:\/\/scrape.pastebin.com\/api_scraping.php?limit=\" + str(SCRAPE_LIMIT))\n            except:\n                logging.info('Error with pastebin')\n                raw = None\n                sleep(5)\n        # import API result as JSON\n        decoded = raw.read().decode('utf-8')\n        raw_json = json.loads(decoded)\n        #parse json to get keys\n        results = []\n        #populate results list with paste_ids\n        for paste_bulk in raw_json:\n            results.append(paste_bulk['key'])\n        if not self.ref_id:\n            #up to 100 new pastes\n            results = results[:100]\n        for entry in results:\n            paste = PastebinPaste(entry)\n            # Check to see if we found our last checked paste_id\n            if paste.id == self.ref_id:\n                #if paste_id matches last checked id, no more new stuff\n                break\n            new_pastes.append(paste)\n        for entry in new_pastes[::-1]:\n            logging.info('Adding URL: ' + entry.url)\n            self.put(entry)","function_tokens":["def","update","(","self",")",":","logging",".","info","(","'Retrieving Pastebin ID\\'s'",")","new_pastes","=","[","]","raw","=","None","while","not","raw",":","try",":","raw","=","urllib",".","request",".","urlopen","(","\"https:\/\/scrape.pastebin.com\/api_scraping.php?limit=\"","+","str","(","SCRAPE_LIMIT",")",")","except",":","logging",".","info","(","'Error with pastebin'",")","raw","=","None","sleep","(","5",")","# import API result as JSON","decoded","=","raw",".","read","(",")",".","decode","(","'utf-8'",")","raw_json","=","json",".","loads","(","decoded",")","#parse json to get keys","results","=","[","]","#populate results list with paste_ids","for","paste_bulk","in","raw_json",":","results",".","append","(","paste_bulk","[","'key'","]",")","if","not","self",".","ref_id",":","#up to 100 new pastes","results","=","results","[",":","100","]","for","entry","in","results",":","paste","=","PastebinPaste","(","entry",")","# Check to see if we found our last checked paste_id","if","paste",".","id","==","self",".","ref_id",":","#if paste_id matches last checked id, no more new stuff","break","new_pastes",".","append","(","paste",")","for","entry","in","new_pastes","[",":",":","-","1","]",":","logging",".","info","(","'Adding URL: '","+","entry",".","url",")","self",".","put","(","entry",")"],"url":"https:\/\/github.com\/Critical-Start\/pastebin_scraper\/blob\/196270249b0706bbeaf27fc2df379e4a2bb9fb5e\/lib\/Pastebin.py#L32-L64"}