2014-06-02 17:57:48 +00:00
|
|
|
#
|
|
|
|
# Standard Library
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'fileutils'
|
|
|
|
|
2014-10-02 19:20:10 +00:00
|
|
|
#
|
|
|
|
# Metasploit gem engines
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'metasploit/model/engine'
|
|
|
|
require 'metasploit/concern/engine'
|
2014-10-03 19:06:13 +00:00
|
|
|
Metasploit::Framework::Require.optionally_require_metasploit_db_gem_engines
|
2014-10-02 19:20:10 +00:00
|
|
|
|
2014-06-02 17:57:48 +00:00
|
|
|
# `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
|
|
|
|
|
2014-08-12 18:53:28 +00:00
|
|
|
config.root = Msf::Config::install_root
|
2014-06-02 17:57:48 +00:00
|
|
|
config.paths.add 'data/meterpreter', glob: '**/ext_*'
|
|
|
|
config.paths.add 'modules'
|
|
|
|
|
2014-08-22 15:33:50 +00:00
|
|
|
config.active_support.deprecation = :notify
|
|
|
|
|
2014-06-02 17:57:48 +00:00
|
|
|
#
|
|
|
|
# `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
|
2014-10-02 19:20:10 +00:00
|
|
|
end
|