Skip to content

Commit

Permalink
Added the ronin-recon config command (closes #178).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Sep 3, 2024
1 parent 53329e6 commit 368f959
Show file tree
Hide file tree
Showing 10 changed files with 728 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Arguments:
Commands:
completion
config
help
irb
new
Expand Down
7 changes: 7 additions & 0 deletions gemspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ generated_files:
- data/completions/ronin-recon
- man/ronin-recon.1
- man/ronin-recon-completion.1
- man/ronin-recon-config.1
- man/ronin-recon-config-disable.1
- man/ronin-recon-config-enable.1
- man/ronin-recon-config-get.1
- man/ronin-recon-config-list.1
- man/ronin-recon-config-set.1
- man/ronin-recon-config-unset.1
- man/ronin-recon-irb.1
- man/ronin-recon-new.1
- man/ronin-recon-workers.1
Expand Down
92 changes: 92 additions & 0 deletions lib/ronin/recon/cli/commands/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# frozen_string_literal: true
#
# ronin-recon - A micro-framework and tool for performing reconnaissance.
#
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
#
# ronin-recon is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-recon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
#

require_relative '../command'

require 'command_kit/commands/auto_load'

module Ronin
module Recon
class CLI
module Commands
#
# Get and set ronin-recon configuration.
#
# ## Usage
#
# ronin-recon config [options] [COMMAND [ARGS...]]
#
# ## Options
#
# -h, --help Print help information
#
# ## Arguments
#
# [COMMAND] The command name to run
# [ARGS ...] Additional arguments for the command
#
# ## Commands
#
# disable
# enable
# get
# help
# list
# set
# unset
#
# ## Examples
#
# ronin-recon config list
# ronin-recon config enable api/hunter_io
# ronin-recon config disable api/hunter_io
# ronin-recon config set --param api/hunter_io.api_key=...
# ronin-recon config set --concurrency web/spider=10
# ronin-recon config unset --param web/spider.proxy
# ronin-recon config unset --concurrency web/spider
#
# @since 0.2.0
#
class Config < Command

include CommandKit::Commands::AutoLoad.new(
dir: "#{__dir__}/config",
namespace: "#{self}"
)

examples [
'list',
'enable api/hunter_io',
'disable api/hunter_io',
'set --param api/hunter_io.api_key=...',
'set --concurrency web/spider=10',
'unset --param web/spider.proxy',
'unset --concurrency web/spider'
]

description 'Get and set ronin-recon configuration'

man_page 'ronin-config.1'

end
end
end
end
end
73 changes: 73 additions & 0 deletions lib/ronin/recon/cli/commands/config/disable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# frozen_string_literal: true
#
# ronin-recon - A micro-framework and tool for performing reconnaissance.
#
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
#
# ronin-recon is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-recon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
#

require_relative '../../config_command'

module Ronin
module Recon
class CLI
module Commands
class Config < Command
#
# Disables a worker in the configuration file.
#
# ## Usage
#
# ronin-recon config disable [options] WORKER
#
# ## Options
#
# -C, --config-file FILE Loads the configuration file
# -h, --help Print help information
#
# ## Arguments
#
# WORKER The worker ID to disable
#
# @since 0.2.0
#
class Disable < ConfigCommand

argument :worker, required: true,
desc: 'The worker ID to disable'

description "Disables a worker in the configuration file"

man_page 'ronin-recon-config-disable.1'

#
# Runs the `ronin-recon config disable` command.
#
# @param [String] worker
#
def run(worker)
load_config

@config.workers.delete(worker)

save_config
end

end
end
end
end
end
end
73 changes: 73 additions & 0 deletions lib/ronin/recon/cli/commands/config/enable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# frozen_string_literal: true
#
# ronin-recon - A micro-framework and tool for performing reconnaissance.
#
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
#
# ronin-recon is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-recon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
#

require_relative '../../config_command'

module Ronin
module Recon
class CLI
module Commands
class Config < Command
#
# Enables a worker in the configuration file.
#
# ## Usage
#
# ronin-recon config enable [options] WORKER
#
# ## Options
#
# -C, --config-file FILE Loads the configuration file
# -h, --help Print help information
#
# ## Arguments
#
# WORKER The worker ID to enable
#
# @since 0.2.0
#
class Enable < ConfigCommand

argument :worker, required: true,
desc: 'The worker ID to enable'

description "Enables a worker in the configuration file"

man_page 'ronin-recon-config-enable.1'

#
# Runs the `ronin-recon config enable` command.
#
# @param [String] worker
#
def run(worker)
load_config

@config.workers.add(worker)

save_config
end

end
end
end
end
end
end
114 changes: 114 additions & 0 deletions lib/ronin/recon/cli/commands/config/get.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# frozen_string_literal: true
#
# ronin-recon - A micro-framework and tool for performing reconnaissance.
#
# Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
#
# ronin-recon is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-recon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
#

require_relative '../../config_command'

module Ronin
module Recon
class CLI
module Commands
class Config < Command
#
# Gets the concurrency or a param for a worker.
#
# ## Usage
#
# ronin-recon config get [options] {--concurrency WORKER | --param WORKER.NAME}
#
# ## Options
#
# -C, --config-file FILE Loads the configuration file
# -c, --concurrency WORKER Gets the concurrency of a worker
# -p, --param WORKER.PARAM Gets a param for a worker
# -h, --help Print help information
#
# @since 0.2.0
#
class Get < ConfigCommand

usage '[options] {--concurrency WORKER | --param WORKER.NAME}'

option :concurrency, short: '-c',
value: {
type: String,
usage: 'WORKER'
},
desc: 'Gets the concurrency for the worker' do |worker|
@mode = :concurrency
@worker = worker
end

option :param, short: '-p',
value: {
type: /\A[^\.\=\s]+\.[^=\s]+\z/,
usage: 'WORKER.PARAM'
},
desc: 'Gets the param for the worker' do |str|
@mode = :param
@worker, @param = str.split('.',2)
end

description 'Gets the concurrency or a param for a worker'

man_page 'ronin-recon-config-get.1'

# Specifies whether to unset the worker's concurrency or param.
#
# @return [:concurrency, :param, nil]
attr_reader :mode

# The worker name.
#
# @return [String, nil]
attr_reader :worker

# The param name to unset.
#
# @return [String, nil]
attr_reader :param

#
# Runs the `ronin-recon config set` command.
#
def run
load_config

case @mode
when :concurrency
if (concurrency = @config.concurrency[@worker])
puts concurrency
end
when :param
if (params = @config.params[@worker]) &&
(value = params[@param])
puts value
end
else
print_error "--concurrency or --param options must be given"
exit(1)
end
end

end
end
end
end
end
end
Loading

0 comments on commit 368f959

Please sign in to comment.