lib/ronin/exploits/target.rb in ronin-exploits-0.3.1 vs lib/ronin/exploits/target.rb in ronin-exploits-1.0.0.beta1
- old
+ new
@@ -1,142 +1,102 @@
#
-# Ronin Exploits - A Ruby library for Ronin that provides exploitation and
+# ronin-exploits - A Ruby library for ronin-rb that provides exploitation and
# payload crafting functionality.
#
-# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
+# Copyright (c) 2007-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# ronin-exploits is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
-# This program is distributed in the hope that it will be useful,
+# ronin-exploits is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# GNU Lesser General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# You should have received a copy of the GNU Lesser General Public License
+# along with ronin-exploits. If not, see <https://www.gnu.org/licenses/>.
#
-require 'ronin/exploits/exceptions/target_data_missing'
-require 'ronin/model/targets_arch'
-require 'ronin/model/targets_os'
-require 'ronin/model/targets_product'
-require 'ronin/model'
+require 'ostruct'
-require 'dm-types/yaml'
-
module Ronin
module Exploits
- class Target
+ #
+ # Contains targeting information used for exploits.
+ # A target may specify which architecture, Operating System (OS),
+ # software version is targets. The target may also contain additional target
+ # parameters.
+ #
+ class Target < OpenStruct
- include Model
- include Model::TargetsArch
- include Model::TargetsOS
- include Model::TargetsProduct
+ # The target's architecture.
+ #
+ # @return [Symbol, nil]
+ attr_reader :arch
- # Primary key
- property :id, Serial
+ # The target's Operating System.
+ #
+ # @return [Symbol, nil]
+ attr_reader :os
- # Target comments
- property :description, String
-
- # The exploit the target belongs to
- belongs_to :exploit
-
- # The extra target data to use for the exploit
- property :data, Yaml, :default => {}
-
+ # The target's Operating System (OS) version.
#
- # Creates a new ExploitTarget object
- #
- # @param [Hash] attributes
- # Additional attributes to create the target with.
- #
- # @yield [target]
- # If a block is given, it will be passed the new target object.
- #
- # @yieldparam [Target] target
- # The newly created target object.
- #
- def initialize(attributes={},&block)
- super(attributes)
+ # @return [String, nil]
+ attr_reader :os_version
- block.call(self) if block
- end
-
+ # The target's software.
#
- # Searches for target data with the matching name.
- #
- # @param [Symbol, String] name
- # The name to search for.
- #
- # @return [Boolean]
- # Specifies whether the target contains data with the matching name.
- #
- def has?(name)
- self.data.has_key?(name.to_sym)
- end
+ # @return [String, nil]
+ attr_reader :software
+ # The target's software version.
#
- # Returns the target data with the matching name.
- #
- # @param [Symbol, String] name
- # The name of the target data to retrieve.
- #
- # @return [Object, nil]
- # The target data.
- #
- def [](name)
- self.data[name.to_sym]
- end
+ # @return [String, nil]
+ attr_reader :version
#
- # Sets the target data with the matching name.
+ # Creates a new ExploitTarget object
#
- # @param [Symbol, String] name
- # The name of the target data to set.
+ # @param [Symbol, nil] arch
+ # The architecture name of the target (ex: `:x86_64`).
#
- # @param [Object] value
- # The value to set for the target data.
+ # @param [Symbol, nil] os
+ # The Operating System (OS) name of the target (ex: `:linux`).
#
- def []=(name,value)
- self.data[name.to_sym] = value
- end
-
- protected
-
+ # @param [String, nil] os_version
+ # The Operating System (OS) version of the target (ex: `"10.13"`).
#
- # Provides transparent access to the target data Hash.
+ # @param [String, nil] software
+ # The software name of the target (ex: `"Apache"`).
#
- # @raise [TargetDataMissing]
- # The target does not have data associated with the specified name.
+ # @param [String, nil] version
+ # The software version of the target (ex: `"2.4.54"`).
#
- # @example
- # target.ip
- # # => 0xff8025a0
+ # @yield [target]
+ # If a block is given, it will be passed the new target object.
#
- # @example
- # target.ip = 0x41414141
+ # @yieldparam [Target] target
+ # The newly created target object.
#
- def method_missing(name,*arguments,&block)
- unless block
- name = name.to_s
+ def initialize(arch: nil,
+ os: nil,
+ os_version: nil,
+ software: nil,
+ version: nil,
+ **params)
+ super(**params)
- if (name[-1..-1] == '=' && arguments.length == 1)
- return self[name.chop] = arguments.first
- elsif arguments.length == 0
- unless has?(name)
- raise(TargetDataMissing,"the target is missing data for #{name.dump}",caller)
- end
+ @arch = arch
- return self[name]
- end
- end
+ @os = os
+ @os_version = os_version
- super(name,*arguments,&block)
+ @software = software
+ @version = version
+
+ yield self if block_given?
end
end
end
end