Пример #1
0
def get_vnc_hash(password):
    passpadd = (password + '\x00' * 8)[:8]
    strkey = ''.join([chr(x) for x in d.vnckey])
    ekey = d.deskey(strkey, False)

    hashed = d.desfunc(passpadd, ekey)
    return hashed.encode('hex')
Пример #2
0
 def get_vnc_enc(password):
     import d3des
     passpadd = (password + '\x00' * 8)[:8]
     strkey = ''.join([chr(x) for x in d3des.vnckey])
     ekey = d3des.deskey(strkey, False)
     ctext = d3des.desfunc(passpadd, ekey)
     return ctext.encode('hex')
Пример #3
0
def get_vnc_hash(password):
    '''
        Given a password, return a UltraVNC compatible hash from its first
        eight chars.
        Arguments:
            password
        Returns:
            hash string.
        Requires:
            d3des module to be available.
            http://vnc2flv.googlecode.com/svn-history/r2/trunk/vnc2flv/vnc2flv/d3des.py
    '''
    hashstr = None
    try:
        import d3des as d
    except ImportError:
        _log.warn(
            'Hash algorithm module not found, skipping VNC password set.')
    else:
        passpadd = (password + '\x00' * 8)[:8]
        strkey = ''.join([chr(x) for x in d.vnckey])
        ekey = d.deskey(strkey, False)

        hashed = d.desfunc(passpadd, ekey)
        hashstr = hashed.encode('hex')
        _log.info('VNC password hash: ' + hashstr)
    return hashstr
Пример #4
0
def get_vnc_hash(password):
    passpadd = (password + "\x00" * 8)[:8]
    strkey = "".join([chr(x) for x in d.vnckey])
    ekey = d.deskey(strkey, False)

    hashed = d.desfunc(passpadd, ekey)
    return hashed.encode("hex")
Пример #5
0
def get_vnc_hash(password):
    '''
        Given a password, return a UltraVNC compatible hash from its first
        eight chars.
        Arguments:
            password
        Returns:
            hash string.
        Requires:
            d3des module to be available.
            http://vnc2flv.googlecode.com/svn-history/r2/trunk/vnc2flv/vnc2flv/d3des.py
    '''
    hashstr = None
    try:
        import d3des as d
    except ImportError:
        _log.warn('Hash algorithm module not found, skipping VNC password set.')
    else:
        passpadd = (password + '\x00'*8)[:8]
        strkey = ''.join([ chr(x) for x in d.vnckey ])
        ekey = d.deskey(strkey, False)

        hashed = d.desfunc(passpadd, ekey)
        hashstr = hashed.encode('hex')
        _log.info('VNC password hash: ' + hashstr)
    return hashstr
Пример #6
0
def encode_password(password):
    if not isinstance(password, bytes):
        raise ValueError('Password should be passed as bytes')
    passpadd = (password + b'\x00' * 8)[:8]
    strkey = bytes(d3des.vnckey)
    ekey = d3des.deskey(strkey, False)
    ctext = d3des.desfunc(passpadd, ekey)
    return ctext
Пример #7
0
def apply_vncpasswd_configuration(item, value, root_path):
    file = item.get("file")
    if not file: return
    check_pathelement_security(file)

    ek = d3des.deskey(pack('8B', *d3des.vnckey), False)
    encrypted = d3des.desfunc((value + '\x00' * 8)[:8], ek)

    target_file = "%s/%s" % (root_path, file)
    with open(target_file, "w") as vncpasswd:
        vncpasswd.write(encrypted)

    os.chmod(target_file, stat.S_IRUSR | stat.S_IWUSR)
Пример #8
0
def apply_vncpasswd_configuration(item, value, root_path):
    file = item.get("file")
    if not file:
        return
    check_pathelement_security(file)

    ek = d3des.deskey(pack("8B", *d3des.vnckey), False)
    encrypted = d3des.desfunc((value + "\x00" * 8)[:8], ek)

    target_file = "%s/%s" % (root_path, file)
    with open(target_file, "w") as vncpasswd:
        vncpasswd.write(encrypted)

    os.chmod(target_file, stat.S_IRUSR | stat.S_IWUSR)
Пример #9
0
def vnc_crypt(vncpass, decrypt=False):
    if decrypt:
        try:
            passpadd = vncpass.decode("hex")
        except TypeError as e:
            if e.message == "Odd-length string":
                module_logger.warning('WARN: %s . Chopping last char off... "%s"' % (e.message, vncpass[:-1]))
                passpadd = vncpass[:-1].decode("hex")
            else:
                raise
    else:
        passpadd = (vncpass + "\x00" * 8)[:8]
    strkey = "".join([chr(x) for x in d3des.vnckey])
    key = d3des.deskey(strkey, decrypt)
    crypted = d3des.desfunc(passpadd, key)
    if decrypt:
        return crypted.encode("hex").decode("hex")
    else:
        return crypted.encode("hex")
Пример #10
0
    def obfuscate(self):
        """Obfuscate a plaintext password in VNC format"""
        password = self
        # pad password up to 8 chars, truncate anything over 8
        passpadd = (password + '\x00' * 8)[:8]

        # load the vnckey from library and change encoding to ascii
        strkey = ''.join([chr(x) for x in d3des.vnckey])
        ekey = d3des.deskey(bytearray(strkey, encoding="ascii"), False)

        # encrypt the passpadd section from above
        ctext = d3des.desfunc(bytearray(passpadd, encoding="ascii"), ekey)

        # if the password was longer than 8 chars, then recurse, this will chunk the
        # password into 8 character obfuscated sections. versions older than 5 will ignore 8+
        # this method is used by RealVNC but most other implementations truncate at 8

        # if len(password) > 8:
        #	ctext += self.obfuscate(password[8:])
        return ctext
Пример #11
0
def vnc_crypt(vncpass, decrypt=False):
    if (decrypt):
        try:
            passpadd = vncpass.decode('hex')
        except TypeError as e:
            if e.message == 'Odd-length string':
                module_logger.warning(
                    'WARN: %s . Chopping last char off... "%s"' %
                    (e.message, vncpass[:-1]))
                passpadd = vncpass[:-1].decode('hex')
            else:
                raise
    else:
        passpadd = (vncpass + '\x00' * 8)[:8]
    strkey = ''.join([chr(x) for x in d3des.vnckey])
    key = d3des.deskey(strkey, decrypt)
    crypted = d3des.desfunc(passpadd, key)
    if (decrypt):
        return crypted.encode('hex').decode('hex')
    else:
        return crypted.encode('hex')
Пример #12
0
def do_crypt(password, decrypt):
    passpadd = (password + '\x00'*8)[:8]
    strkey = ''.join([ chr(x) for x in d.vnckey ])
    key = d.deskey(strkey, decrypt)
    crypted = d.desfunc(passpadd, key)
    return crypted
Пример #13
0
 def do_crypt(self, password, decrypt):
     passpadd = (password + '\x00' * 8)[:8]
     strkey = ''.join([chr(x) for x in self.vnckey])
     key = d.deskey(strkey, decrypt)
     crypted = d.desfunc(passpadd, key)
     return crypted
Пример #14
0
def get_vnc_enc(password):
    passpadd = (password + '\x00' * 8)[:8]
    strkey = ''.join([chr(x) for x in d.vnckey])
    ekey = d.deskey(strkey, False)
    ctext = d.desfunc(passpadd, ekey)
    return ctext