msfenv.rb 3.0 KB

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