forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use railties to load Metasploit::Credential correctly
MSP-9606 In order to support Metasploit::Credential correctly, metasploit-framework needs to support Metasploit::Concern, which does all its magic using a Rails::Engine initializer, so the easiest path is to make metasploit-framework be able to use Rails::Engines. To make Rails::Engine use Rails::Engine, make a dummy Rails::Application subclass so that all the initializers will be run when anything requires msfenv.
- Loading branch information
1 parent
c70ef2a
commit 3370465
Showing
27 changed files
with
368 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,4 @@ | ||
require 'bundler/setup' | ||
#!/usr/bin/env rake | ||
require File.expand_path('../config/application', __FILE__) | ||
|
||
pathname = Pathname.new(__FILE__) | ||
root = pathname.parent | ||
|
||
# add metasploit-framework/lib to load paths so rake files can just require | ||
# files normally without having to use __FILE__ and recalculating root and the | ||
# path to lib | ||
lib_pathname = root.join('lib') | ||
$LOAD_PATH.unshift(lib_pathname.to_s) | ||
|
||
# | ||
# load rake files like a rails engine | ||
# | ||
|
||
rakefile_glob = root.join('lib', 'tasks', '**', '*.rake').to_path | ||
|
||
Dir.glob(rakefile_glob) do |rakefile| | ||
# Skip database tasks, will load them later if MDM is present | ||
next if rakefile =~ /database\.rake$/ | ||
load rakefile | ||
end | ||
|
||
print_without = false | ||
|
||
begin | ||
require 'rspec/core/rake_task' | ||
rescue LoadError | ||
puts "rspec not in bundle, so can't set up spec tasks. " \ | ||
"To run specs ensure to install the development and test groups." | ||
|
||
print_without = true | ||
else | ||
RSpec::Core::RakeTask.new(:spec => 'db:test:prepare') | ||
|
||
task :default => :spec | ||
end | ||
|
||
# Require yard before loading metasploit_data_models rake tasks as the yard tasks won't be defined if | ||
# YARD is not defined when yard.rake is loaded. | ||
begin | ||
require 'yard' | ||
rescue LoadError | ||
puts "yard not in bundle, so can't set up yard tasks. " \ | ||
"To generate documentation ensure to install the development group." | ||
|
||
print_without = true | ||
end | ||
|
||
begin | ||
require 'metasploit_data_models' | ||
rescue LoadError | ||
puts "metasploit_data_models not in bundle, so can't set up db tasks. " \ | ||
"To run database tasks, ensure to install the db bundler group." | ||
|
||
print_without = true | ||
else | ||
load 'lib/tasks/database.rake' | ||
metasploit_data_models_task_glob = MetasploitDataModels.root.join( | ||
'lib', | ||
'tasks', | ||
'**', | ||
'*.rake' | ||
).to_s | ||
# include tasks from metasplioit_data_models, such as `rake yard`. | ||
# metasploit-framework specific yard options are in .yardopts | ||
Dir.glob(metasploit_data_models_task_glob) do |path| | ||
load path | ||
end | ||
end | ||
|
||
|
||
|
||
if print_without | ||
puts "Bundle currently installed " \ | ||
"'--without #{Bundler.settings.without.join(' ')}'." | ||
puts "To clear the without option do `bundle install --without ''` " \ | ||
"(the --without flag with an empty string) or " \ | ||
"`rm -rf .bundle` to remove the .bundle/config manually and " \ | ||
"then `bundle install`" | ||
end | ||
Metasploit::Framework::Application.load_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails' | ||
require File.expand_path('../boot', __FILE__) | ||
|
||
# only the parts of 'rails/all' that metasploit-framework actually uses | ||
require 'active_record/railtie' | ||
|
||
all_environments = [ | ||
:development, | ||
:production, | ||
:test | ||
] | ||
|
||
Bundler.require( | ||
*Rails.groups( | ||
db: all_environments, | ||
pcap: all_environments | ||
) | ||
) | ||
|
||
require 'msf/base/config' | ||
|
||
module Metasploit | ||
module Framework | ||
class Application < Rails::Application | ||
user_config_root = Pathname.new(Msf::Config.get_config_root) | ||
user_database_yaml = user_config_root.join('database.yml') | ||
|
||
if user_database_yaml.exist? | ||
config.paths['config/database'] = [user_database_yaml.to_path] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'pathname' | ||
require 'rubygems' | ||
|
||
bundle_gemfile = ENV['BUNDLE_GEMFILE'] | ||
|
||
config_pathname = Pathname.new(__FILE__).expand_path.parent | ||
root = config_pathname.parent | ||
|
||
if bundle_gemfile | ||
bundle_gemfile = Pathname.new(bundle_gemfile) | ||
else | ||
bundle_gemfile = root.join('Gemfile') | ||
end | ||
|
||
if bundle_gemfile.exist? | ||
ENV['BUNDLE_GEMFILE'] = bundle_gemfile.to_path | ||
|
||
begin | ||
require 'bundler' | ||
rescue LoadError | ||
$stderr.puts "[*] Metasploit requires the Bundler gem to be installed" | ||
$stderr.puts " $ gem install bundler" | ||
exit(0) | ||
end | ||
end | ||
|
||
Bundler.setup | ||
|
||
lib_path = root.join('lib').to_path | ||
|
||
unless $LOAD_PATH.include? lib_path | ||
$LOAD_PATH.unshift lib_path | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Load the rails application | ||
require File.expand_path('../application', __FILE__) | ||
|
||
# Initialize the rails application | ||
Metasploit::Framework::Application.initialize! |
Empty file.
Oops, something went wrong.