Module: Ronin::Exploits::Mixins::HasTargets

Defined in:
lib/ronin/exploits/mixins/has_targets.rb

Overview

Adds target information to an exploit class.

Since:

  • 1.0.0

Defined Under Namespace

Modules: ClassMethods Classes: NoMatchingTarget, NoTargetSelected, TargetError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#targetTarget?

Currently selected exploit target.

Returns:

Since:

  • 1.0.0



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.

Parameters:

Since:

  • 1.0.0



53
54
55
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 53

def self.included(exploit)
  exploit.extend ClassMethods
end

Instance Method Details

#archSymbol?

The current targeted architecture.

Returns:

  • (Symbol, nil)

Since:

  • 1.0.0



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.

Parameters:

  • target (Hash{Symbol => Object}, Integer, nil) (defaults to: nil)

    The optional target information to select.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Since:

  • 1.0.0



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

#osSymbol?

The current targeted OS.

Returns:

  • (Symbol, nil)

Since:

  • 1.0.0



259
260
261
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 259

def os
  target.os if target
end

#os_versionString?

The current targeted OS version.

Returns:

  • (String, nil)

Since:

  • 1.0.0



270
271
272
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 270

def os_version
  target.os_version if target
end

#perform_validateObject

Validates that a target was selected and all required params are set.

Raises:

  • (Ronin::Core::Params::RequiredParam)

    One of the required params was not set.

  • (NoTargetSelected)

    No target was selected.

Since:

  • 1.0.0



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.

Parameters:

  • arch (Symbol) (defaults to: nil)

    The targeted Architecture.

  • os (Symbol) (defaults to: nil)

    The targeted Operating System (OS).

  • os_version (Symbol) (defaults to: nil)

    The targeted Operating System (OS) version.

  • software (Symbol) (defaults to: nil)

    The targeted software.

  • version (Symbol) (defaults to: nil)

    The targeted software version.

Raises:

Since:

  • 1.0.0



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

#softwareString?

The current targeted software.

Returns:

  • (String, nil)

Since:

  • 1.0.0



281
282
283
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 281

def software
  target.software if target
end

#versionString?

The current targeted software version.

Returns:

  • (String, nil)

Since:

  • 1.0.0



292
293
294
# File 'lib/ronin/exploits/mixins/has_targets.rb', line 292

def version
  target.version if target
end