#!/usr/bin/env python3 # -*-coding:UTF-8 -* """ The Cryptocurrency Module ============================ It trying to extract Bitcoin address and secret key from paste ..seealso:: Paste method (get_regex) Requirements ------------ *Need running Redis instances. (Redis). """ from Helper import Process from pubsublogger import publisher import os import re import sys import time import redis import signal sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages')) import Item import Cryptocurrency class TimeoutException(Exception): pass def timeout_handler(signum, frame): raise TimeoutException signal.signal(signal.SIGALRM, timeout_handler) def search_crytocurrency(item_id, item_content): is_cryptocurrency_found = False for crypto_name in cryptocurrency_dict: crypto_dict = cryptocurrency_dict[crypto_name] signal.alarm(crypto_dict['max_execution_time']) try: crypto_addr = re.findall(crypto_dict['regex'], item_content) except TimeoutException: crypto_addr = [] p.incr_module_timeout_statistic() # add encoder type print ("{0} processing timeout".format(item_id)) continue else: signal.alarm(0) if crypto_addr: is_valid_crypto_addr = False # validate cryptocurrency address for address in crypto_addr: if(Cryptocurrency.verify_cryptocurrency_address(crypto_name, address)): is_valid_crypto_addr = True print('{} address found : {}'.format(crypto_name, address)) # build bitcoin correlation Cryptocurrency.save_cryptocurrency_data(crypto_name, Item.get_item_date(item_id), item_id, address) # At least one valid cryptocurrency address was found if(is_valid_crypto_addr): # valid cryptocurrency found in this item is_cryptocurrency_found = True # Tag Item msg = '{};{}'.format(crypto_dict['tag'], item_id) p.populate_set_out(msg, 'Tags') # search cryptocurrency private key if crypto_dict.get('private_key'): signal.alarm(crypto_dict['private_key']['max_execution_time']) try: addr_private_key = re.findall(crypto_dict['private_key']['regex'], item_content) except TimeoutException: addr_private_key = [] p.incr_module_timeout_statistic() # add encoder type print ("{0} processing timeout".format(item_id)) continue else: signal.alarm(0) if addr_private_key: # Tag Item msg = '{};{}'.format(crypto_dict['private_key']['tag'], item_id) p.populate_set_out(msg, 'Tags') # debug print(addr_private_key) to_print = '{} found: {} address and {} private Keys'.format(crypto_name, len(crypto_addr), len(addr_private_key)) print(to_print) publisher.warning(to_print) to_print = 'Cryptocurrency;{};{};{};'.format(Item.get_source(item_id), Item.get_item_date(item_id), Item.get_item_basename(item_id)) publisher.warning('{}Detected {} {} private key;{}'.format( to_print, len(addr_private_key), crypto_name, item_id)) if is_cryptocurrency_found: # send to duplicate module p.populate_set_out(item_id, 'Duplicate') default_max_execution_time = 30 cryptocurrency_dict = { 'bitcoin': { 'name': 'bitcoin', # e.g. 1NbEPRwbBZrFDsx1QW19iDs8jQLevzzcms 'regex': r'\b(?