Module: Ronin::UI::CLI

Defined in:
lib/ronin/ui/cli/cli.rb,
lib/ronin/ui/cli/command.rb,
lib/ronin/ui/cli/commands.rb,
lib/ronin/ui/cli/commands/ips.rb,
lib/ronin/ui/cli/commands/exec.rb,
lib/ronin/ui/cli/commands/help.rb,
lib/ronin/ui/cli/commands/urls.rb,
lib/ronin/ui/cli/model_command.rb,
lib/ronin/ui/cli/commands/creds.rb,
lib/ronin/ui/cli/commands/hosts.rb,
lib/ronin/ui/cli/commands/repos.rb,
lib/ronin/ui/cli/script_command.rb,
lib/ronin/ui/cli/commands/emails.rb,
lib/ronin/ui/cli/commands/console.rb,
lib/ronin/ui/cli/commands/database.rb,
lib/ronin/ui/cli/resources_command.rb,
lib/ronin/ui/cli/commands/campaigns.rb,
lib/ronin/ui/cli/exceptions/unknown_command.rb

Overview

The CLI provides an extensible Command Line Interface (CLI) for Ronin. The CLI can load any command using the CLI.command method, from the ronin/ui/cli/commands directory.

Defined Under Namespace

Modules: Commands Classes: Command, ModelCommand, ResourcesCommand, ScriptCommand, UnknownCommand

Constant Summary collapse

DEFAULT_COMMAND =

Name of the default to run

'console'

Class Method Summary collapse

Class Method Details

.command(name) ⇒ Command

Searches for a Command class with the matching name.

Examples:

CLI.command('auto_hack')
# => Ronin::UI::CLI::Commands::AutoHack
CLI.command('auto-hack')
# => Ronin::UI::CLI::Commands::AutoHack

Parameters:

  • name (String, Symbol)

    The command-line name of the command to search for.

Returns:

  • (Command)

    The Command registered with the command-line utility with the matching command-line name.

Raises:

  • (UnknownCommand)

    No valid command could be found or loaded with the matching command-line name.

Since:

  • 1.0.0


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ronin/ui/cli/cli.rb', line 95

def CLI.command(name)
  name = name.to_s

  unless (command = Commands.require_const(name))
    raise(UnknownCommand,"unable to load the command #{name.dump}",caller)
  end

  unless command.respond_to?(:start)
    raise(UnknownCommand,"command #{name.dump} must provide a 'start' method",caller)
  end

  return command
end

.commandsHash

All command-line names of Commands available to the Ronin::UI::CLI.

Returns:

  • (Hash)

    The command-line names and paths of available Command classes.

Since:

  • 1.0.0


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ronin/ui/cli/cli.rb', line 50

def CLI.commands
  if @commands.empty?
    commands_dir = File.join('lib',Commands.namespace_root)

    Installation.each_file_in(commands_dir,:rb) do |path|
      # remove the .rb file extension
      name = path.chomp('.rb')

      # replace any file separators with a ':', to mimic the
      # naming convention of Rake/Thor.
      name.tr!(File::SEPARATOR,':')

      @commands << name
    end
  end

  return @commands
end

.start(argv = ARGV) ⇒ true

Runs the command-line utility. If the first argument is a Command name, the Ronin::UI::CLI will attempt to find and run the command with the matching command-line name. If the first argument is an option, or there are no arguments, the DEFAULT_COMMAND will be ran.

Parameters:

  • argv (Array) (defaults to: ARGV)

    Command-line arguments which are used to select the Command to run, and which will be passed to the Command.

Returns:

  • (true)

    The command was successfully ran.

Since:

  • 1.0.0


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ronin/ui/cli/cli.rb', line 126

def CLI.start(argv=ARGV)
  name = argv.first

  # run the default command if an option or no arguments were given
  if (name.nil? || name[0,1] == '-')
    name = DEFAULT_COMMAND
  else
    argv = argv[1..-1]
  end

  begin
    CLI.command(name).start(argv)
  rescue UnknownCommand => e
    $stderr.puts e.message
    exit -1
  end

  return true
end