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.


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/msf/ui/web/driver.rb', line 36

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

Returns the value of attribute consoles


24
25
26
# File 'lib/msf/ui/web/driver.rb', line 24

def consoles
  @consoles
end

#frameworkObject

:nodoc:


23
24
25
# File 'lib/msf/ui/web/driver.rb', line 23

def framework
  @framework
end

#last_consoleObject

:nodoc:


26
27
28
# File 'lib/msf/ui/web/driver.rb', line 26

def last_console
  @last_console
end

#sessionsObject

:nodoc: :nodoc:


25
26
27
# File 'lib/msf/ui/web/driver.rb', line 25

def sessions
  @sessions
end

Instance Method Details

#clean_consoles(timeout = 300) ⇒ Object


90
91
92
93
94
95
96
97
# File 'lib/msf/ui/web/driver.rb', line 90

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


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/msf/ui/web/driver.rb', line 114

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


63
64
65
66
67
68
69
70
71
# File 'lib/msf/ui/web/driver.rb', line 63

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


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

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

#read_console(id) ⇒ Object


86
87
88
# File 'lib/msf/ui/web/driver.rb', line 86

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

#read_session(id) ⇒ Object


106
107
108
109
110
111
# File 'lib/msf/ui/web/driver.rb', line 106

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


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

def run
  true
end

#write_console(id, buf) ⇒ Object


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

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

#write_session(id, buf) ⇒ Object


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

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