2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-12-12 07:07:19 +00:00
|
|
|
require 'msf/base'
|
2011-05-12 20:03:55 +00:00
|
|
|
require 'rex/services/local_relay'
|
2005-12-12 07:07:19 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Sessions
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
#
|
|
|
|
###
|
2010-04-03 05:21:15 +00:00
|
|
|
class VncInject
|
2005-12-12 07:07:19 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2010-04-03 05:21:15 +00:00
|
|
|
def initialize(rstream, opts={})
|
2005-12-12 07:07:19 +00:00
|
|
|
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
|
|
|
|
|
2011-04-18 20:07:53 +00:00
|
|
|
#
|
|
|
|
# Skip session registration for VNC
|
|
|
|
#
|
|
|
|
def register?
|
|
|
|
false
|
|
|
|
end
|
2011-11-20 01:11:40 +00:00
|
|
|
|
2005-12-12 07:07:19 +00:00
|
|
|
#
|
|
|
|
# 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
|
2010-04-03 05:21:15 +00:00
|
|
|
|
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 {
|
2010-04-03 05:21:15 +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 {
|
2010-04-03 05:21:15 +00:00
|
|
|
|
|
|
|
if (self.conn_eof == false)
|
2005-12-12 07:07:19 +00:00
|
|
|
print_status("VNC connection closed.")
|
|
|
|
self.conn_eof = true
|
2010-04-03 05:21:15 +00:00
|
|
|
|
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
|
2010-04-03 05:21:15 +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.
|
|
|
|
#
|
2010-06-22 00:09:50 +00:00
|
|
|
# Returns true if we were able to find the executable and false otherwise.
|
|
|
|
# Note that this says nothing about whether it worked, only that we found
|
|
|
|
# the file.
|
|
|
|
#
|
2005-12-12 07:07:19 +00:00
|
|
|
def autovnc
|
2010-04-03 05:21:15 +00:00
|
|
|
vnc =
|
|
|
|
Rex::FileUtils::find_full_path('vncviewer') ||
|
2007-02-18 04:25:46 +00:00
|
|
|
Rex::FileUtils::find_full_path('vncviewer.exe')
|
2010-04-03 05:21:15 +00:00
|
|
|
|
2007-02-18 04:25:46 +00:00
|
|
|
if (vnc)
|
2010-11-12 06:19:49 +00:00
|
|
|
self.view = framework.threads.spawn("VncViewerWrapper", false) {
|
2005-12-12 07:07:19 +00:00
|
|
|
system("vncviewer #{vlhost}::#{vlport}")
|
|
|
|
}
|
2005-12-13 03:48:33 +00:00
|
|
|
|
2010-06-22 00:09:50 +00:00
|
|
|
return true
|
2005-12-12 07:07:19 +00:00
|
|
|
end
|
2010-06-22 00:09:50 +00:00
|
|
|
false
|
2005-12-12 07:07:19 +00:00
|
|
|
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
|
2010-04-03 05:21:15 +00:00
|
|
|
end
|
|
|
|
|