Skip to content

Commit

Permalink
Added the -T,--test option to ronin-exploits run (#123)
Browse files Browse the repository at this point in the history
* Added the `-T,--test` option to `ronin-exploits run` to allow only running
  `Exploit#perform_test` to determine if the target is vulnerable or not:

      $ ronin-exploits --file=path/to/exploit.rb --test -p host=example.com ...

* Printed output looks like one of these lines, depending on the return type:

      [+] Vulnerable: <test result message>
      [-] NotVulnerable: <test result message>
      [~] Unknown: <test result message>
      [!] Unexpected: <other result type to_s>

---------

Co-authored-by: Postmodern <postmodern.mod3@gmail.com>
  • Loading branch information
flavorjones and postmodern committed Jun 28, 2024
1 parent 3e4ddb6 commit 56d6776
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/ronin/exploits/cli/commands/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module Commands
# -f, --file FILE The exploit file to load
# -p, --param NAME=VALUE Sets a param
# -D, --dry-run Builds the exploit but does not launch it
# -T --test Runs only the exploit test
# --payload-file FILE Load the payload from the given Ruby file
# --read-payload FILE Reads the payload string from the file
# --payload-string STRING Uses the raw payload string instead
Expand Down Expand Up @@ -85,11 +86,15 @@ class Run < ExploitCommand
include Core::CLI::Options::Param
include Core::CLI::Logging
include CommandKit::Printing::Indent
include Support::CLI::Printing

# Exploit options
option :dry_run, short: '-D',
desc: 'Builds the exploit but does not launch it'

option :test, short: '-T',
desc: 'Runs only the exploit test'

# Payload options
option :payload_file, value: {
type: String,
Expand Down Expand Up @@ -273,7 +278,12 @@ def run(name=nil)
validate_payload
initialize_exploit
validate_exploit
run_exploit

if options[:test]
run_test
else
run_exploit
end

if options[:irb]
start_shell
Expand Down Expand Up @@ -382,6 +392,22 @@ def run_exploit
end
end

#
# Run the exploit's test method, and print the result.
#
def run_test
case (result = @exploit.perform_test)
when TestResult::Vulnerable
print_positive "Vulnerable: #{result}"
when TestResult::NotVulnerable
print_negative "NotVulnerable: #{result}"
when TestResult::Unknown
print_warning "Unknown: #{result}"
else
print_error "Unexpected result: #{result.inspect}"
end
end

#
# Starts an interactive ruby shell within the exploit object.
#
Expand Down
3 changes: 3 additions & 0 deletions man/ronin-exploits-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Loads and runs an exploit.
`-D`, `--dry-run`
: Builds the exploit but does not launch it.

`-T`, `--test`
: Runs only the exploit test.

`--payload-file` *FILE*
: Load the payload from the given Ruby file.

Expand Down

0 comments on commit 56d6776

Please sign in to comment.