Class: Msf::Ui::Web::WebConsole

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

Overview

This class implements a console instance for use by the web interface

Defined Under Namespace

Modules: WebConsoleShell Classes: WebConsolePipe

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework, console_id, opts = {}) ⇒ WebConsole

Returns a new instance of WebConsole.


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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/msf/ui/web/web_console.rb', line 37

def initialize(framework, console_id, opts={})
  # Configure the framework
  self.framework = framework

  # Configure the ID
  self.console_id = console_id

  # Create a new pipe
  self.pipe = WebConsolePipe.new

  # Create a read subscriber
  self.pipe.create_subscriber('msfweb')

  # Skip database initialization if it is already configured
  if framework.db && framework.db.active
    opts['SkipDatabaseInit'] = true
    if opts['workspace']
      wspace = framework.db.find_workspace(opts['workspace'])
      framework.db.workspace = wspace
    end
  end

  # Initialize the console with our pipe
  self.console = Msf::Ui::Console::Driver.new(
    'msf',
    '>',
    opts.merge({
      'Framework'   => self.framework,
      'LocalInput'  => self.pipe,
      'LocalOutput' => self.pipe,
      'AllowCommandPassthru' => true,
      'Resource'    => [],
    })
  )

  self.console.extend(WebConsoleShell)
  self.console.block_command('irb')

  self.thread = framework.threads.spawn("WebConsoleShell", false) { self.console.run }

  update_access()
end

Instance Attribute Details

#consoleObject

Returns the value of attribute console


14
15
16
# File 'lib/msf/ui/web/web_console.rb', line 14

def console
  @console
end

#console_idObject

Returns the value of attribute console_id


15
16
17
# File 'lib/msf/ui/web/web_console.rb', line 15

def console_id
  @console_id
end

#frameworkObject

Returns the value of attribute framework


17
18
19
# File 'lib/msf/ui/web/web_console.rb', line 17

def framework
  @framework
end

#last_accessObject

Returns the value of attribute last_access


16
17
18
# File 'lib/msf/ui/web/web_console.rb', line 16

def last_access
  @last_access
end

#pipeObject

Returns the value of attribute pipe


13
14
15
# File 'lib/msf/ui/web/web_console.rb', line 13

def pipe
  @pipe
end

#threadObject

Returns the value of attribute thread


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

def thread
  @thread
end

Instance Method Details

#active_moduleObject


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

def active_module
  self.console.active_module
end

#active_module=(val) ⇒ Object


143
144
145
# File 'lib/msf/ui/web/web_console.rb', line 143

def active_module=(val)
  self.console.active_module = val
end

#busyObject


114
115
116
# File 'lib/msf/ui/web/web_console.rb', line 114

def busy
  self.console.busy
end

#execute(cmd) ⇒ Object


94
95
96
# File 'lib/msf/ui/web/web_console.rb', line 94

def execute(cmd)
  self.console.run_single(cmd)
end

#promptObject


98
99
100
# File 'lib/msf/ui/web/web_console.rb', line 98

def prompt
  self.pipe.prompt
end

#readObject


84
85
86
87
# File 'lib/msf/ui/web/web_console.rb', line 84

def read
  update_access
  self.pipe.read_subscriber('msfweb')
end

#session_detachObject


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/msf/ui/web/web_console.rb', line 118

def session_detach
  if(self.console.active_session)
    #background interactive meterpreter channel
    if(self.console.active_session.respond_to?('channels'))
      self.console.active_session.channels.each_value do |ch|
        if(ch.respond_to?('interacting') && ch.interacting)
          ch.detach()
          return
        end
      end
    end
    #background session
    self.console.active_session.completed = true
    self.console.active_session.detach()
  end
end

#session_killObject


135
136
137
# File 'lib/msf/ui/web/web_console.rb', line 135

def session_kill
  self.thread.raise(Interrupt)
end

#shutdownObject


109
110
111
112
# File 'lib/msf/ui/web/web_console.rb', line 109

def shutdown
  self.pipe.close
  self.thread.kill
end

#tab_complete(cmd) ⇒ Object


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

def tab_complete(cmd)
  if(self.console.active_session)
    return self.console.active_session.console.tab_complete(cmd)
  end
  self.console.tab_complete(cmd)
end

#update_accessObject


80
81
82
# File 'lib/msf/ui/web/web_console.rb', line 80

def update_access
  self.last_access = Time.now
end

#write(buf) ⇒ Object


89
90
91
92
# File 'lib/msf/ui/web/web_console.rb', line 89

def write(buf)
  update_access
  self.pipe.write_input(buf)
end