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/msfenv.rb
Views: 1903
1
# Use bundler to load dependencies
2
#
3
4
# Enable legacy providers such as blowfish-cbc, cast128-cbc, arcfour, etc
5
$stderr.puts "Overriding user environment variable 'OPENSSL_CONF' to enable legacy functions." unless ENV['OPENSSL_CONF'].nil?
6
ENV['OPENSSL_CONF'] = File.expand_path(
7
File.join(File.dirname(__FILE__), '..', 'config', 'openssl.conf')
8
)
9
10
if ENV['KRB5CCNAME']
11
$stderr.puts 'Warning: KRB5CCNAME environment variable not supported - unsetting'
12
ENV['KRB5CCNAME'] = nil
13
end
14
15
# Override the normal rails default, so that msfconsole will come up in production mode instead of development mode
16
# unless the `--environment` flag is passed.
17
ENV['RAILS_ENV'] ||= 'production'
18
19
require 'pathname'
20
root = Pathname.new(__FILE__).expand_path.parent.parent
21
config = root.join('config')
22
require config.join('boot')
23
24
# Requiring environment will define the Metasploit::Framework::Application as the one and only Rails::Application in
25
# this process and cause an error if a Rails.application is already defined, such as when loading msfenv through
26
# msfconsole in Metasploit Pro.
27
unless defined?(Rails) && !Rails.application.nil?
28
require config.join('environment')
29
end
30
require 'msf_autoload'
31
32
# Disable the enhanced error messages introduced as part of Ruby 3.1, as some error messages are directly shown to users,
33
# and the default ErrorHighlight formatter displays unneeded Ruby code to the user
34
# https://github.com/ruby/error_highlight/tree/f3626b9032bd1024d058984329accb757687cee4#custom-formatter
35
if defined?(::ErrorHighlight)
36
noop_error_formatter = Object.new
37
def noop_error_formatter.message_for(_spot)
38
''
39
end
40
::ErrorHighlight.formatter = noop_error_formatter
41
end
42
43
MsfAutoload.instance
44
45
def _warn_deprecation_message(method)
46
stack_size = 3
47
warning_message = "[DEPRECATION] The global method #{method.inspect} is deprecated, please raise a Github issue with this output. Called from: #{caller(1, stack_size).to_a}"
48
warn(warning_message)
49
# Additionally write to ~/.msf4/logs/framework.log - as this gets attached to Github issues etc
50
elog(warning_message)
51
end
52
53
# @deprecated In most scenarios you should delegate to either a framework module object, or Rex::Ui::Text::DispatcherShell etc
54
def print_line(msg)
55
_warn_deprecation_message __method__
56
$stdout.puts(msg)
57
end
58
59
# @deprecated In most scenarios you should delegate to either a framework module object, or Rex::Ui::Text::DispatcherShell etc
60
def print_warning(msg)
61
_warn_deprecation_message __method__
62
$stderr.puts(msg)
63
end
64
65
# @deprecated In most scenarios you should delegate to either a framework module object, or Rex::Ui::Text::DispatcherShell etc
66
def print_good(msg)
67
_warn_deprecation_message __method__
68
$stdout.puts(msg)
69
end
70
71
# @deprecated In most scenarios you should delegate to either a framework module object, or Rex::Ui::Text::DispatcherShell etc
72
def print_error(msg, exception = nil)
73
_warn_deprecation_message __method__
74
75
unless exception.nil?
76
msg += "\n Call Stack:"
77
exception.backtrace.each {|line|
78
msg += "\n"
79
msg += "\t #{line}"
80
}
81
end
82
83
$stderr.puts(msg)
84
end
85
86