Beispiel #1
0
def unfish_it(string, passphrase):
    cipher = blowfish.Blowfish(passphrase)
    cipher.initCTR()
    text = string
    decrypted = cipher.encryptCTR(text)

    return decrypted
Beispiel #2
0
    def get_algorithm(self, alg):
        """ Return an object based on the algorithm name. Supported algorithms
		are:
			blowfish
			
		Other algorithms may be added later."""
        if alg == 'blowfish': return blowfish.Blowfish(self.key)
Beispiel #3
0
def encryptdiary(data, password, level):
    salt = createsalt()
    key = createkey(password + salt)
    cipher = blowfish.Blowfish(key)
    cipher.initCTR()
    diary = ''
    if level == 1:
        diary += ('$1')
    elif level == 2:
        diary += ('$2')
    elif level == 3:
        diary += ('$3')
    diary += (repr(data))
    crypted = cipher.encryptCTR(diary)
    if DEBUG:
        print "Encrypting:"
        print "Salt:" + salt
        print "Password:"******"Key:" + key
        print len(diary) + sallen
        print len(diary)
        print "Decrypted string:"
        print diary
        print "Encrypted string:"
        print crypted
    f = open('diary.db', 'wb')
    f.write(crypted + salt)
    if level == 2 or level == 3:
        fh = open('diary.hash', 'wb')
        fh.write(md5calc(crypted) + md5calc(repr(data)))
        fh.close()
    f.close()
    return True
Beispiel #4
0
def encryptentry(entry, password):
    salt = createsalt()
    key = createkey(password + salt)
    cipher = blowfish.Blowfish(key)
    cipher.initCTR()
    entry[1] = 'entryok' + entry[1]
    entry[1] = cipher.encryptCTR(entry[1])
    return entry + [salt]
Beispiel #5
0
def decryptentry(entry, password):
    if len(entry) <= 2:
        return 'notenc'
    salt = entry[len(entry) - 1]
    key = createkey(password + salt)
    cipher = blowfish.Blowfish(key)
    cipher.initCTR()
    entry[1] = cipher.decryptCTR(entry[1])
    if entry[1][:7] != 'entryok':
        return False  #Decryption error
    entry[1] = entry[1][7:]
    return entry[:len(entry) - 1]
Beispiel #6
0
    def store_passwd(cls, email, passwd):
        """
        """
        passwd_file = '%s/%s.passwd' % (cls.get_home_dir_path(), email)

        fdesc = open(passwd_file, "w+")

        cipher = blowfish.Blowfish(cls.get_secret())
        cipher.initCTR()

        fdesc.write(cipher.encryptCTR(passwd))

        fdesc.close()
Beispiel #7
0
    def get_encryption_cipher(self):
        """
           Return the cipher to encrypt an decrypt.
           If the secret key doesn't exist, it will be generated.
        """
        if not self._cipher:
            if not self._encryption_key:
                self._encryption_key = credential_utils.CredentialHelper.get_secret_key(
                    '%s/%s' % (self._info_dir, self.ENCRYPTION_KEY_FILENAME))

            #create blowfish cipher if data needs to be encrypted
            self._cipher = blowfish.Blowfish(self._encryption_key)

        return self._cipher
Beispiel #8
0
def finder100(html, ref):
    #try:
    if 'Blowfish' not in html:
        return
    if 'wib' in ref:
        log('yes')

    key = re.findall('new Blowfish\([\"\'](.+?)[\"\']\)', html)[0]
    if len(key) > 56:
        key = key[:56]
    crypted = re.findall('.decrypt\([\"\'](.+?)[\"\']\)', html)[0]
    import blowfish
    cipher = blowfish.Blowfish(key)

    decrypted = cipher.decrypt(crypted)
    log(decrypted)
    return find_link(ref, html=decrypted)
Beispiel #9
0
 def store_passwd(cls, email, passwd):
     """
        Encrypt and store gmail password
     """
     passwd_file = '%s/%s.passwd' % (gmvault_utils.get_home_dir_path(), email)
 
     fdesc = os.open(passwd_file, os.O_CREAT|os.O_WRONLY, 0600)
     
     cipher       = blowfish.Blowfish(cls.get_secret_key(cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())))
     cipher.initCTR()
 
     encrypted = cipher.encryptCTR(passwd)
     the_bytes = os.write(fdesc, encrypted)
 
     os.close(fdesc)
     
     if the_bytes < len(encrypted):
         raise Exception("Error: Cannot write password in %s" % (passwd_file))
Beispiel #10
0
def decryptdiary(password):
    f = open('diary.db', 'rb')
    string = f.read()
    f.close()
    salt = string[len(string) - sallen:]
    string = string[:len(string) - sallen]
    stringc = string
    key = createkey(password + salt)
    cipher = blowfish.Blowfish(key)
    cipher.initCTR()
    data = cipher.decryptCTR(string)
    if DEBUG:
        print "Decrypting:"
        print "Salt:" + salt
        print "Password:"******"Key:" + key
        print len(string) + sallen
        print len(string)
        print "Encrypted string:"
        print string
        print "Decrypted string:"
        print data
    level = data[:2]
    if level not in ['$1', '$2', '$3']:
        return False  #Decryption error
    level = int(level[1:])
    data = data[2:]
    try:
        data = eval(data)
    except:
        return False  #Decryption problem
    if level in [2, 3]:
        fh = open('diary.hash', 'r')
        hashf = fh.read()
        fh.close()
        if hashf != md5calc(stringc) + md5calc(repr(data)):
            return [data, level, 'ERROR!']
        else:
            return [data, level]
    else:
        return [data, level]
def main(args):
    replay = args.replay

    print("Reading header…")
    header = replay.read(8)
    json_blocks_count = header[4]

    for i in range(json_blocks_count):
        read_json(replay)

    replay.read(4)
    length = read_int(replay)
    print("Compressed data length: %d." % length)

    cipher = blowfish.Blowfish(b"\xDE\x72\xBE\xA0\xDE\x04\xBE\xB1\xDE\xFE\xBE\xEF\xDE\xAD\xBE\xEF")
    previous_block = b"\x00" * 8
    blocks = []

    print("Decrypting…")
    while True:
        block = replay.read(8)
        if not block:
            break
        block = cipher.decrypt(block)
        block = bytes(byte1 ^ byte2 for byte1, byte2 in zip(block, previous_block))
        previous_block = block
        blocks.append(block)

    print("Blocks: %d." % len(blocks))
    compressed_data = b"".join(blocks)[:length]

    print("Decompressing…")
    uncompressed_data = zlib.decompress(compressed_data)

    print("Uncompressed data length: %d." % len(uncompressed_data))
    args.output.write(uncompressed_data)

    print("Reading packets…")
    for packet in read_packets(io.BytesIO(uncompressed_data)):
        print(packet, file=args.packets)
Beispiel #12
0
    def read_password(cls, email):
        """
           Read password credentials
           Look for the defined in env GMVAULT_DIR so by default to ~/.gmvault
           Look for file GMVAULT_DIR/email.passwd
        """
        gmv_dir = cls.get_home_dir_path()

        #look for email.passwed in GMV_DIR
        user_passwd_file_path = "%s/%s.passwd" % (gmv_dir, email)

        password = None
        if os.path.exists(user_passwd_file_path):
            passwd_file = open(user_passwd_file_path)

            password = passwd_file.read()
            cipher = blowfish.Blowfish(cls.get_secret())
            cipher.initCTR()
            password = cipher.decryptCTR(password)

            LOG.debug("password=[%s]" % (password))

        return password
Beispiel #13
0
    def read_password(cls, email):
        """
           Read password credentials
           Look by default to ~/.gmvault
           Look for file ~/.gmvault/email.passwd
        """
        gmv_dir = gmvault_utils.get_home_dir_path()
        
        #look for email.passwed in GMV_DIR
        user_passwd_file_path = "%s/%s.passwd" % (gmv_dir, email)

        password = None
        if os.path.exists(user_passwd_file_path):
            passwd_file  = open(user_passwd_file_path)
            
            password     = passwd_file.read()
            cipher       = blowfish.Blowfish(cls.get_secret_key(cls.SECRET_FILEPATH % (gmvault_utils.get_home_dir_path())))
            cipher.initCTR()
            password     = cipher.decryptCTR(password)

            #LOG.debug("password=[%s]" % (password))
        
        return password
Beispiel #14
0
 def __init__(self, filename, key):
     # The name of the file that is going to be encoded
     self.filename = filename
     self.key = key
     self.bf = blowfish.Blowfish(key)
 def encrypt(self, password, salt, text):
     key = str(password + salt)
     cipher = blowfish.Blowfish(key)
     cipher.initCTR()
     return cipher.encryptCTR(text)