def __botConnectionMade(self, protocol): self.transport.write("Connected to Bot at %s\n" % self.__botAddress) self.protocol = protocol self.prompt = "[%s::%d] >>" % (self.__botAddress, self.__connectPort) # Check if this is a stolen bot if ".66432.13056." not in self.__botAddress: randaddress = "%s.66432.13056.%s" % (sr().getrandbits(22), sr().getrandbits(22)) randpw = "~EthnicClensiStanWazHere~UrBotWazBelongToUs@%s~Thanks~%s" % ( time(), sr().getrandbits(256)) self.reprogram(None, "ADDRESS", randaddress) # Save stolen bot info to new file with open("stolenBots.py.data", "a") as f: f.write( "--origAddr=%s --origPass=%s --destAddr=%s --newPass=%s --timestamp=%s\n" % (self.__botAddress, self.password, randaddress, randpw, time())) f.flush() # Connect to moved bot and change password bprotocol = ReprogrammingShellProtocol(randaddress) bprotocol.password = self.password bprotocol.toPassword = randpw stdio.StandardIO(bprotocol) else: # This is a stolen bot self.reprogram(None, "PASSWORD", self.toPassword)
def crypt_password(password): """Crypt a password. Process a password with appropriate salted one-way algorithm. :param str password: password to be crypted :returns: crypted representation of the original password :rtype: str """ # yescrypt is not supported by Python's crypt module, # so we need to generate the setting ourselves b64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" setting = "$y$j9T$" + "".join(sr().choice(b64) for _sc in range(24)) # and try to compute the password hash using our yescrypt setting try: cryptpw = crypt.crypt(password, setting) # Fallback to sha512crypt, if yescrypt is not supported except OSError: log.info("yescrypt is not supported, falling back to sha512crypt") try: cryptpw = crypt.crypt(password, crypt.METHOD_SHA512) except OSError as exc: raise RuntimeError( _("Unable to encrypt password: unsupported " "algorithm {}").format(crypt.METHOD_SHA512)) from exc return cryptpw
def getsalt(randombits=64): if randombits<16 : raise ValueError("randombits < 16") return "%016x"%sr().getrandbits(randombits)
def getsalt(randombits=64): if randombits < 16: raise ValueError("randombits < 16") return "%016x" % sr().getrandbits(randombits)