CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/metasploit/framework/command/console.rb
Views: 1904
1
#
2
# Project
3
#
4
5
require 'metasploit/framework/command'
6
require 'metasploit/framework/command/base'
7
require 'rex/text'
8
9
# Based on pattern used for lib/rails/commands in the railties gem.
10
class Metasploit::Framework::Command::Console < Metasploit::Framework::Command::Base
11
12
# Provides an animated spinner in a separate thread.
13
#
14
# See GitHub issue #4147, as this may be blocking some
15
# Windows instances, which is why Windows platforms
16
# should simply return immediately.
17
18
def spinner
19
return if Rex::Compat.is_windows
20
return if Rex::Compat.is_cygwin
21
return if $msf_spinner_thread
22
$msf_spinner_thread = Thread.new do
23
base_line = "[*] Starting the Metasploit Framework console..."
24
cycle = 0
25
loop do
26
%q{/-\|}.each_char do |c|
27
status = "#{base_line}#{c}\r"
28
cycle += 1
29
off = cycle % base_line.length
30
case status[off, 1]
31
when /[a-z]/
32
status[off, 1] = status[off, 1].upcase
33
when /[A-Z]/
34
status[off, 1] = status[off, 1].downcase
35
end
36
$stderr.print status
37
::IO.select(nil, nil, nil, 0.10)
38
end
39
end
40
end
41
end
42
43
def start
44
case parsed_options.options.subcommand
45
when :version
46
$stderr.puts "Framework Version: #{Metasploit::Framework::VERSION}"
47
else
48
unless parsed_options.options.console.quiet
49
colorizor = Struct.new(:supports_color?).new(false).extend(Rex::Text::Color)
50
$stdout.print colorizor.substitute_colors(Rex::Text.wordwrap("Metasploit tip: #{Msf::Ui::Tip.sample}\n", indent = 0, cols = 80))
51
spinner
52
end
53
54
driver.run
55
end
56
end
57
58
private
59
60
# The console UI driver.
61
#
62
# @return [Msf::Ui::Console::Driver]
63
def driver
64
unless @driver
65
66
@driver = Msf::Ui::Console::Driver.new(
67
Msf::Ui::Console::Driver::DefaultPrompt,
68
Msf::Ui::Console::Driver::DefaultPromptChar,
69
driver_options
70
)
71
end
72
73
@driver
74
end
75
76
def driver_options
77
unless @driver_options
78
options = parsed_options.options
79
80
driver_options = {}
81
driver_options['Config'] = options.framework.config
82
driver_options['ConfirmExit'] = options.console.confirm_exit
83
driver_options['DatabaseEnv'] = options.environment
84
driver_options['DatabaseMigrationPaths'] = options.database.migrations_paths
85
driver_options['DatabaseYAML'] = options.database.config
86
driver_options['DeferModuleLoads'] = options.modules.defer_loads
87
driver_options['DisableBanner'] = options.console.quiet
88
driver_options['DisableDatabase'] = options.database.disable
89
driver_options['HistFile'] = options.console.histfile
90
driver_options['LocalOutput'] = options.console.local_output
91
driver_options['Logger'] = options.console.logger
92
driver_options['ModulePath'] = options.modules.path
93
driver_options['Plugins'] = options.console.plugins
94
driver_options['Readline'] = options.console.readline
95
driver_options['Resource'] = options.console.resources
96
driver_options['XCommands'] = options.console.commands
97
98
@driver_options = driver_options
99
end
100
101
@driver_options
102
end
103
end
104
105