Skip to content

Commit 60444c2

Browse files
committed
Land rapid7#5658, MSF version includes git hash now
2 parents a2bdd0b + 8349a27 commit 60444c2

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
metasploit-framework (4.11.3.pre.dev)
4+
metasploit-framework (4.11.3)
55
actionpack (>= 4.0.9, < 4.1.0)
66
activesupport (>= 4.0.9, < 4.1.0)
77
bcrypt
@@ -20,14 +20,14 @@ PATH
2020
rubyzip (~> 1.1)
2121
sqlite3
2222
tzinfo
23-
metasploit-framework-db (4.11.3.pre.dev)
23+
metasploit-framework-db (4.11.3)
2424
activerecord (>= 4.0.9, < 4.1.0)
2525
metasploit-credential (= 1.0.0)
26-
metasploit-framework (= 4.11.3.pre.dev)
26+
metasploit-framework (= 4.11.3)
2727
metasploit_data_models (= 1.2.5)
2828
pg (>= 0.11)
29-
metasploit-framework-pcap (4.11.3.pre.dev)
30-
metasploit-framework (= 4.11.3.pre.dev)
29+
metasploit-framework-pcap (4.11.3)
30+
metasploit-framework (= 4.11.3)
3131
network_interface (~> 0.0.1)
3232
pcaprub
3333

lib/metasploit/framework/core/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ module Version
1616
GEM_VERSION = Gem::Version.new(Metasploit::Framework::GEM_VERSION)
1717
end
1818
end
19-
end
19+
end

lib/metasploit/framework/version.rb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
1+
require 'rbconfig'
2+
require 'yaml'
3+
14
module Metasploit
25
module Framework
36
module Version
7+
# Determines the git hash for this source tree
8+
#
9+
# @return [String] the git hash for this source tree
10+
def self.get_hash
11+
@@git_hash ||= begin
12+
root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
13+
version_yml = File.join(root, 'version.yml')
14+
hash = ''
15+
16+
if File.exist?(version_yml)
17+
version_info = YAML.load_file(version_yml)
18+
hash = '-' + version_info['build_framework_rev']
19+
else
20+
# determine if git is installed
21+
void = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL' : '/dev/null'
22+
git_installed = system("git --version >>#{void} 2>&1")
23+
24+
# get the hash of the HEAD commit
25+
if git_installed && File.exist?(File.join(root, '.git'))
26+
hash = '-' + `git rev-parse HEAD`[0, 8]
27+
end
28+
end
29+
hash.strip
30+
end
31+
end
32+
433
MAJOR = 4
534
MINOR = 11
635
PATCH = 3
736
PRERELEASE = 'dev'
37+
HASH = get_hash
838
end
939

10-
VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::PATCH}-#{Version::PRERELEASE}"
11-
GEM_VERSION = VERSION.gsub('-', '.pre.')
40+
VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::PATCH}-#{Version::PRERELEASE}#{Version::HASH}"
41+
GEM_VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::PATCH}"
1242
end
1343
end

lib/msf/core/framework.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#
1212

1313
require 'metasploit/framework/version'
14+
require 'msf/base/config'
1415
require 'msf/core'
1516
require 'msf/util'
1617

@@ -33,16 +34,10 @@ class Framework
3334
Minor = Metasploit::Framework::Version::MINOR
3435
Point = Metasploit::Framework::Version::PATCH
3536
Release = "-#{Metasploit::Framework::Version::PRERELEASE}"
36-
37-
if(Point)
38-
Version = "#{Major}.#{Minor}.#{Point}#{Release}"
39-
else
40-
Version = "#{Major}.#{Minor}#{Release}"
41-
end
37+
Version = Metasploit::Framework::VERSION
4238

4339
Revision = "$Revision$"
4440

45-
4641
# Repository information
4742
RepoRevision = ::Msf::Util::SVN.revision
4843
RepoUpdated = ::Msf::Util::SVN.updated

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def cmd_banner(*args)
418418
avdwarn = nil
419419

420420
banner_trailers = {
421-
:version => "%yelmetasploit v#{Msf::Framework::Version} [core:#{Metasploit::Framework::Core::GEM_VERSION} api:#{Metasploit::Framework::API::GEM_VERSION}]%clr",
421+
:version => "%yelmetasploit v#{Metasploit::Framework::VERSION}%clr",
422422
:exp_aux_pos => "#{framework.stats.num_exploits} exploits - #{framework.stats.num_auxiliary} auxiliary - #{framework.stats.num_post} post",
423423
:pay_enc_nop => "#{framework.stats.num_payloads} payloads - #{framework.stats.num_encoders} encoders - #{framework.stats.num_nops} nops",
424424
:free_trial => "Free Metasploit Pro trial: http://r-7.co/trymsp",

spec/lib/msf/core/framework_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@
1717
end
1818

1919
describe "#version" do
20-
CURRENT_VERSION = "4.11.3-dev"
21-
2220
subject(:framework) do
2321
described_class.new
2422
end
2523

26-
it "should return the current version" do
27-
framework.version.should == CURRENT_VERSION
28-
end
29-
3024
it "should return the Version constant" do
3125
described_class.const_get(:Version).should == framework.version
3226
end

0 commit comments

Comments
 (0)