diff --git a/lib/ronin/exploits/exploit.rb b/lib/ronin/exploits/exploit.rb index 7f580df0..5bb74cd3 100644 --- a/lib/ronin/exploits/exploit.rb +++ b/lib/ronin/exploits/exploit.rb @@ -30,6 +30,7 @@ require 'ronin/core/metadata/description' require 'ronin/core/metadata/references' require 'ronin/core/params/mixin' +require 'ronin/support/software/version_range' require 'ronin/support/cli/printing' require 'ronin/post_ex' @@ -407,17 +408,28 @@ def self.software(new_software=nil) # # Gets or sets the software version(s) which the exploit targets. # - # @param [Array, nil] new_software_versions + # @param [Array, String,nil] new_software_versions # the optional new software version(s) to set. # - # @return [Array, nil] + # @return [Array, nil] # The name of the software version which the exploit targets. # + # @example Specify a single version range: + # software_versions '>= 1.2.3, < 2.0.0' + # + # @example Specify multiple version ranges: + # software_versions [ + # '>= 1.2.3, < 2.0.0', + # '>= 2.1.0' + # ] + # # @api public # def self.software_versions(new_software_versions=nil) if new_software_versions - @software_versions = new_software_versions + @software_versions = Array(new_software_versions).map do |string| + Support::Software::VersionRange.parse(string) + end else @software_versions ||= if superclass < Exploit superclass.software_versions diff --git a/spec/exploit_spec.rb b/spec/exploit_spec.rb index 8bd45ecb..2da1d54c 100644 --- a/spec/exploit_spec.rb +++ b/spec/exploit_spec.rb @@ -341,6 +341,17 @@ module TestExploitSoftwareVersions class WithNoSoftwareVersionsSet < Ronin::Exploits::Exploit end + class WithASingleSoftwareVersionRangeSet < Ronin::Exploits::Exploit + software_versions '>= 1.2.3, < 2.0.0' + end + + class WithMultipleSoftwareVersionRangesSet < Ronin::Exploits::Exploit + software_versions [ + '>= 1.2.3, < 2.0.0', + '>= 2.1.0' + ] + end + class WithSoftwareVersionsSet < Ronin::Exploits::Exploit software_versions [ '>= 0.1.0, < 0.3.0' @@ -359,6 +370,31 @@ class OverridesItsInheritedSoftwareVersions < WithSoftwareVersionsSet subject { test_class } + context "and when a single software version range String is given as an argument" do + let(:test_class) { TestExploitSoftwareVersions::WithASingleSoftwareVersionRangeSet } + + it "must return an Array of Ronin::Support::Software::VersionRange objects" do + expect(subject.software_versions).to eq( + [ + Ronin::Support::Software::VersionRange.parse('>= 1.2.3, < 2.0.0') + ] + ) + end + end + + context "and when an Array of software version range Strings is given as an argument" do + let(:test_class) { TestExploitSoftwareVersions::WithMultipleSoftwareVersionRangesSet } + + it "must return an Array of Ronin::Support::Software::VersionRange objects" do + expect(subject.software_versions).to eq( + [ + Ronin::Support::Software::VersionRange.parse('>= 1.2.3, < 2.0.0'), + Ronin::Support::Software::VersionRange.parse('>= 2.1.0') + ] + ) + end + end + context "and when software versions are not set in the class" do let(:test_class) { TestExploitSoftwareVersions::WithNoSoftwareVersionsSet } @@ -371,7 +407,11 @@ class OverridesItsInheritedSoftwareVersions < WithSoftwareVersionsSet let(:test_class) { TestExploitSoftwareVersions::WithSoftwareVersionsSet } it "must return the set software" do - expect(subject.software_versions).to eq(['>= 0.1.0, < 0.3.0']) + expect(subject.software_versions).to eq( + [ + Ronin::Support::Software::VersionRange.parse('>= 0.1.0, < 0.3.0') + ] + ) end end @@ -379,14 +419,22 @@ class OverridesItsInheritedSoftwareVersions < WithSoftwareVersionsSet let(:test_class) { TestExploitSoftwareVersions::InheritsItsSoftwareVersions } it "must return the software versions set in the superclass" do - expect(subject.software_versions).to eq(['>= 0.1.0, < 0.3.0']) + expect(subject.software_versions).to eq( + [ + Ronin::Support::Software::VersionRange.parse('>= 0.1.0, < 0.3.0') + ] + ) end context "but the software versions are overridden in the sub-class" do let(:test_class) { TestExploitSoftwareVersions::OverridesItsInheritedSoftwareVersions } it "must return the software versions set in the sub-class" do - expect(subject.software_versions).to eq(['>= 1.0.0, <= 1.0.2']) + expect(subject.software_versions).to eq( + [ + Ronin::Support::Software::VersionRange.parse('>= 1.0.0, <= 1.0.2') + ] + ) end end end