Skip to content

Commit

Permalink
Added worker options to the ronin-recon run command (closes #14,#17,#…
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jun 4, 2024
1 parent edfd97a commit 40a322a
Show file tree
Hide file tree
Showing 3 changed files with 496 additions and 1 deletion.
191 changes: 190 additions & 1 deletion lib/ronin/recon/cli/commands/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ module Commands
# ## 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: 3)
# -o, --output FILE The output file to write results to
# -I, --ignore VALUE The values to ignore in result
Expand All @@ -64,6 +71,76 @@ class Run < Command

usage '[options] {IP | IP-range | DOMAIN | HOST | WILDCARD | WEBSITE} ...'

option :config_file, short: '-C',
value: {
type: String,
usage: 'FILE'
},
desc: 'Loads the configuration file'

option :worker, short: '-w',
value: {
type: String,
usage: 'WORKER'
},
desc: 'Explicitly uses a worker' do |worker|
@only_workers << worker
end

option :enable, short: '-e',
value: {
type: String,
usage: 'WORKER'
},
desc: 'Enables a worker' do |worker|
@enable_workers << worker
end

option :disable, short: '-d',
value: {
type: String,
usage: 'WORKER'
},
desc: 'Disables a worker' do |worker|
@disable_workers << worker
end

option :worker_file, value: {
type: String,
usage: 'FILE'
},
desc: 'Loads a worker from a file' do |path|
@worker_files << path
end

option :param, short: '-p',
value: {
type: /\A[^\.\=\s]+\.[^=\s]+=.+\z/,
usage: 'WORKER.NAME=VALUE'
},
desc: 'Sets a param for a worker' do |str|
prefix, value = str.split('=',2)
worker, name = prefix.split('.',2)

@worker_params[worker][name.to_sym] = value
end

option :concurrency, short: '-c',
value: {
type: /\A[^\.\=\s]+=\d+\z/,
usage: 'WORKER=NUM'
},
desc: 'Sets the concurrency of a worker' do |str|
worker, concurrency = str.split('=',2)

@worker_concurrency[worker] = concurrency.to_i
end

option :intensity, value: {
type: [:passive, :active, :aggressive]
},
desc: 'Filter workers by intensity'

option :max_depth, value: {
type: Integer,
usage: 'NUM',
Expand Down Expand Up @@ -107,6 +184,46 @@ class Run < Command

man_page 'ronin-recon-run.1'

# Explicit set of workers to only use.
#
# @return [Set<String>]
attr_reader :only_workers

# Additional set of workers to enable.
#
# @return [Set<String>]
attr_reader :enable_workers

# Additional set of workers to disable.
#
# @return [Set<String>]
attr_reader :disable_workers

# Additional set of worker files to load.
#
# @return [Set<String>]
attr_reader :worker_files

# The loaded configuration for the {Engine}.
#
# @return [Config]
attr_reader :config

# The loaded workers for the {Engine}.
#
# @return [Workers]
attr_reader :workers

# The params for the workers.
#
# @return [Hash{String => Hash{String => String}}]
attr_reader :worker_params

# The concurrency for the workers.
#
# @return [Hash{String => Integer}]
attr_reader :worker_concurrency

# The values that are out of scope.
#
# @return [Array<Values::Value>]
Expand All @@ -121,6 +238,14 @@ class Run < Command
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

Expand All @@ -131,6 +256,9 @@ def initialize(**kwargs)
# The initial recon values.
#
def run(*values)
load_config
load_workers

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

output_file = if options[:output] && options[:output_format]
Expand All @@ -144,7 +272,10 @@ def run(*values)
end

begin
Engine.run(values, max_depth: options[:max_depth], ignore: @ignore) do |engine|
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
Expand Down Expand Up @@ -198,6 +329,64 @@ def parse_value(value)
exit(-1)
end

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

#
# Loads the worker classes from the {Config#workers}, as well as
# additional workers loaded by `--load-worker`.
#
# @note
# If the `--intensity` option is given, then the workers will be
# filtered by intensity.
#
def load_workers
@workers = 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
end

#
# Imports a discovered value into ronin-db.
#
Expand Down
22 changes: 22 additions & 0 deletions man/ronin-recon-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ Runs the recon engine with one or more initial values.
`-D`, `--debug`
: Enables debugging output.

`-C`, `--config-file` *FILE*
: Loads the `ronin-recon` configuration file. If not specified, then
`~/.config/ronin-recon/config.yml` will be loaded instead.

`-w`, `--worker` *WORKER*
: Explicitly uses the specified worker instead of the default set of workers.

`-e`, `--enable` *WORKER*
: Enables the worker in addition to the default set of workers.

`-d`, `--disable` *WORKER*
: Disables the worker from the default set of workers.

`--worker-file` *FILE*
: Loads a custom worker from the specified `.rb` file.

`-p`, `--param` *WORKER*`.`*NAME*`=`*VALUE*
: Sets a param value for the given worker.

`-c`, `--concurrency` *WORKER*`=`*NUM*
: Overrides the concurrency for the given worker.

`--max-depth` *NUM*
: The maximum recon depth. Defaults to depth of `3` if the option is not
specified.
Expand Down
Loading

0 comments on commit 40a322a

Please sign in to comment.