Extra common engine and fix default encoding
MSP-9653 Extra config and initializers that can we shared between Metasploit::Framework::Application and the future Metasploit::Framework::Engine. Move the default encoding setup from lib/msf/sanity.rb to a before_initialize callback for the shared config so that gems, like gherkin that depend on the utf-8 default internal encoding can be loaded.
This commit is contained in:
parent
3ebe7dfbc8
commit
9d326fcb24
|
@ -26,11 +26,18 @@ Bundler.require(
|
|||
)
|
||||
)
|
||||
|
||||
#
|
||||
# Project
|
||||
#
|
||||
|
||||
require 'metasploit/framework/common_engine'
|
||||
require 'msf/base/config'
|
||||
|
||||
module Metasploit
|
||||
module Framework
|
||||
class Application < Rails::Application
|
||||
include Metasploit::Framework::CommonEngine
|
||||
|
||||
user_config_root = Pathname.new(Msf::Config.get_config_root)
|
||||
user_database_yaml = user_config_root.join('database.yml')
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
#
|
||||
# Standard Library
|
||||
#
|
||||
|
||||
require 'fileutils'
|
||||
|
||||
# `Rails::Engine` behavior common to both {Metasploit::Framework::Application} and {Metasploit::Framework::Engine}.
|
||||
module Metasploit::Framework::CommonEngine
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
#
|
||||
# config
|
||||
#
|
||||
|
||||
# Force binary encoding to remove necessity to set external and internal encoding when construct Strings from
|
||||
# from files. Socket#read always returns a String in ASCII-8bit encoding
|
||||
#
|
||||
# @see http://rubydoc.info/stdlib/core/IO:read
|
||||
config.before_initialize do
|
||||
encoding = 'binary'
|
||||
Encoding.default_external = encoding
|
||||
Encoding.default_internal = encoding
|
||||
end
|
||||
|
||||
config.paths.add 'data/meterpreter', glob: '**/ext_*'
|
||||
config.paths.add 'modules'
|
||||
|
||||
#
|
||||
# `initializer`s
|
||||
#
|
||||
|
||||
initializer 'metasploit_framework.merge_meterpreter_extensions' do
|
||||
Rails.application.railties.engines.each do |engine|
|
||||
merge_meterpreter_extensions(engine)
|
||||
end
|
||||
|
||||
# The Rails.application itself could have paths['data/meterpreter'], but will not be part of
|
||||
# Rails.application.railties.engines because only direct subclasses of `Rails::Engine` are returned.
|
||||
merge_meterpreter_extensions(Rails.application)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Instance Methods
|
||||
#
|
||||
|
||||
private
|
||||
|
||||
# Merges the meterpreter extensions from `engine`'s `paths['data/meterpreter]`.
|
||||
#
|
||||
# @param engine [Rails::Engine] a Rails engine or application that has meterpreter extensions
|
||||
# @return [void]
|
||||
# @todo Make metasploit-framework look for meterpreter extension in paths['data/meterpreter'] from the engine instead of copying them.
|
||||
def merge_meterpreter_extensions(engine)
|
||||
data_meterpreter_paths = engine.paths['data/meterpreter']
|
||||
|
||||
# may be `nil` since 'data/meterpreter' is not part of the core Rails::Engine paths set.
|
||||
if data_meterpreter_paths
|
||||
source_paths = data_meterpreter_paths.existent
|
||||
destination_directory = root.join('data', 'meterpreter').to_path
|
||||
|
||||
source_paths.each do |source_path|
|
||||
basename = File.basename(source_path)
|
||||
destination_path = File.join(destination_directory, basename)
|
||||
|
||||
unless destination_path == source_path
|
||||
FileUtils.copy(source_path, destination_directory)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -33,18 +33,6 @@ if (RUBY_VERSION =~ /^1\.9\.1/)
|
|||
$stderr.puts "*** Ruby 1.9.1 is not supported, please upgrade to Ruby 1.9.3 or newer."
|
||||
end
|
||||
|
||||
if(RUBY_VERSION =~ /^(1\.9|2\.0)\./)
|
||||
# Load rubygems before changing default_internal, otherwise we may get
|
||||
# Encoding::UndefinedConversionError as the gemspec files are loaded
|
||||
require 'rubygems'
|
||||
Gem::Version # trigger Rubygems to fully load
|
||||
|
||||
# Force binary encoding for Ruby versions that support it
|
||||
if(Object.const_defined?('Encoding') and Encoding.respond_to?('default_external='))
|
||||
Encoding.default_external = Encoding.default_internal = "binary"
|
||||
end
|
||||
end
|
||||
|
||||
if(RUBY_PLATFORM == 'java')
|
||||
require 'socket'
|
||||
s = Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM, ::Socket::IPPROTO_TCP)
|
||||
|
|
Loading…
Reference in New Issue