Class: Ronin::Recon::Workers Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/recon/workers.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a set of recon worker classes.

Constant Summary collapse

INTENSITY_LEVELS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Intensity levels sorted by their intensity.

[
  :passive,
  :active,
  :aggressive
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workers = Set.new) ⇒ Workers

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.

Initializes the workers.

Parameters:

  • workers (Array<Class<Worker>>, Set<Class<Worker>>) (defaults to: Set.new)

    The set of worker classes.



47
48
49
# File 'lib/ronin/recon/workers.rb', line 47

def initialize(workers=Set.new)
  @classes = workers.to_set
end

Instance Attribute Details

#classesSet<Class<Worker>> (readonly)

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.

The worker classes in the set.

Returns:



39
40
41
# File 'lib/ronin/recon/workers.rb', line 39

def classes
  @classes
end

Class Method Details

.[](*worker_ids) ⇒ Workers

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.

Alias for load.

Parameters:

  • worker_ids (Array<String>)

    The array of worker IDs to load.

Returns:



77
78
79
# File 'lib/ronin/recon/workers.rb', line 77

def self.[](*worker_ids)
  load(worker_ids)
end

.allWorkers

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.

Loads all workers.

Returns:



86
87
88
# File 'lib/ronin/recon/workers.rb', line 86

def self.all
  load(Recon.list_files)
end

.category(name) ⇒ Workers

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.

Loads all workers under a specific category.

Parameters:

  • name (String)

    The category name.

Returns:



98
99
100
101
102
103
104
# File 'lib/ronin/recon/workers.rb', line 98

def self.category(name)
  load(
    Recon.list_files.select { |worker_id|
      worker_id.start_with?("#{name}/")
    }
  )
end

.load(worker_ids) ⇒ Workers

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.

Loads the worker classes.

Parameters:

  • worker_ids (Enumerable<String>)

    The list of worker IDs to load.

Returns:



59
60
61
62
63
64
65
66
67
# File 'lib/ronin/recon/workers.rb', line 59

def self.load(worker_ids)
  workers = new

  worker_ids.each do |worker_id|
    workers.load(worker_id)
  end

  return workers
end

Instance Method Details

#+(other) ⇒ Workers

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 another set of workers to the workers.

Parameters:

Returns:



130
131
132
133
134
# File 'lib/ronin/recon/workers.rb', line 130

def +(other)
  other_workers = other.to_set

  self.class.new((@classes + other_workers).uniq)
end

#<<(worker) ⇒ self

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 the worker class to the workers.

Parameters:

  • worker (Class<Worker>)

    The worker class to add.

Returns:

  • (self)


144
145
146
147
# File 'lib/ronin/recon/workers.rb', line 144

def <<(worker)
  @classes << worker
  return self
end

#==(other) ⇒ Boolean

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.

Determines if the workers is equal to another workers.

Parameters:

  • other (Object)

    The other workers.

Returns:

  • (Boolean)


244
245
246
247
# File 'lib/ronin/recon/workers.rb', line 244

def ==(other)
  self.class == other.class &&
    @classes == other.classes
end

#delete(worker) ⇒ self?

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.

Removes a worker class from the workers.

Parameters:

  • worker (Class<Worker>)

    The worker class to remove.

Returns:

  • (self, nil)

    If the worker class was in the workers, than self is returned. If the worker class was not in the workers, then nil will be returned.



184
185
186
187
188
# File 'lib/ronin/recon/workers.rb', line 184

def delete(worker)
  if @classes.delete?(worker)
    self
  end
end

#each {|worker| ... } ⇒ Enumerator

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.

Enumerates over the worker classes within the set.

Yields:

  • (worker)

    If a block is given, it will be passed every worker class within the set.

Yield Parameters:

  • worker (Class<Worker>)

    A worker class within the set.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator object will be returned.



119
120
121
# File 'lib/ronin/recon/workers.rb', line 119

def each(&block)
  @classes.each(&block)
end

#intensity(level) ⇒ Workers

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.

Filters the workers by their intensity level.

Parameters:

  • level (:passive, :active, :aggressive)

    The maximum intensity level to filter by.

Returns:



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/ronin/recon/workers.rb', line 224

def intensity(level)
  level_index = INTENSITY_LEVELS.index(level)

  self.class.new(
    @classes.select { |worker|
      if (intensity_index = INTENSITY_LEVELS.index(worker.intensity))
        intensity_index <= level_index
      end
    }
  )
end

#load(worker_id) ⇒ self

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.

Loads a worker and adds it to the workers.

Parameters:

  • worker_id (String)

    The worker ID to load.

Returns:

  • (self)


157
158
159
# File 'lib/ronin/recon/workers.rb', line 157

def load(worker_id)
  self << Recon.load_class(worker_id)
end

#load_file(path) ⇒ self

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.

Loads a worker from a file and adds it to the workers.

Parameters:

  • path (String)

    The path to the file.

Returns:

  • (self)


169
170
171
# File 'lib/ronin/recon/workers.rb', line 169

def load_file(path)
  self << Recon.load_class_from_file(path)
end

#remove(worker_id) ⇒ self?

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.

Removes a worker with the ID from the workers.

Parameters:

  • worker_id (String)

    The worker ID to remove.

Returns:

  • (self, nil)

    If the worker ID was in the workers, than self is returned. If the worker ID was not in the workers, then nil will be returned.



201
202
203
204
205
# File 'lib/ronin/recon/workers.rb', line 201

def remove(worker_id)
  if @classes.reject! { |worker| worker.id == worker_id }
    self
  end
end

#to_setSet<Class<Worker>>

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.

Converts the workers into a Set.

Returns:



254
255
256
# File 'lib/ronin/recon/workers.rb', line 254

def to_set
  @classes
end