Merge branch 'master' of github.com:rapid7/metasploit-framework into rapid7

bug/bundler_fix
James Lee 2013-03-04 12:14:33 -06:00
commit c0689a7d43
201 changed files with 1479 additions and 193 deletions

View File

@ -7,7 +7,7 @@ gem 'activerecord'
# Needed for some admin modules (scrutinizer_add_user.rb)
gem 'json'
# Database models shared between framework and Pro.
gem 'metasploit_data_models', :git => 'git://github.com/rapid7/metasploit_data_models.git', :tag => '0.4.0'
gem 'metasploit_data_models', :git => 'git://github.com/rapid7/metasploit_data_models.git', :tag => '0.5.1'
# Needed by msfgui and other rpc components
gem 'msgpack'
# Needed by anemone crawler

View File

@ -1,9 +1,9 @@
GIT
remote: git://github.com/rapid7/metasploit_data_models.git
revision: 448c1065329efea1eac76a3897f626f122666743
tag: 0.4.0
revision: 1e3e0c2effb8e1bb6cec9683b830e4244babf706
tag: 0.5.1
specs:
metasploit_data_models (0.4.0)
metasploit_data_models (0.5.1)
activerecord (>= 3.2.10)
activesupport
pg
@ -12,22 +12,22 @@ GIT
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.11)
activesupport (= 3.2.11)
activemodel (3.2.12)
activesupport (= 3.2.12)
builder (~> 3.0.0)
activerecord (3.2.11)
activemodel (= 3.2.11)
activesupport (= 3.2.11)
activerecord (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.11)
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.4)
coderay (1.0.8)
coderay (1.0.9)
diff-lcs (1.1.3)
i18n (0.6.1)
i18n (0.6.4)
json (1.7.7)
method_source (0.8.1)
msgpack (0.5.2)
@ -35,10 +35,10 @@ GEM
nokogiri (1.5.6)
pcaprub (0.11.3)
pg (0.14.1)
pry (0.9.10)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
slop (~> 3.4)
rake (10.0.2)
redcarpet (2.2.2)
robots (0.10.1)
@ -54,7 +54,7 @@ GEM
multi_json (~> 1.0.3)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
slop (3.3.3)
slop (3.4.3)
tzinfo (0.3.35)
yard (0.8.3)

View File

@ -1,127 +0,0 @@
class MoveOldImportedCredsToNewFiles < ActiveRecord::Migration
class ImportedCred < ActiveRecord::Base
end
class CredFile < ActiveRecord::Base
end
class Workspace < ActiveRecord::Base
end
class << self
def find_or_create_cred_path
cred_files_dir = nil
msf_base = Msf::Config.install_root
pro_base = File.expand_path(File.join(msf_base, "..", "engine", "lib", "pro"))
if File.directory? pro_base
cred_files_dir = File.expand_path(File.join(msf_base, "..", "cred_files"))
FileUtils.mkdir_p(cred_files_dir) unless File.exists?(cred_files_dir)
if File.directory?(cred_files_dir) and File.writable?(cred_files_dir)
end
end
return cred_files_dir
end
def find_all_imported_creds_by_workspace
valid_ptypes = ["smb_hash", "userpass", "password"]
valid_workspaces = Workspace.all.map {|w| w.id}
creds = {}
ImportedCred.all.each do |cred|
next unless cred.ptype
next unless valid_ptypes.include? cred.ptype
next unless cred.workspace_id
next unless valid_workspaces.include? cred.workspace_id
creds[cred.workspace_id] ||= []
creds[cred.workspace_id] << cred
end
return creds
end
def sort_creds_into_file_types(old_creds)
files = {}
old_creds.each do |wid,creds|
filedata = {}
creds.each do |cred|
filedata[cred.ptype] ||= []
case cred.ptype
when "smb_hash", "userpass"
filedata[cred.ptype] << ("%s %s" % [cred.user,cred.pass])
when "password"
filedata[cred.ptype] << cred.pass.to_s
end
files[wid] = filedata
end
end
return files
end
def write_creds_to_files(old_creds,cred_path)
file_data_to_write = sort_creds_into_file_types(old_creds)
files_written = []
file_data_to_write.each do |wid, fdata_hash|
fdata_hash.each do |ftype,cred_data|
next unless cred_data
next if cred_data.empty?
fname = File.join(cred_path,"creds_#{wid}_#{ftype}-#{Time.now.utc.to_i}.txt")
fdata = cred_data.join("\n")
fh = File.open(fname, "wb")
begin
fh.write fdata
fh.flush
ensure
fh.close
end
files_written << fname
end
end
return files_written
end
def register_new_files(new_files)
successful_count = 0
new_files.each do |fname|
next unless File.split(fname).last =~ /^creds_([0-9]+)_(userpass|password|smb_hash)\-[0-9]+\.txt$/
wid = $1
next unless Workspace.find(wid)
ftype = $2
actual_ftype = case ftype
when "smb_hash", "userpass"
"userpass" # They're treated the same
when "password"
"pass"
end
next unless actual_ftype
say "Registering credential file '%s' for workspace %d as type '%s'" % [fname,wid,actual_ftype]
cred_file = CredFile.new
cred_file.workspace_id = wid
cred_file.created_by = ""
cred_file.path = fname
cred_file.name = "#{ftype}.txt"
cred_file.desc = "Migrated #{ftype} credentials"
cred_file.ftype = actual_ftype
if cred_file.save
successful_count += 1
say "Successfully imported #{ftype} credentials for workspace #{wid}"
end
end
successful_count
end
end
def self.up
cred_path = find_or_create_cred_path
if cred_path
old_imported_creds = find_all_imported_creds_by_workspace
new_files = write_creds_to_files(old_imported_creds,cred_path)
successful_count = register_new_files(new_files)
end
end
# Sorry, can't get the old data back.
def self.down
end
end

View File

@ -1,10 +0,0 @@
source "http://rubygems.org"
# Specify your gem's dependencies in metasploit_data_models.gemspec
gemspec
group :test do
# rails is only used for testing with a dummy application in spec/dummy
gem 'rails'
gem 'rspec-rails'
end

View File

@ -1,7 +0,0 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec

View File

@ -1,16 +0,0 @@
class Mdm::WebVuln < ActiveRecord::Base
#
# Relations
#
belongs_to :web_site, :class_name => 'Mdm::WebSite'
#
# Serializations
#
serialize :params, MetasploitDataModels::Base64Serializer.new
ActiveSupport.run_load_hooks(:mdm_web_vuln, self)
end

View File

@ -1,7 +0,0 @@
module MetasploitDataModels
# MetasploitDataModels follows the {Semantic Versioning Specification http://semver.org/}. At this time, the API
# is considered unstable because the database migrations are still in metasploit-framework and certain models may not
# be shared between metasploit-framework and pro, so models may be removed in the future. Because of the unstable API
# the version should remain below 1.0.0
VERSION = '0.4.0'
end

View File

@ -6,13 +6,19 @@
*.gem
# Rubymine project configuration
.idea
# logs
*.log
# Don't check in rvmrc since this is a gem
.rvmrc
# YARD database
.yardoc
# coverage report directory for simplecov/Rubymine
coverage
# generated yardocs
doc
# Installed gem versions. Not stored for the same reasons as .rvmrc
Gemfile.lock
# Packaging directory for builds
pkg/*
# Database configuration (with passwords) for specs
spec/dummy/config/database.yml
# logs
*.log

View File

@ -0,0 +1,38 @@
# RM_INFO is set when using Rubymine. In Rubymine, starting SimpleCov is
# controlled by running with coverage, so don't explicitly start coverage (and
# therefore generate a report) when in Rubymine. This _will_ generate a report
# whenever `rake spec` is run.
unless ENV['RM_INFO']
SimpleCov.start
end
SimpleCov.configure do
load_adapter('rails')
# ignore this file
add_filter '.simplecov'
#
# Changed Files in Git Group
# @see http://fredwu.me/post/35625566267/simplecov-test-coverage-for-changed-files-only
#
untracked = `git ls-files --exclude-standard --others`
unstaged = `git diff --name-only`
staged = `git diff --name-only --cached`
all = untracked + unstaged + staged
changed_filenames = all.split("\n")
add_group 'Changed' do |source_file|
changed_filenames.detect { |changed_filename|
source_file.filename.end_with?(changed_filename)
}
end
#
# Specs are reported on to ensure that all examples are being run and all
# lets, befores, afters, etc are being used.
#
add_group 'Specs', 'spec'
end

View File

@ -0,0 +1,4 @@
--markup markdown
--protected
{app,lib}/**/*.rb
db/migrate/*.rb

View File

@ -0,0 +1,22 @@
source "http://rubygems.org"
# Specify your gem's dependencies in metasploit_data_models.gemspec
gemspec
# used by dummy application
group :development, :test do
# supplies factories for producing model instance for specs
gem 'factory_girl_rails'
# rails is only used for the dummy application in spec/dummy
gem 'rails'
end
group :test do
# In a full rails project, factory_girl_rails would be in both the :development, and :test group, but since we only
# want rails in :test, factory_girl_rails must also only be in :test.
# add matchers from shoulda, such as validates_presence_of, which are useful for testing validations
gem 'shoulda-matchers'
# code coverage of tests
gem 'simplecov', :require => false
gem 'rspec-rails'
end

View File

@ -0,0 +1,20 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
load 'rails/tasks/engine.rake'
Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
load 'lib/tasks/yard.rake'

View File

@ -0,0 +1,144 @@
# A Web Vulnerability found during a web scan or web audit.
#
# If you need to modify Mdm::WebVuln you can use ActiveSupport.on_load(:mdm_web_vuln) in side an initializer so that
# your patches are reloaded on each request in development mode for your Rails application.
#
# @example extending Mdm::WebVuln
# # config/initializers/mdm_web_vuln.rb
# ActiveSupport.on_load(:mdm_web_vuln) do
# def confidence_percentage
# "#{confidence}%"
# end
# end
class Mdm::WebVuln < ActiveRecord::Base
#
# CONSTANTS
#
# A percentage {#confidence} that the vulnerability is real and not a false positive. 0 is not allowed because there
# shouldn't be an {Mdm::WebVuln} record if there is 0% {#confidence} in the the finding.
CONFIDENCE_RANGE = 1 .. 100
# Allowed {#method methods}.
METHODS = [
'GET',
# XXX I don't know why PATH is a valid method when it's not an HTTP Method/Verb
'PATH',
'POST'
]
# {#risk Risk} is rated on a scale from 0 (least risky) to 5 (most risky).
RISK_RANGE = 0 .. 5
#
# Associations
#
belongs_to :web_site, :class_name => 'Mdm::WebSite'
#
# Attributes
#
# @!attribute [rw] blame
# Who to blame for the vulnerability
#
# @return [String]
# @!attribute [rw] category
# Category of this vulnerability.
#
# @return [String]
# @!attribute [rw] confidence
# Percentage confidence scanner or auditor has that this vulnerability is not a false positive
#
# @return [Integer] 1% to 100%
# @!attribute [rw] description
# Description of the vulnerability
#
# @return [String, nil]
# @!attribute [rw] method
# HTTP Methods for request that found vulnerability. 'PATH' is also allowed even though it is not an HTTP Method.
#
# @return [String]
# @see METHODS
# @!attribute [rw] name
# Name of the vulnerability
#
# @return [String]
# @!attribute [rw] path
# Path portion of URL
#
# @return [String]
# @!attribute [rw] payload
# Web audit payload that gets executed by the remote server. Used for code injection vulnerabilities.
#
# @return [String, nil]
# @!attribute [rw] pname
# Name of parameter that demonstrates vulnerability
#
# @return [String]
# @!attribute [rw] proof
# String that proves vulnerability, such as a code snippet, etc.
#
# @return [String]
# @!attribute [rw] query
# The GET query.
#
# @return [String]
# @!attribute [rw] request
#
# @return [String]
# @!attribute [rw] risk
# {RISK_RANGE Risk} of leaving this vulnerability unpatched.
#
# @return [Integer]
#
# Validations
#
validates :category, :presence => true
validates :confidence,
:inclusion => {
:in => CONFIDENCE_RANGE
}
validates :method,
:inclusion => {
:in => METHODS
}
validates :name, :presence => true
validates :path, :presence => true
validates :params, :presence => true
validates :pname, :presence => true
validates :proof, :presence => true
validates :risk,
:inclusion => {
:in => RISK_RANGE
}
validates :web_site, :presence => true
#
# Serializations
#
# @!attribute [rw] params
# Parameters sent as part of request
#
# @return [Array<Array<(String, String)>>] Array of parameter key value pairs
serialize :params, MetasploitDataModels::Base64Serializer.new
ActiveSupport.run_load_hooks(:mdm_web_vuln, self)
end

Some files were not shown because too many files have changed in this diff Show More