def block_out(ip_address): print(Fore.RED + "Block out counter archived!") winsound.Beep(1000, 4000) ip_research_counter = 1 if internet_status() is True: print(Fore.RED + "Blocked IP:" + str(ip_address).strip()) refresh_ip = None while (refresh_ip == ip_address) or refresh_ip is None: print( "Program will be wait until you to renew internet ip for:" + str(config_section_map("general")["ip_refresh_second"]) + " second {:%Y-%m-%d %H:%M:%S}".format(datetime.datetime.now()) ) sleep(int(config_section_map("general")["ip_refresh_second"])) refresh_ip = public_ip() print("Refreshed IP:" + str(refresh_ip)) else: while internet_status() is False: print( "Connection is lost!,Check your internet connection! Try:", ip_research_counter, " second {:%Y-%m-%d %H:%M:%S}".format(datetime.datetime.now()), ) sleep(int(config_section_map("general")["ip_refresh_second"])) ip_research_counter += 1
def main(): conn_id = None global conn while conn_id is None: try: db_config = read_db_config() conn = MySQLConnection(**db_config) conn_id = conn.connection_id except Exception: conn_id = None print('Try connecting to database...') if config_section_map("ip_resolver")['default_list_name']: selected_list = str(config_section_map("ip_resolver")['default_list_name']) loop_counter = 1 process_counter = 0 while loop_counter > 0: # lock record for process lock_record_query = 'update %s set lockedby=connection_id(),lockedat=now(),HFlag=\'I\' ' \ 'where lockedby is null and status=\'Site registered\' and HFlag<>\'R\' ' \ 'and (ip is null or ip=\'Fail\') and trycount<%s order by trycount limit %s '\ % (selected_list,config_section_map("ip_resolver")['try_count'], int(config_section_map("ip_resolver")['buffer'])) loop_counter, connection_d = db_update(lock_record_query) if loop_counter: todo_query = 'select no,site from %s where lockedby=%s ' % ( selected_list, connection_d) todo_result = db_select(todo_query) if todo_result: for to_do_line in range(0, len(todo_result)): process_counter += 1 try: look_for = todo_result[to_do_line][1] looking_for = (str(look_for.strip())) ip = host2ip('www.' + looking_for) print(Fore.CYAN + looking_for+': '+ip) if ip == 'Fail': return_update_query = "update %s set HFlag=\'I\',lockedby=null,ip='%s' " \ ",trycount=trycount+1 where No=%s " \ % (selected_list, ip, todo_result[to_do_line][0]) else: return_update_query = "update %s set HFlag=\'R\',lockedby=null,ip='%s' " \ ",trycount=trycount+1 where No=%s " \ % (selected_list, ip, todo_result[to_do_line][0]) db_update(return_update_query) except Exception: print('exception') return_update_query = "update %s set HFlag=Null,lockedby=null " \ ",trycount=trycount+1 where No=%s " \ % (selected_list, todo_result[to_do_line][0]) db_update(return_update_query) else: print('All record are processed for ' + selected_list + ' list!')
def main(): conn_id = None global conn while conn_id is None: try: db_config = read_db_config() conn = MySQLConnection(**db_config) conn_id = conn.connection_id except Exception: conn_id = None print('Try connecting to database...') if config_section_map("dns_reverser")['default_list_name']: selected_list = str(config_section_map("dns_reverser")['default_list_name']) todo_result_rows = 1 process_counter = 0 while todo_result_rows > 0: todo_query = 'select distinct(ip) from %s where ip is not null and ip!=\'Fail\' and ip not in ' \ '(select refrence from harverster_hosts) limit %s' % \ (selected_list, int(config_section_map("dns_reverser")['buffer'])) todo_result, todo_result_rows = db_select(todo_query) if todo_result: for to_do_line in range(0, len(todo_result)): process_counter += 1 look_for = todo_result[to_do_line][0] looking_for = (str(look_for.strip())) reverse_result = reverse_dns(looking_for) if reverse_result is None: return_insert_query = "insert into harverster_hosts (host,refrence) " \ "values ('%s','%s')" \ % ('None', todo_result[to_do_line][0]) db_update(return_insert_query) else: for line in reverse_result: return_insert_query = "insert into harverster_hosts (host,refrence) " \ "values ('%s','%s')" \ % ((reverse_result[line][0])[:100], todo_result[to_do_line][0]) db_update(return_insert_query)
import config from common_utils.connection import Connection queueConfig = config.config_section_map('QueueConnection') __request_queue = str(queueConfig['request_queue_name']) def request(msg): """ send message to request queue :param msg: msg to queue """ send(msg, __request_queue) def reply(msg): """ send message to destination :param msg: message to queue """ send(msg, msg.destination) def send(msg, queue): """ :param msg: send message to custom queue :param queue: queue name """ Connection(queue).send(msg.to_queue())
''' Setup MongoDB ''' import pymongo import config # Get the parser for extracting the database config details # Get the database details HOST = config.config_section_map('MongoDB')['host'] USER = config.config_section_map('MongoDB')['user'] PASSWORD = config.config_section_map('MongoDB')['password'] DATABASE = config.config_section_map('MongoDB')['database'] MONGODB_URI = 'mongodb://' + USER + ':' + PASSWORD + '@' + HOST CLIENT = pymongo.MongoClient(MONGODB_URI) TEMP = CLIENT.get_default_database() DB = TEMP[DATABASE]
__author__ = 'Saman' if __name__ == '__main__': from config import config_section_map if config_section_map("general")['auto_start_search'] == 'True': import ListSearch ListSearch.main() else: ch = input('Choice Action:\n1:Create List\n2:Search Existed List:\n3:Export List Result\n' '4:IP Resolver\n5:DNS Reverser\n0:Exit\n') if ch == '1': import ListCreator ListCreator.main() elif ch == '2': import ListSearch ListSearch.main() elif ch == '3': import ListExport ListExport.main() elif ch == '4': import IPResolver IPResolver.main() elif ch == '5': import DnsReverser
def main(): # List available table conn_id = None global conn internet_try_counter = 1 while internet_status() is not True: print( "Connection is lost!,Check your internet connection! Refresh interval:", int(config_section_map("general")["ip_refresh_second"]), "second,Try:", internet_try_counter, ) sleep(int(config_section_map("general")["ip_refresh_second"])) internet_try_counter += 1 ip_address = public_ip() while conn_id is None: try: db_config = read_db_config() conn = MySQLConnection(**db_config) conn_id = conn.connection_id except Exception: conn_id = None print("Try connecting to database...") table_list = ( "select table_name,table_rows from information_schema.tables " "where table_name like 'lst_%' and table_rows>0;" ) table_list_exec = db_select(table_list) table_list_result = {} for line in range(0, len(table_list_exec)): table_records_status_query = ( "select count(site) from %s where status='Passed' or status is null " "or status='Registered No Email'" % (table_list_exec[line][0]) ) table_records_status_result = db_select(table_records_status_query) table_list_result.setdefault(table_list_exec[line][0], []).append(table_records_status_result[0][0]) table_list_result.setdefault(table_list_exec[line][0], []).append(table_list_exec[line][1]) if config_section_map("general")["default_list_name"]: selected_list = str(config_section_map("general")["default_list_name"]) print("Searching " + selected_list + " list...") if selected_list in table_list_result.keys(): print("Processable,Total Record:" + str(table_list_result[selected_list])) else: print("Please Choice your dictionary list from below list") print( tabulate( zip(table_list_result.keys(), table_list_result.values()), headers=["List Name", "Processable/Record Count"], tablefmt="grid", ) ) selected_list = input("List Name:").lower() if selected_list in table_list_result.keys(): delay = float(config_section_map("search")["delay_second"]) whois = "whois.nic.ir" port = 43 try_count = config_section_map("search")["try_count"] loop_counter = 1 process_counter = 0 passed_counter = 0 monitoring(socket.gethostname(), "Searching", str(ip_address)) while loop_counter > 0: # lock record for process lock_record_query = ( "update %s set lockedby=connection_id(),lockedat=now()," "trycount=trycount+1,Hostname='%s' " "where lockedby is null and (status='Passed' or status is null " "or status='Registered No Email' ) and trycount<%s order by trycount limit %s" % (selected_list, socket.gethostname(), try_count, int(config_section_map("search")["buffer"])) ) loop_counter, connection_d = db_update(lock_record_query) if loop_counter: todo_query = "select no,site from %s where lockedby=%s and trycount<=%s " % ( selected_list, connection_d, try_count, ) todo_result = db_select(todo_query) if todo_result: for to_do_line in range(0, len(todo_result)): if ( process_counter > 0 and (process_counter / int(config_section_map("search")["mid_sleep_record"])) - (math.floor(process_counter / int(config_section_map("search")["mid_sleep_record"]))) == 0 ): print( Fore.BLUE + "Sleep mode:" + str(config_section_map("search")["mid_sleep_time"]) + " second {:%Y-%m-%d %H:%M:%S}".format(datetime.datetime.now()), "Session Processed Count:", process_counter, end="\r", ) monitoring(socket.gethostname(), "Sleep Mode", str(ip_address)) sleep(int(config_section_map("search")["mid_sleep_time"])) monitoring(socket.gethostname(), "Searching", str(ip_address)) process_counter += 1 try: sleep(delay) look_for = todo_result[to_do_line][1] looking_for = str(look_for.strip()) telnet_connect = Telnet( whois, port, timeout=int(config_section_map("telnet")["telnet_timeout"]) ) telnet_connect.write(looking_for.encode("ascii") + b"\r\n") telnet_result = str(telnet_connect.read_all()) if telnet_result == "b''": print(str(todo_result[to_do_line][0]) + " : Passed --> " + looking_for, end="\r") return_update_query = ( "update %s set Status='Passed',lockedby=null ,Hostname='%s' " "where No=%s " % (selected_list, socket.gethostname(), todo_result[to_do_line][0]) ) db_update(return_update_query) else: telnet_parser( telnet_result, todo_result, to_do_line, look_for, selected_list, looking_for ) passed_counter = 0 except Exception: passed_counter += 1 print( Fore.RED + "Telnet exception Passed -->", str(look_for), "Count", passed_counter, end="\r", ) winsound.Beep(9000, 300) return_update_query = ( "update %s set Status='Passed',lockedby=null ,Hostname='%s' " "where No=%s " % (selected_list, socket.gethostname(), todo_result[to_do_line][0]) ) db_update(return_update_query) if passed_counter >= int(config_section_map("search")["block_counter_out"]): ip_address = public_ip() monitoring(socket.gethostname(), "Blocked", str(ip_address)) mail_sender(socket.gethostname(), "Blocked") block_out(ip_address) else: print("All record are processed for " + selected_list + " list!") else: monitoring(socket.gethostname(), "Finished", str(ip_address)) print("List does not exist!Bye!") sys.exit(0)
def reverse_dns(target): # First Page Parsing and Getting count of total result result = {} print('\n' + Fore.BLACK + 'Try DNS Reverse for:' + target, end='\r') link = "http://www.bing.com/search?q=ip%3a" + target + "+language%3afa&first=1&FORM=PERE1" try: print(Fore.CYAN + 'Try DNS Reverse for:' + target + ' Page 1', end='\r') sock = urllib.request.urlopen(link) htmlsource = sock.read() soup = BeautifulSoup(htmlsource, 'html5lib') result_count = search(r'("sb_count">)(\S+) results', str(soup.find(id="b_tween"))) records = 0 if result_count: records = int(str(result_count.group(2)).replace(',', '')) no_result = search(r'No results found for', str(soup.find_all('h1'))) if no_result: result = None for link in soup.find_all('a'): pre_result = str(link.get('href')) if pre_result[:4] == 'http' and pre_result[:9] != 'http://go' \ and pre_result[:34] != 'http://www.microsofttranslator.com' \ and pre_result[:32] != 'https://view.officeapps.live.com': result.setdefault(pre_result, []).append(pre_result) # Detect other pages and parse it if records >= 10: page_number = 1 x = 0 y = 1 while x != y: if page_number >= int(config_section_map("dns_reverser")['pages_to_process']): break link = "http://www.bing.com/search?q=ip%3a" + target + "+language%3afa&first=" + \ str(page_number) + "1&FORM=PERE1" try: print(Fore.CYAN + 'Try DNS Reverse for:' + target + ' Page ' + str(page_number + 1), end='\r') sock = urllib.request.urlopen(link) htmlsource = sock.read() soup = BeautifulSoup(htmlsource, 'html5lib') result_count = search(r'("sb_count">)(\w+)-(\w+) of (\S+) results', str(soup.find(id="b_tween"))) if result_count: x = int(str(result_count.group(3)).replace(',', '')) y = int(str(result_count.group(4)).replace(',', '')) else: x = 0 y = 0 for link in soup.find_all('a'): pre_result = str(link.get('href')) if pre_result[:4] == 'http' and pre_result[:9] != 'http://go' \ and pre_result[:34] != 'http://www.microsofttranslator.com' \ and pre_result[:32] != 'https://view.officeapps.live.com': result.setdefault(pre_result, []).append(pre_result) page_number += 1 except Exception: print('Other page exception') sock.close() except Exception: print('First Page exception') return result
import config import gzip compress = config.config_section_map('CompressMessages')['compress'] def prepare_message(message): if compress: with gzip.open('message.gz', 'wb') as write_message: write_message.write(message) with open("message.gz", "rb") as read_message: message_content = read_message.read() message_byte_array = bytearray(message_content) return str(message_byte_array) else: print("don't compress")