Class: Msf::Ui::Web::Driver

Inherits:
Driver
  • Object
show all
Defined in:
lib/msf/ui/web/driver.rb

Overview

This class implements a user interface driver on a web interface.

Constant Summary collapse

ConfigCore =
"framework/core"
ConfigGroup =
"framework/ui/web"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Driver

#cleanup, #stop

Constructor Details

#initialize(opts = {}) ⇒ Driver

Initializes a web driver instance and prepares it for listening to HTTP requests. The constructor takes a hash of options that can control how the web server will operate.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/msf/ui/web/driver.rb', line 31

def initialize(opts = {})
  # Call the parent
  super()

  # Set the passed options hash for referencing later on.
  self.opts = opts

  self.consoles = {}
  self.sessions = {}

  if(opts[:framework])
    self.framework = opts[:framework]
  else
    # Initialize configuration
    Msf::Config.init

    # Initialize logging
    initialize_logging

    # Initialize attributes
    self.framework = Msf::Simple::Framework.create
  end

  # Initialize the console count
  self.last_console = 0
end

Instance Attribute Details

#consolesObject

:nodoc:



19
20
21
# File 'lib/msf/ui/web/driver.rb', line 19

def consoles
  @consoles
end

#frameworkObject

:nodoc:



18
19
20
# File 'lib/msf/ui/web/driver.rb', line 18

def framework
  @framework
end

#last_consoleObject

:nodoc:



21
22
23
# File 'lib/msf/ui/web/driver.rb', line 21

def last_console
  @last_console
end

#optsObject (protected)

:nodoc:



145
146
147
# File 'lib/msf/ui/web/driver.rb', line 145

def opts
  @opts
end

#sessionsObject

:nodoc:



20
21
22
# File 'lib/msf/ui/web/driver.rb', line 20

def sessions
  @sessions
end

Instance Method Details

#clean_consoles(timeout = 300) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/msf/ui/web/driver.rb', line 85

def clean_consoles(timeout=300)
  self.consoles.each_pair do |id, con|
    if (con.last_access + timeout < Time.now)
      con.shutdown
      self.consoles.delete(id)
    end
  end
end

#connect_session(id) ⇒ Object

Detach the session from an existing input/output pair



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/msf/ui/web/driver.rb', line 109

def connect_session(id)

  # Ignore invalid sessions
  ses = self.framework.sessions[id]
  return if not ses

  # Has this session already been detached?
  if (ses.user_output)
    return if ses.user_output.has_subscriber?('session_reader')
  end

  # Create a new pipe
  spipe = WebConsole::WebConsolePipe.new
  spipe.input = spipe.pipe_input

  # Create a read subscriber
  spipe.create_subscriber('session_reader')

  framework.threads.spawn("ConnectSessionInteraction", false) do
    ses.interact(spipe.input, spipe)
  end
end

#create_console(opts = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/msf/ui/web/driver.rb', line 58

def create_console(opts={})
  # Destroy any unused consoles
  clean_consoles

  console = WebConsole.new(self.framework, self.last_console, opts)
  self.last_console += 1
  self.consoles[console.console_id.to_s] = console
  console.console_id.to_s
end

#destroy_console(cid) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/msf/ui/web/driver.rb', line 68

def destroy_console(cid)
  con = self.consoles[cid]
  if(con)
    con.shutdown
    self.consoles.delete(cid)
  end
end

#initialize_loggingObject (protected)

Initializes logging for the web interface



150
151
152
153
154
# File 'lib/msf/ui/web/driver.rb', line 150

def initialize_logging
  level = (opts['LogLevel'] || 0).to_i

  Msf::Logging.enable_log_source(LogSource, level)
end

#read_console(id) ⇒ Object



81
82
83
# File 'lib/msf/ui/web/driver.rb', line 81

def read_console(id)
  self.consoles[id] ? self.consoles[id].read() : nil
end

#read_session(id) ⇒ Object



101
102
103
104
105
106
# File 'lib/msf/ui/web/driver.rb', line 101

def read_session(id)
  ses = self.framework.sessions[id]
  return if not ses
  return if not ses.user_output
  ses.user_output.read_subscriber('session_reader')
end

#runObject

Stub



139
140
141
# File 'lib/msf/ui/web/driver.rb', line 139

def run
  true
end

#write_console(id, buf) ⇒ Object



77
78
79
# File 'lib/msf/ui/web/driver.rb', line 77

def write_console(id, buf)
  self.consoles[id] ? self.consoles[id].write(buf) : nil
end

#write_session(id, buf) ⇒ Object



94
95
96
97
98
99
# File 'lib/msf/ui/web/driver.rb', line 94

def write_session(id, buf)
  ses = self.framework.sessions[id]
  return if not ses
  return if not ses.user_input
  ses.user_input.put(buf)
end