Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --test flag to the ronin-exploits CLI #123

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 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'
flavorjones marked this conversation as resolved.
Show resolved Hide resolved

# 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,24 @@ 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

result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to return the result here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it was better to return it in case the caller wanted to act on the result, rather than return the case statement's value.

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`
flavorjones marked this conversation as resolved.
Show resolved Hide resolved
: 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