Class: Ronin::Recon::CLI::Commands::Run Private

Inherits:
Ronin::Recon::CLI::Command show all
Includes:
Core::CLI::Logging, DB::CLI::DatabaseOptions, DebugOption, Printing
Defined in:
lib/ronin/recon/cli/commands/run.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.

Runs the recon engine with one or more initial values.

Usage

ronin-recon run [options] {IP | IP-range | DOMAIN | HOST | WILDCARD | WEBSITE} ...

Options

-D, --debug                      Enable debugging output
-C, --config-file FILE           Loads the configuration file
-w, --worker WORKER              Explicitly uses a worker
-e, --enable WORKER              Enables a worker
-d, --disable WORKER             Disables a worker
    --worker-file FILE           Loads a worker from a file
-p, --param WORKER.NAME=VALUE    Sets a param for a worker
-c, --concurrency WORKER=NUM     Sets the concurrency of a worker
    --max-depth NUM              The maximum recon depth (Default: 10)
-o, --output FILE                The output file to write results to
-I, --ignore VALUE               The values to ignore in result
-F txt|list|csv|json|ndjson|dot|svg|png|pdf,
    --output-format              The output format
    --import                     Imports each newly discovered value into the Ronin database
-h, --help                       Print help information

Arguments

IP|IP-range|DOMAIN|HOST|WILDCARD|WEBSITE  An initial recon value.

Constant Summary

Constants included from Printing

Printing::VALUE_CLASS_NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Printing

#format_value, #print_value, #value_class_name

Methods included from DebugOption

included

Constructor Details

#initialize(**kwargs) ⇒ Run

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 ronin-recon run command.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/ronin/recon/cli/commands/run.rb', line 238

def initialize(**kwargs)
  super(**kwargs)

  @only_workers    = Set.new
  @enable_workers  = Set.new
  @disable_workers = Set.new
  @worker_files    = Set.new

  @worker_params      = Hash.new { |hash,key| hash[key] = {} }
  @worker_concurrency = {}

  @ignore = []
end

Instance Attribute Details

#configConfig (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 loaded configuration for the Engine.

Returns:



210
211
212
# File 'lib/ronin/recon/cli/commands/run.rb', line 210

def config
  @config
end

#disable_workersSet<String> (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.

Additional set of workers to disable.

Returns:

  • (Set<String>)


200
201
202
# File 'lib/ronin/recon/cli/commands/run.rb', line 200

def disable_workers
  @disable_workers
end

#enable_workersSet<String> (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.

Additional set of workers to enable.

Returns:

  • (Set<String>)


195
196
197
# File 'lib/ronin/recon/cli/commands/run.rb', line 195

def enable_workers
  @enable_workers
end

#ignoreArray<Value> (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 values that are out of scope.

Returns:



230
231
232
# File 'lib/ronin/recon/cli/commands/run.rb', line 230

def ignore
  @ignore
end

#only_workersSet<String> (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.

Explicit set of workers to only use.

Returns:

  • (Set<String>)


190
191
192
# File 'lib/ronin/recon/cli/commands/run.rb', line 190

def only_workers
  @only_workers
end

#worker_concurrencyHash{String => Integer} (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 concurrency for the workers.

Returns:

  • (Hash{String => Integer})


225
226
227
# File 'lib/ronin/recon/cli/commands/run.rb', line 225

def worker_concurrency
  @worker_concurrency
end

#worker_filesSet<String> (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.

Additional set of worker files to load.

Returns:

  • (Set<String>)


205
206
207
# File 'lib/ronin/recon/cli/commands/run.rb', line 205

def worker_files
  @worker_files
end

#worker_paramsHash{String => Hash{String => String}} (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 params for the workers.

Returns:

  • (Hash{String => Hash{String => String}})


220
221
222
# File 'lib/ronin/recon/cli/commands/run.rb', line 220

def worker_params
  @worker_params
end

#workersWorkers (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 loaded workers for the Engine.

Returns:



215
216
217
# File 'lib/ronin/recon/cli/commands/run.rb', line 215

def workers
  @workers
end

Instance Method Details

#import_connection(value, parent) ⇒ 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.

Imports a connection between two values into ronin-db.

Parameters:

  • value (Value)

    A discovered recon value to import.

  • parent (Value)

    The parent value of the discovered recon value.



412
413
414
# File 'lib/ronin/recon/cli/commands/run.rb', line 412

def import_connection(value,parent)
  Importer.import_connection(value,parent)
end

#import_value(value) ⇒ 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.

Imports a discovered value into ronin-db.

Parameters:

  • value (Value)

    A discovered recon value to import.



399
400
401
# File 'lib/ronin/recon/cli/commands/run.rb', line 399

def import_value(value)
  Importer.import_value(value)
end

#load_configObject

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 recon configuration file from either the --config-file option or ~/.config/ronin-recon/config.yml.



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/ronin/recon/cli/commands/run.rb', line 336

def load_config
  @config = if (path = options[:config_file])
              Config.load(path)
            else
              Config.default
            end

  unless @only_workers.empty?
    @config.workers = @only_workers
  end

  @enable_workers.each do |worker_id|
    @config.workers.add(worker_id)
  end

  @disable_workers.each do |worker_id|
    @config.workers.delete(worker_id)
  end

  @worker_params.each do |worker,params|
    if @config.params.has_key?(params)
      @config.params[worker].merge!(params)
    else
      @config.params[worker] = params
    end
  end

  @worker_concurrency.each do |worker,concurrency|
    @config.concurrency[worker] = concurrency
  end
end

#load_workersObject

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.

Note:

If the --intensity option is given, then the workers will be filtered by intensity.

Loads the worker classes from the Ronin::Recon::Config#workers, as well as additional workers loaded by --load-worker.



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/ronin/recon/cli/commands/run.rb', line 376

def load_workers
  @workers = Ronin::Recon::Workers.load(@config.workers)

  unless @worker_files.empty?
    @worker_files.each do |path|
      @workers.load_file(path)
    end
  end

  if (level = options[:intensity])
    @workers = @workers.intensity(level)
  end
rescue Ronin::Recon::ClassNotFound => error
  print_error(error.message)
  exit(1)
end

#parse_value(value) ⇒ Value

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.

Parses the value string.

Parameters:

  • value (String)

    The value to parse.

Returns:

  • (Value)

    The parsed value.



324
325
326
327
328
329
330
# File 'lib/ronin/recon/cli/commands/run.rb', line 324

def parse_value(value)
  Value.parse(value)
rescue UnknownValue => error
  print_error(error.message)
  print_error("value must be an IP address, CIDR IP-range, domain, sub-domain, wildcard hostname, or website base URL")
  exit(-1)
end

#run(*values) ⇒ 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.

Runs the ronin-recon run command.

Parameters:

  • values (Array<String>)

    The initial recon values.



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/ronin/recon/cli/commands/run.rb', line 258

def run(*values)
  load_config
  load_workers

  values = values.map { |value| parse_value(value) }

  output_file = if options[:output] && options[:output_format]
                  options[:output_format].open(options[:output])
                end

  if options[:import]
    require 'ronin/db'
    require 'ronin/recon/importer'
    db_connect
  end

  begin
    Engine.run(values, config:    @config,
                       workers:   @workers,
                       max_depth: options[:max_depth],
                       ignore:    @ignore) do |engine|
      engine.on(:value) do |value,parent|
        print_value(value,parent)
      end

      if output_file
        engine.on(:value) do |value|
          output_file << value
        end

        if output_file.kind_of?(OutputFormats::GraphFormat)
          engine.on(:connection) do |value,parent|
            output_file[value] = parent
          end
        end
      end

      if options[:import]
        engine.on(:connection) do |value,parent|
          import_connection(value,parent)
        end
      end

      engine.on(:job_failed) do |worker,value,exception|
        log_error "[#{worker.id}] job failed for value #{value}:"
        log_error "  #{exception.class}: #{exception.message}"

        exception.backtrace.each do |line|
          log_error "    #{line}"
        end
      end
    end
  ensure
    output_file.close if options[:output]
  end
end