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.



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
80
81
82
83
84
85
86
87
# File 'lib/msf/ui/web/web_console.rb', line 46

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



148
149
150
# File 'lib/msf/ui/web/web_console.rb', line 148

def active_module
  self.console.active_module
end

#active_module=(val) ⇒ Object



152
153
154
# File 'lib/msf/ui/web/web_console.rb', line 152

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

#busyObject



123
124
125
# File 'lib/msf/ui/web/web_console.rb', line 123

def busy
  self.console.busy
end

#execute(cmd) ⇒ Object



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

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

#promptObject



107
108
109
# File 'lib/msf/ui/web/web_console.rb', line 107

def prompt
  self.pipe.prompt
end

#readObject



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

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

#session_detachObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/msf/ui/web/web_console.rb', line 127

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



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

def session_kill
  self.thread.raise(Interrupt)
end

#shutdownObject



118
119
120
121
# File 'lib/msf/ui/web/web_console.rb', line 118

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

#tab_complete(cmd) ⇒ Object



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

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



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

def update_access
  self.last_access = Time.now
end

#write(buf) ⇒ Object



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

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