use and include git hash of Framework as part of the version

Because we do not always update the version number, multiple releases have
shown version string, which is not useful for helping debug issues, or for
knowing what features are enabled.

This adds the git hash or reads from a file a copy of the git hash (useful for
doing packaged builds without git) so that it is clear the origin of a
particular metasploit-framework version.
bug/bundler_fix
Brent Cook 2015-07-02 15:30:58 -05:00
parent 3347b90db7
commit 8349a274ea
6 changed files with 41 additions and 22 deletions

View File

@ -1,7 +1,7 @@
PATH
remote: .
specs:
metasploit-framework (4.11.3.pre.dev)
metasploit-framework (4.11.3)
actionpack (>= 4.0.9, < 4.1.0)
activesupport (>= 4.0.9, < 4.1.0)
bcrypt
@ -20,14 +20,14 @@ PATH
rubyzip (~> 1.1)
sqlite3
tzinfo
metasploit-framework-db (4.11.3.pre.dev)
metasploit-framework-db (4.11.3)
activerecord (>= 4.0.9, < 4.1.0)
metasploit-credential (= 1.0.0)
metasploit-framework (= 4.11.3.pre.dev)
metasploit-framework (= 4.11.3)
metasploit_data_models (= 1.2.5)
pg (>= 0.11)
metasploit-framework-pcap (4.11.3.pre.dev)
metasploit-framework (= 4.11.3.pre.dev)
metasploit-framework-pcap (4.11.3)
metasploit-framework (= 4.11.3)
network_interface (~> 0.0.1)
pcaprub

View File

@ -16,4 +16,4 @@ module Metasploit
GEM_VERSION = Gem::Version.new(Metasploit::Framework::GEM_VERSION)
end
end
end
end

View File

@ -1,13 +1,43 @@
require 'rbconfig'
require 'yaml'
module Metasploit
module Framework
module Version
# Determines the git hash for this source tree
#
# @return [String] the git hash for this source tree
def self.get_hash
@@git_hash ||= begin
root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
version_yml = File.join(root, 'version.yml')
hash = ''
if File.exist?(version_yml)
version_info = YAML.load_file(version_yml)
hash = '-' + version_info['build_framework_rev']
else
# determine if git is installed
void = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL' : '/dev/null'
git_installed = system("git --version >>#{void} 2>&1")
# get the hash of the HEAD commit
if git_installed && File.exist?(File.join(root, '.git'))
hash = '-' + `git rev-parse HEAD`[0, 8]
end
end
hash.strip
end
end
MAJOR = 4
MINOR = 11
PATCH = 3
PRERELEASE = 'dev'
HASH = get_hash
end
VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::PATCH}-#{Version::PRERELEASE}"
GEM_VERSION = VERSION.gsub('-', '.pre.')
VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::PATCH}-#{Version::PRERELEASE}#{Version::HASH}"
GEM_VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::PATCH}"
end
end

View File

@ -11,6 +11,7 @@ require 'monitor'
#
require 'metasploit/framework/version'
require 'msf/base/config'
require 'msf/core'
require 'msf/util'
@ -33,16 +34,10 @@ class Framework
Minor = Metasploit::Framework::Version::MINOR
Point = Metasploit::Framework::Version::PATCH
Release = "-#{Metasploit::Framework::Version::PRERELEASE}"
if(Point)
Version = "#{Major}.#{Minor}.#{Point}#{Release}"
else
Version = "#{Major}.#{Minor}#{Release}"
end
Version = Metasploit::Framework::VERSION
Revision = "$Revision$"
# Repository information
RepoRevision = ::Msf::Util::SVN.revision
RepoUpdated = ::Msf::Util::SVN.updated

View File

@ -418,7 +418,7 @@ class Core
avdwarn = nil
banner_trailers = {
:version => "%yelmetasploit v#{Msf::Framework::Version} [core:#{Metasploit::Framework::Core::GEM_VERSION} api:#{Metasploit::Framework::API::GEM_VERSION}]%clr",
:version => "%yelmetasploit v#{Metasploit::Framework::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",

View File

@ -17,16 +17,10 @@ describe Msf::Framework do
end
describe "#version" do
CURRENT_VERSION = "4.11.3-dev"
subject(:framework) do
described_class.new
end
it "should return the current version" do
framework.version.should == CURRENT_VERSION
end
it "should return the Version constant" do
described_class.const_get(:Version).should == framework.version
end