Skip to content

Commit

Permalink
Changed software_versions to parse the software version ranges (closes
Browse files Browse the repository at this point in the history
 #149).

* Use the new `Ronin::Support::Software::VersionRange` class in
  `ronin-support` 1.2.0.
* `software_versions` now accepts both a single String and an Array of
  Strings.
* `software_versions` will now return an Array of parsed
  `Ronin::Support::Software::VersionRange` objects.
  • Loading branch information
postmodern committed Dec 13, 2024
1 parent ebf512e commit 2f227b5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
18 changes: 15 additions & 3 deletions lib/ronin/exploits/exploit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -407,17 +408,28 @@ def self.software(new_software=nil)
#
# Gets or sets the software version(s) which the exploit targets.
#
# @param [Array<String>, nil] new_software_versions
# @param [Array<String>, String,nil] new_software_versions
# the optional new software version(s) to set.
#
# @return [Array<String>, nil]
# @return [Array<Ronin::Support::Software::VersionRange>, 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
Expand Down
54 changes: 51 additions & 3 deletions spec/exploit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 }

Expand All @@ -371,22 +407,34 @@ 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

context "but when the software versions was set in the superclass" do
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
Expand Down

0 comments on commit 2f227b5

Please sign in to comment.