2005-12-12 07:07:19 +00:00
|
|
|
require 'msf/base'
|
|
|
|
require 'rex/services/local_relay'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Sessions
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class VncInject
|
|
|
|
|
|
|
|
#
|
|
|
|
# The vncinject session is interactive
|
|
|
|
#
|
|
|
|
include Msf::Session
|
2008-01-06 20:02:49 +00:00
|
|
|
include Msf::Session::Basic
|
2005-12-12 07:07:19 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Initializes a vncinject session instance using the supplied rstream
|
|
|
|
# that is to be used as the client's connection to the server.
|
|
|
|
#
|
|
|
|
def initialize(rstream)
|
|
|
|
super
|
|
|
|
|
|
|
|
self.conn_eof = false
|
|
|
|
self.got_conn = false
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Cleans up the local relay and closes the stream.
|
|
|
|
#
|
|
|
|
def cleanup
|
|
|
|
# Stop the local TCP relay
|
|
|
|
service = Rex::ServiceManager.start(Rex::Services::LocalRelay)
|
|
|
|
|
|
|
|
if (service)
|
|
|
|
begin
|
|
|
|
service.stop_tcp_relay(vlport, vlhost) if (vlport)
|
|
|
|
ensure
|
|
|
|
service.deref
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the session type as being 'vncinject'.
|
|
|
|
#
|
|
|
|
def self.type
|
|
|
|
"vncinject"
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Msf::Session overrides
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the session description.
|
|
|
|
#
|
|
|
|
def desc
|
|
|
|
"VNC Server"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Calls the class method.
|
|
|
|
#
|
|
|
|
def type
|
|
|
|
self.class.type
|
|
|
|
end
|
|
|
|
|
2005-12-13 02:40:35 +00:00
|
|
|
def _interact # :nodoc:
|
2005-12-12 07:07:19 +00:00
|
|
|
raise EOFError if (self.conn_eof == true)
|
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
end
|
|
|
|
|
2008-01-06 20:02:49 +00:00
|
|
|
#
|
|
|
|
# Not interactive in the normal sense
|
|
|
|
#
|
|
|
|
def interactive?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2005-12-12 07:07:19 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# VNC Server specific interfaces
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Sets up a local relay that is associated with the stream connection
|
|
|
|
#
|
|
|
|
def setup_relay(port, host = '127.0.0.1')
|
|
|
|
if (port)
|
|
|
|
self.vlhost = host
|
|
|
|
self.vlport = port
|
|
|
|
|
|
|
|
service = Rex::ServiceManager.start(Rex::Services::LocalRelay)
|
|
|
|
|
|
|
|
if (service)
|
|
|
|
begin
|
|
|
|
service.start_tcp_relay(port,
|
|
|
|
'LocalHost' => host,
|
|
|
|
'Stream' => true,
|
|
|
|
'OnLocalConnection' => Proc.new {
|
2008-01-06 20:02:49 +00:00
|
|
|
|
2005-12-12 07:07:19 +00:00
|
|
|
if (self.got_conn == true)
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
self.got_conn = true
|
|
|
|
|
|
|
|
rstream
|
|
|
|
end
|
|
|
|
},
|
|
|
|
'OnConnectionClose' => Proc.new {
|
2008-01-06 20:02:49 +00:00
|
|
|
|
2005-12-12 07:07:19 +00:00
|
|
|
if (self.conn_eof == false)
|
|
|
|
print_status("VNC connection closed.")
|
|
|
|
self.conn_eof = true
|
2008-01-06 20:02:49 +00:00
|
|
|
|
|
|
|
# Closing time
|
|
|
|
self.view.kill if self.view
|
|
|
|
self.view = nil
|
|
|
|
self.kill
|
2005-12-12 07:07:19 +00:00
|
|
|
end
|
2008-01-06 20:02:49 +00:00
|
|
|
|
2005-12-12 07:07:19 +00:00
|
|
|
},
|
|
|
|
'__RelayType' => 'vncinject')
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise RuntimeError, "Relay failed to start."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Launches VNC viewer against the local relay for this VNC server session.
|
|
|
|
#
|
|
|
|
def autovnc
|
2007-02-18 04:25:46 +00:00
|
|
|
vnc =
|
|
|
|
Rex::FileUtils::find_full_path('vncviewer') ||
|
|
|
|
Rex::FileUtils::find_full_path('vncviewer.exe')
|
|
|
|
|
|
|
|
if (vnc)
|
2008-01-06 20:02:49 +00:00
|
|
|
self.view = Thread.new {
|
2005-12-12 07:07:19 +00:00
|
|
|
system("vncviewer #{vlhost}::#{vlport}")
|
|
|
|
}
|
2005-12-13 03:48:33 +00:00
|
|
|
|
|
|
|
true
|
2005-12-12 07:07:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
attr_accessor :vlhost # :nodoc:
|
|
|
|
attr_accessor :vlport # :nodoc:
|
|
|
|
attr_accessor :conn_eof # :nodoc:
|
|
|
|
attr_accessor :got_conn # :nodoc:
|
2008-01-06 20:02:49 +00:00
|
|
|
attr_accessor :view # :nodoc:
|
2005-12-12 07:07:19 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2008-10-19 21:03:39 +00:00
|
|
|
end
|