From 9096a8a1f58fb570a6bbe152cb32e12bd5fc3d75 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 1 Aug 2014 21:43:14 -0500 Subject: [PATCH] Remove Msf::Framework::VersionAPI MSP-10998 It's compacting of the version parts into a single float doesn't work with APIMinor over 10, so replace with Gem::Version, which compares parts correctly. --- lib/metasploit/framework/api.rb | 7 +++++++ lib/metasploit/framework/api/version.rb | 16 ++++++++++++++++ lib/msf/core/framework.rb | 7 ------- lib/msf/core/modules/namespace.rb | 6 +++--- lib/msf/ui/console/command_dispatcher/core.rb | 2 +- spec/lib/msf/core/modules/namespace_spec.rb | 12 ++++++------ 6 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 lib/metasploit/framework/api.rb create mode 100644 lib/metasploit/framework/api/version.rb diff --git a/lib/metasploit/framework/api.rb b/lib/metasploit/framework/api.rb new file mode 100644 index 0000000000..b643aec8b2 --- /dev/null +++ b/lib/metasploit/framework/api.rb @@ -0,0 +1,7 @@ +module Metasploit + module Framework + module API + + end + end +end \ No newline at end of file diff --git a/lib/metasploit/framework/api/version.rb b/lib/metasploit/framework/api/version.rb new file mode 100644 index 0000000000..9b6fce0da0 --- /dev/null +++ b/lib/metasploit/framework/api/version.rb @@ -0,0 +1,16 @@ +module Metasploit + module Framework + module API + # @note This is a like. The API version is not semantically version and it's version has actually never changed + # even though API changes have occured. DO NOT base compatibility on this version. + module Version + MAJOR = 1 + MINOR = 0 + PATCH = 0 + end + + VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::PATCH}" + GEM_VERSION = Gem::Version.new(VERSION) + end + end +end \ No newline at end of file diff --git a/lib/msf/core/framework.rb b/lib/msf/core/framework.rb index 52f503ab8d..70c7ae6883 100644 --- a/lib/msf/core/framework.rb +++ b/lib/msf/core/framework.rb @@ -42,13 +42,6 @@ class Framework # EICAR canary EICARCorrupted = ::Msf::Util::EXE.is_eicar_corrupted? - # API Version - APIMajor = 1 - APIMinor = 0 - - # API Version - VersionAPI = APIMajor + (APIMinor / 10.0) - # # Mixin meant to be included into all classes that can have instances that # should be tied to the framework, such as modules. diff --git a/lib/msf/core/modules/namespace.rb b/lib/msf/core/modules/namespace.rb index 655ecf3131..b2a68c7914 100644 --- a/lib/msf/core/modules/namespace.rb +++ b/lib/msf/core/modules/namespace.rb @@ -57,10 +57,10 @@ module Msf::Modules::Namespace if const_defined?(:RequiredVersions) required_versions = const_get(:RequiredVersions) minimum_core_version = Gem::Version.new(required_versions[0].to_s) - minimum_api_version = required_versions[1] + minimum_api_version = Gem::Version.new(required_versions[1].to_s) - if (minimum_core_version > Metasploit::Framework::Core::GEM_VERSION or - minimum_api_version > ::Msf::Framework::VersionAPI) + if (minimum_core_version > Metasploit::Framework::Core::GEM_VERSION || + minimum_api_version > Metasploit::Framework::API::GEM_VERSION) raise Msf::Modules::VersionCompatibilityError.new( :module_path => module_path, :module_reference_name => module_reference_name, diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index f0e006fbf1..8733ce216a 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -408,7 +408,7 @@ class Core avdwarn = nil banner_trailers = { - :version => "%yelmetasploit v#{Msf::Framework::Version} [core:#{Metasploit::Framework::Core::GEM_VERSION} api:#{Msf::Framework::VersionAPI}]%clr", + :version => "%yelmetasploit v#{Msf::Framework::Version} [core:#{Metasploit::Framework::Core::GEM_VERSION} api:#{Metasploit::Framework::API::GEM_VERSION}]%clr", :exp_aux_pos => "#{framework.stats.num_exploits} exploits - #{framework.stats.num_auxiliary} auxiliary - #{framework.stats.num_post} post", :pay_enc_nop => "#{framework.stats.num_payloads} payloads - #{framework.stats.num_encoders} encoders - #{framework.stats.num_nops} nops", :free_trial => "Free Metasploit Pro trial: http://r-7.co/trymsp", diff --git a/spec/lib/msf/core/modules/namespace_spec.rb b/spec/lib/msf/core/modules/namespace_spec.rb index cc7a0965f5..4925fa98f2 100644 --- a/spec/lib/msf/core/modules/namespace_spec.rb +++ b/spec/lib/msf/core/modules/namespace_spec.rb @@ -218,8 +218,8 @@ describe Msf::Modules::Namespace do 2 end - it 'should be > Msf::Framework::VersionAPI' do - minimum_api_version.should > Msf::Framework::VersionAPI + it 'should be > Metasploit::Framework::API::GEM_VERSION' do + minimum_api_version.should > Metasploit::Framework::API::GEM_VERSION end it_should_behave_like 'Msf::Modules::VersionCompatibilityError' @@ -248,16 +248,16 @@ describe Msf::Modules::Namespace do 2 end - it 'should be > Msf::Framework::VersionAPI' do - minimum_api_version.should > Msf::Framework::VersionAPI + it 'should be > Metasploit::Framework::API::GEM_VERSION' do + minimum_api_version.should > Metasploit::Framework::API::GEM_VERSION end it_should_behave_like 'Msf::Modules::VersionCompatibilityError' end context 'with minimum API version' do - it 'should be <= Msf::Framework::VersionAPI' do - minimum_api_version <= Msf::Framework::VersionAPI + it 'should be <= Metasploit::Framework::API::GEM_VERSION' do + minimum_api_version <= Metasploit::Framework::API::GEM_VERSION end it_should_behave_like 'Msf::Modules::VersionCompatibilityError'