Skip to content

Commit

Permalink
Merge branch 'master' of github.com:trinitronx/vncpasswd.py
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitronx committed Jun 2, 2017
2 parents 8f26d0e + c4b3997 commit 76ccf2f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.pyc
.idea/misc.xml
*.xml
*.iml
6 changes: 5 additions & 1 deletion WindowsRegistry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import _winreg as wreg
import cPickle as pickle
import platform

class WindowsRegistry:
""" A class to simplify read/write access to the Windows Registry """
Expand Down Expand Up @@ -58,7 +59,10 @@ def __init__(self, company="RealVNC", project="WinVNC4", create=0):
i=0
while not_opened and i<len(rights)-1:
try:
self.key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, self.keyname,0, rights[i])
if platform.machine().endswith('64') and platform.architecture()[0] == '32bit':
self.key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, self.keyname, 0, rights[i] | wreg.KEY_WOW64_64KEY)
else:
self.key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, self.keyname,0, rights[i])
not_opened = False
self.right = rights[i]
#print "rights = %05x" % rights[i]
Expand Down
21 changes: 19 additions & 2 deletions vncpasswd.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def main():
if ( args.filename == None and args.passwd == None and (args.registry == False or not platform.system().startswith('Windows')) ):
parser.error('Error: No password file or password passed\n')
if ( args.registry and args.decrypt and platform.system().startswith('Windows')):
reg = wreg.WindowsRegistry("RealVNC", "WinVNC4")
reg = get_realvnc_key()
( args.passwd, key_type) = reg.getval("Password")
elif not platform.system().startswith('Windows'):
print 'Cannot read from Windows Registry on a %s system' % platform.system()
Expand Down Expand Up @@ -159,7 +159,7 @@ def main():
if ( args.filename != None and not args.decrypt ):
do_file_out(args.filename, crypted, args.hex)
if ( args.registry and not args.decrypt and platform.system().startswith('Windows')):
reg = wreg.WindowsRegistry("RealVNC", "WinVNC4")
reg = get_realvnc_key()
reg.setval('Password', crypted, wreg.WindowsRegistry.REG_BINARY)
elif not platform.system().startswith('Windows'):
print 'Cannot write to Windows Registry on a %s system' % platform.system()
Expand All @@ -168,5 +168,22 @@ def main():
print "%scrypted Bin Pass= '%s'" % ( prefix, crypted )
print "%scrypted Hex Pass= '%s'" % ( prefix, crypted.encode('hex') )


def get_realvnc_key():
reg = None

for k in ['vncserver', 'WinVNC4',]:
try:
reg = wreg.WindowsRegistry('RealVNC', k)
break
except WindowsError as e:
if 'The system cannot find the file specified' in str(e):
pass
else:
raise e

return reg


if __name__ == '__main__':
main()

0 comments on commit 76ccf2f

Please sign in to comment.