Module: Ronin::Exploits::Mixins::HasTargets
- Defined in:
- lib/ronin/exploits/mixins/has_targets.rb
Overview
Adds target information to an exploit class.
Defined Under Namespace
Modules: ClassMethods Classes: NoMatchingTarget, NoTargetSelected, TargetError
Instance Attribute Summary collapse
-
#target ⇒ Target?
Currently selected exploit target.
Class Method Summary collapse
-
.included(exploit) ⇒ Object
private
Adds ClassMethods to the including exploit class.
Instance Method Summary collapse
-
#arch ⇒ Symbol?
The current targeted architecture.
-
#initialize(target: nil, **kwargs) ⇒ Object
Sets that #target if the
target:
keyword argument is giving. -
#os ⇒ Symbol?
The current targeted OS.
-
#os_version ⇒ String?
The current targeted OS version.
-
#perform_validate ⇒ Object
Validates that a target was selected and all required params are set.
-
#select_target(arch: nil, os: nil, os_version: nil, software: nil, version: nil) ⇒ Object
Selects the target to use in exploitation.
-
#software ⇒ String?
The current targeted software.
-
#version ⇒ String?
The current targeted software version.
Instance Attribute Details
#target ⇒ Target?
Currently selected exploit target.
115 116 117 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 115 def target @target end |
Class Method Details
.included(exploit) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds ClassMethods to the including exploit class.
53 54 55 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 53 def self.included(exploit) exploit.extend ClassMethods end |
Instance Method Details
#arch ⇒ Symbol?
The current targeted architecture.
248 249 250 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 248 def arch target.arch if target end |
#initialize(target: nil, **kwargs) ⇒ Object
Sets that #target if the target:
keyword argument is giving.
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 128 def initialize(target: nil, **kwargs) super(**kwargs) if target case target when Hash then select_target(**target) when Integer then self.target = target else raise(ArgumentError,"target: must be either a Hash or an Integer") end end end |
#os ⇒ Symbol?
The current targeted OS.
259 260 261 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 259 def os target.os if target end |
#os_version ⇒ String?
The current targeted OS version.
270 271 272 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 270 def os_version target.os_version if target end |
#perform_validate ⇒ Object
Validates that a target was selected and all required params are set.
152 153 154 155 156 157 158 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 152 def perform_validate unless target raise(NoTargetSelected,"no target was selected") end super() end |
#select_target(arch: nil, os: nil, os_version: nil, software: nil, version: nil) ⇒ Object
Selects the target to use in exploitation.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 183 def select_target(arch: nil, os: nil, os_version: nil, software: nil, version: nil) targets = self.class.targets.lazy if arch targets = targets.select { |target| target.arch == arch } end if os targets = targets.select { |target| target.os == os } end if os_version targets = targets.select { |target| target.os_version == os_version } end if software targets = targets.select { |target| target.software == software } end if version targets = targets.select do |target| target.version == version end end unless (@target = targets.first) raise(NoMatchingTarget,"could not find any matching targets") end end |
#software ⇒ String?
The current targeted software.
281 282 283 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 281 def software target.software if target end |
#version ⇒ String?
The current targeted software version.
292 293 294 |
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 292 def version target.version if target end |