def initialize(self): h, e, i, s = setup.load_local_vars() self.info['host'] = h self.info['external'] = e self.info['internal'] = i self.info['server'] = s self.RUNNING = True self.start_date, self.start_time = utils.create_timestamp()
def training_ascii(): date, hours = utils.create_timestamp() print '\033[1m\033[32m================================================================\033[0m' print 'GENERATING POKER_HAND TRAINING DATA %s - %s' % (date, hours) print '[-' + '-' * int(60 * (round + 1) / N) + '-]' print '\033[1m[%ss Elapsed] \t \t %s percent complete' % ( str(time.time() - tic), str(100 * float(round) / N)) print '\033[1m\033[32m================================================================\033[0m'
def create_job(self, process_name): # Create Job Method ldate, ltime = utils.create_timestamp() job = {} job['NAME'] = process_name job['COMPLETE'] = False job['START'] = ldate job['RUNNING'] = False self.log_work(process_name, False, job)
def currentDatetime(): ld, lt = utils.create_timestamp() mon = int(ld.split('/')[0]) day = int(ld.split('/')[1]) yr = int(ld.split('/')[2]) hr = int(lt.split(':')[0]) mn = int(lt.split(':')[1]) sec = int(lt.split(':')[2]) return datetime.datetime(yr, mon, day, hr, mn, sec)
def create_log(self): ld, lt = utils.create_timestamp() fn = ld.replace('/', '-') + '_' + lt.replace(':', '-') + '.log' if not os.path.isdir('logs/web'): os.mkdir('logs/web') if not os.path.isfile(fn): open('logs/web/' + fn, 'w').write('Starting HoneyPot [%s - %s]\n' % (ld, lt)) return fn
def populate_info(self): ldate, ltime = utils.create_timestamp() self.info['START'] = ldate self.info['NSHARES'] = len(self.local_shares.keys()) previous_info = self.load_node_info() # TODO: Update as needed if 'START' in previous_info.keys(): if ldate != previous_info['START']: self.info['LAST_RUN'] = previous_info['START'] self.info['RUNNING'] = True
def shutdown(self): ldate, ltime = utils.create_timestamp() uptime = time.time() - self.start try: self.serve.close() except socket.error: pass print( '\033[1m\033[31m\n[*] %s - %s: Shutting Down Server [Uptime: %fs]\033[0m' % (ldate, ltime, uptime)) return uptime
def honey(port, run_time, verbose, reply): clients = [] date, local_time = utils.create_timestamp() banner = 'Honey pot created [port %d] - %s %s\n' % (port, local_time, date) if verbose: print 'Honey pot created [port %d] - %s %s' % (port, local_time, date) print '[*] Initialized Uptime: %f hours' % (run_time / 3600.) data = '' log_file = date.replace('/', '') + '_' + local_time.split( ':')[0] + local_time.split(':')[1] + '.log' open(log_file, 'wb').write(banner) s = utils.start_listener(port, 5) tic = time.time() try: while (time.time() - tic) < run_time: if (int(time.time()) - int(tic)) % 5 == 0: date, local_time = utils.create_timestamp() client, client_adr = s.accept() try: # Recv? (idk... so much room for error) client.send(reply) client.close() clients.append(client_adr[0]) except socket.error: print '[*] Connection Broken with %s' % client_adr[0] msg = '[*] Connection accepted-> %s:%d' % (client_adr[0], client_adr[1]) data = '[*] Connection accepted from %s at %s - %s\n' % ( client_adr[0], date, local_time) if verbose: print msg print '[*] Logging Connections [%ss Elapsed]' % str( time.time() - tic) open(log_file, 'a').write(data) except KeyboardInterrupt: print '[!!] Server Killed [%ss Elapsed]' % str(time.time() - tic) pass s.close()
def run(self): self.running = True self.runtime = time.time() sdate, stime = utils.create_timestamp() rules = { 'master': self.master_node, 'brokers': self.brokers, 'listening': self.running } # dump this into /Config/Channels/Self/messaging.json with open('PoolData/Config/Channels/Self/messaging.json', 'w') as c: json.dump(rules, c) try: # create a socket s = utils.create_tcp_listener(self.inbound) print('[*] Server Started [%s - %s]' % (sdate, stime)) # Start Listening for Commands while self.running: # accept a client client, cinfo = s.accept() # handle their request succeeded = False try: # event = pool.apply_async(self.client_handler, (client, cinfo)) handler = Thread(target=self.client_handler, args=(client, cinfo)) handler.start() succeeded = True except multiprocessing.TimeoutError: print('[!!] Connection Error with %s' % cinfo[0]) pass # close everything client.close() # all incoming messages are from brokers if succeeded and cinfo[0] not in self.brokers: self.brokers.append(cinfo[0]) except KeyboardInterrupt: self.running = False print('[*] Shutting Down Backend Messager') pass s.close() rules = { 'master': self.master_node, 'brokers': self.brokers, 'listening': self.running } # dump this into /Config/Channels/Self/messaging.json with open('PoolData/Config/Channels/Self/messaging.json', 'w') as c: json.dump(rules, c) print('[*] Messaging rules saved')
def __init__(self, active=None, created=None, yk_publicname=None, yk_counter=None, yk_use=None, yk_low=None, yk_high=None, nonce=None, notes=None): if created is None: created = create_timestamp() self.created = created self.active = active self.created = created self.yk_publicname = yk_publicname self.yk_counter = yk_counter self.yk_use = yk_use self.yk_low = yk_low self.yk_high = yk_high self.nonce = nonce self.notes = notes
def __init__(self, targetFiles, useBot): self.dstart, self.tstart = utils.create_timestamp() # setup which files to be watching self.lib = load_tripwires() self.targets = self.checkfiles(targetFiles) self.watching = True # TODO: configure alerting system besides printing to console if useBot: # report file alerts to a discord bot integration self.hasBot = True if not os.path.isdir('.alerts'): os.mkdir('.alerts') open('.alerts/alarm', 'w').write('') # run it self.run()
def run(self): running = True serve = create_listener(self.inbound) self.log = self.create_log() ld, lt = utils.create_timestamp() print('[*] Honeypot Started [%s - %s]' % (ld, lt)) try: while running: c, ci = serve.accept() print('[*] \033[1m\033[31m%s:%d\033[0m has connected ' % (ci[0], ci[1])) handler = Thread(target=client_handler, args=(c, ci, self.log)) handler.run() c.close() except KeyboardInterrupt: running = False
def wx_js_sdk(): # 返回weixin-js-sdk权限配置 url = request.args.get('url') if not url: abort(404) ticket = client.jsapi.get_jsapi_ticket() noncestr = create_nonce_str() timestamp = create_timestamp() signature = client.jsapi.get_jsapi_signature(noncestr=noncestr, ticket=ticket, timestamp=timestamp, url=url) return jsonify({ 'appId': APPID, 'timestamp': timestamp, 'nonceStr': noncestr, 'signature': signature })
def client_handler(csock, caddr, logfile): # Get their request request = '' t0 = time.time() waiting = True timeout = 3.0 try: while waiting and (time.time() - t0) < timeout: try: raw_req = csock.recv(1024) request = raw_req.decode('utf-8') except UnicodeDecodeError: print('[x] %s sent something nasty' % caddr[0]) request = raw_req waiting = False except socket.error: print('[!!] Unable to get request from %s' % caddr[0]) waiting = False pass # Maybe send something silly if not waiting: try: csock.send(open('page.html', 'r').read().encode('utf-8')) except socket.error: pass # Log Everything data = {'IP': caddr[0], 'Req': request} ld, lt = utils.create_timestamp() try: parsed = json.dumps(data) except: pass parsed = '{"%s" : "%s"' % (caddr[0], request) entry = ('Connection at %s - %s :\n' % (ld, lt)) + parsed + '\n' + '=' * 80 + '\n' open('logs/web/' + logfile, 'a').write(entry) return True
import os import sys spark = create_spark_session('generate_similarities') file_name = sys.argv[1] df_labels = spark.read.csv(f'data/{file_name}', header=True) COLUMNS = 'all' INDEX_COLUMN = sys.argv[2] SIMILARITY_TYPE = 'cosine' etl_created = create_timestamp() preprocessor = Preprocess(df_labels=df_labels, columns=COLUMNS, index_column=INDEX_COLUMN) df_recipe_features = preprocessor.preprocess() pd_df_recipe_features = df_recipe_features.toPandas() features_dir = f'output/{etl_created}/features' os.makedirs(features_dir) pd_df_recipe_features.to_csv(f'{features_dir}/features.csv', index=False) similarity = Similarity(df_features=df_recipe_features, index_column=INDEX_COLUMN, similarity_type=SIMILARITY_TYPE) similarities = similarity.generate()
print '\to %d RDP \tPORTS OPEN' % rdp print '\to %d SMTP \tPORTS OPEN' % smtp print '\to %d UPNP \tPORTS OPEN' % upnp print '\to %d MYSQL \tPORTS OPEN' % mysql print '\to %d FLASK \tPORTS OPEN' % flask print '\to %d MS-RPC \tPORTS OPEN' % msrpc print '\to %d TELNET \tPORTS OPEN' % telnet print '\033[0m' return database if __name__ == '__main__': base = '/home/tylersdurden/Desktop/ScanData' n_scans = len(os.listdir(base)) date, local_time = utils.create_timestamp() if ('-q' or 'query') in sys.argv: host_data = process_scan_data(base, verbose=False) if len(sys.argv) >= 3: query = sys.argv[2] else: query = raw_input('Enter Query:') if query in host_data.keys(): ''' Return IPs that match the query in a way that will be useful for other scripts IE Print Line by Line, not just a straight print(array) ''' for line in host_data[query]: if len(line) > 1: print line
def shutdown(self): ldate, ltime = utils.create_timestamp() if 'RUNNING' in self.info.keys(): self.info['RUNNING'] = False self.log_work('node.py', True, self.info)
def test_create_timestamp(self): timestamp = create_timestamp() self.assertTrue('_' in timestamp) self.assertTrue(len(timestamp), 4 + 2 + 2 + 1 + 4)