Class: Msf::Sessions::VncInject

Inherits:
Object
  • Object
show all
Includes:
Msf::Session, Msf::Session::Basic
Defined in:
lib/msf/base/sessions/vncinject.rb

Instance Attribute Summary

Attributes included from Msf::Session::Interactive

#ring, #rstream

Attributes included from Rex::Ui::Interactive

#completed, #interacting, #on_command_proc, #on_print_proc

Attributes included from Rex::Ui::Subscriber::Input

#user_input

Attributes included from Rex::Ui::Subscriber::Output

#user_output

Attributes included from Msf::Session

#alive, #db_record, #exploit, #exploit_datastore, #exploit_task, #exploit_uuid, #framework, #info, #routes, #sid, #sname, #target_host, #target_port, #username, #uuid, #workspace

Attributes included from Framework::Offspring

#framework

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Msf::Session::Interactive

#kill, #run_cmd, #tunnel_local, #tunnel_peer

Methods included from Rex::Ui::Interactive

#detach, #interact

Methods included from Rex::Ui::Subscriber

#copy_ui, #init_ui, #reset_ui

Methods included from Rex::Ui::Subscriber::Input

#gets

Methods included from Rex::Ui::Subscriber::Output

#flush, #print, #print_debug, #print_error, #print_good, #print_line, #print_status, #print_warning

Methods included from Msf::Session

#alive?, #dead?, #inspect, #kill, #log_file_name, #log_from_local, #log_from_remote, #log_source, #name, #name=, #session_host, #session_host=, #session_port, #session_port=, #set_from_exploit, #set_via, #tunnel_local, #tunnel_peer, #tunnel_to_s, #via_exploit, #via_payload

Constructor Details

#initialize(rstream, opts = {}) ⇒ VncInject

Initializes a vncinject session instance using the supplied rstream that is to be used as the client's connection to the server.


24
25
26
27
28
29
# File 'lib/msf/base/sessions/vncinject.rb', line 24

def initialize(rstream, opts={})
  super

  self.conn_eof = false
  self.got_conn = false
end

Class Method Details

.typeObject

Returns the session type as being 'vncinject'.


59
60
61
# File 'lib/msf/base/sessions/vncinject.rb', line 59

def self.type
  "vncinject"
end

Instance Method Details

#_interactObject

:nodoc:

Raises:

  • (EOFError)

83
84
85
86
87
# File 'lib/msf/base/sessions/vncinject.rb', line 83

def _interact # :nodoc:
  raise EOFError if (self.conn_eof == true)

  sleep(1)
end

#autovnc(viewonly = true) ⇒ Object

Launches VNC viewer against the local relay for this VNC server session.

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.


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/msf/base/sessions/vncinject.rb', line 155

def autovnc(viewonly=true)
  vnc =
    Rex::FileUtils::find_full_path('vncviewer') ||
    Rex::FileUtils::find_full_path('vncviewer.exe')

  if (vnc)
    args = []
    args.push '-viewonly' if viewonly
    args.push "#{vlhost}::#{vlport}"

    self.view = framework.threads.spawn("VncViewerWrapper", false) {
      system(vnc, *args)
    }

    return true
  end
  false
end

#cleanupObject

Cleans up the local relay and closes the stream.


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/msf/base/sessions/vncinject.rb', line 34

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

#descObject

Returns the session description.


72
73
74
# File 'lib/msf/base/sessions/vncinject.rb', line 72

def desc
  "VNC Server"
end

#interactive?Boolean

Not interactive in the normal sense

Returns:

  • (Boolean)

92
93
94
# File 'lib/msf/base/sessions/vncinject.rb', line 92

def interactive?
  false
end

#register?Boolean

Skip session registration for VNC

Returns:

  • (Boolean)

52
53
54
# File 'lib/msf/base/sessions/vncinject.rb', line 52

def register?
  false
end

#setup_relay(port, host = '127.0.0.1') ⇒ Object

Sets up a local relay that is associated with the stream connection


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/msf/base/sessions/vncinject.rb', line 105

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 {

            if (self.got_conn == true)
              nil
            else
              self.got_conn = true

              rstream
            end
          },
          'OnConnectionClose' => Proc.new {

            if (self.conn_eof == false)
              print_status("VNC connection closed.")
              self.conn_eof = true

              # Closing time
              self.view.kill if self.view
              self.view = nil
              self.kill
            end

          },
          '__RelayType'       => 'vncinject')
      end
    else
      raise RuntimeError, "Relay failed to start."
    end
  end
end

#typeObject

Calls the class method.


79
80
81
# File 'lib/msf/base/sessions/vncinject.rb', line 79

def type
  self.class.type
end