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

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/ui/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.


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
79
# File 'lib/msf/ui/web/console.rb', line 38

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


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

def console
  @console
end

#console_idObject

Returns the value of attribute console_id


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

def console_id
  @console_id
end

#frameworkObject

Returns the value of attribute framework


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

def framework
  @framework
end

#last_accessObject

Returns the value of attribute last_access


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

def last_access
  @last_access
end

#pipeObject

Returns the value of attribute pipe


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

def pipe
  @pipe
end

#threadObject

Returns the value of attribute thread


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

def thread
  @thread
end

Instance Method Details

#active_moduleObject


140
141
142
# File 'lib/msf/ui/web/console.rb', line 140

def active_module
  self.console.active_module
end

#active_module=(val) ⇒ Object


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

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

#busyObject


115
116
117
# File 'lib/msf/ui/web/console.rb', line 115

def busy
  self.console.busy
end

#execute(cmd) ⇒ Object


95
96
97
# File 'lib/msf/ui/web/console.rb', line 95

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

#promptObject


99
100
101
# File 'lib/msf/ui/web/console.rb', line 99

def prompt
  self.pipe.prompt
end

#readObject


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

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

#session_detachObject


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

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


136
137
138
# File 'lib/msf/ui/web/console.rb', line 136

def session_kill
  self.thread.raise(Interrupt)
end

#shutdownObject


110
111
112
113
# File 'lib/msf/ui/web/console.rb', line 110

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

#tab_complete(cmd) ⇒ Object


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

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


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

def update_access
  self.last_access = Time.now
end

#write(buf) ⇒ Object


90
91
92
93
# File 'lib/msf/ui/web/console.rb', line 90

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