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


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
# File 'lib/msf/ui/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 and framework.db.usable and framework.db.migrated
    opts['SkipDatabaseInit'] = true
  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/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/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/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/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/console.rb', line 13

def pipe
  @pipe
end

#threadObject

Returns the value of attribute thread


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

def thread
  @thread
end

Instance Method Details

#active_moduleObject


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

def active_module
  self.console.active_module
end

#active_module=(val) ⇒ Object


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

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

#busyObject


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

def busy
  self.console.busy
end

#execute(cmd) ⇒ Object


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

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

#promptObject


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

def prompt
  self.pipe.prompt
end

#readObject


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

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

#session_detachObject


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/msf/ui/web/console.rb', line 114

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


131
132
133
# File 'lib/msf/ui/web/console.rb', line 131

def session_kill
  self.thread.raise(Interrupt)
end

#shutdownObject


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

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

#tab_complete(cmd) ⇒ Object


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

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


76
77
78
# File 'lib/msf/ui/web/console.rb', line 76

def update_access
  self.last_access = Time.now
end

#write(buf) ⇒ Object


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

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