Class: Ronin::Masscan::CLI::Commands::Scan Private
- Inherits:
-
Ronin::Masscan::CLI::Command
- Object
- Core::CLI::Command
- Ronin::Masscan::CLI::Command
- Ronin::Masscan::CLI::Commands::Scan
- Includes:
- Core::CLI::Logging, Importable
- Defined in:
- lib/ronin/masscan/cli/commands/scan.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Runs masscan and outputs data as JSON or CSV or imports into the database.
Usage
ronin-masscan scan [options] -- [masscan_options]
Options
--db NAME The database to connect to (Default: default)
--db-uri URI The database URI to connect to
--sudo Runs the masscan command under sudo
-o, --output FILE The output file
-F, --output-format json|csv The output format
--import Imports the scan results into the database
-h, --help Print help information
Arguments
masscan_options ... Additional arguments for masscan
Examples
ronin-masscan scan -o scan.json -- 192.168.1.1
ronin-masscan scan --import -- 192.168.1.1
Constant Summary collapse
- OUTPUT_FORMATS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Supported output formats.
{ '.json' => :json, '.csv' => :csv }
Instance Method Summary collapse
-
#import_scan(path) ⇒ Object
private
Imports a masscan output file.
-
#infer_output_format(path) ⇒ :json, ...
private
Infers the output format from the given path's file extension.
-
#run(*masscan_args) ⇒ Object
private
Runs the
ronin-masscan scan
command. -
#run_masscan(*masscan_args, output:) ⇒ Boolean?
private
Runs the
masscan
command. -
#save_output(path, output, format:) ⇒ Object
private
Saves the masscan scan results to an output file in the given format.
Methods included from Importable
Instance Method Details
#import_scan(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Imports a masscan output file.
177 178 179 180 |
# File 'lib/ronin/masscan/cli/commands/scan.rb', line 177 def import_scan(path) db_connect import_file(path) end |
#infer_output_format(path) ⇒ :json, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Infers the output format from the given path's file extension.
198 199 200 |
# File 'lib/ronin/masscan/cli/commands/scan.rb', line 198 def infer_output_format(path) OUTPUT_FORMATS[File.extname(path)] end |
#run(*masscan_args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the ronin-masscan scan
command.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ronin/masscan/cli/commands/scan.rb', line 102 def run(*masscan_args) if (output = [:output]) output_format = .fetch(:output_format) do infer_output_format(output) end if output_format.nil? print_error "cannot infer the output format of the output file (#{output.inspect}), please specify --output-format" exit(1) end end tempfile = Tempfile.new(['ronin-masscan', '.bin']) log_info "Running masscan #{masscan_args.join(' ')} ..." unless run_masscan(*masscan_args, output: tempfile.path) print_error "failed to run masscan" exit(1) end if output log_info "Saving #{output_format.upcase} output to #{output} ..." save_output(tempfile.path,output, format: output_format) end if [:import] log_info "Importing masscan output ..." import_scan(tempfile.path) end end |
#run_masscan(*masscan_args, output:) ⇒ Boolean?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the masscan
command.
146 147 148 149 150 151 |
# File 'lib/ronin/masscan/cli/commands/scan.rb', line 146 def run_masscan(*masscan_args, output: ) masscan_command = ['masscan', '-v', *masscan_args, '-oB', output] masscan_command.unshift('sudo') if [:sudo] return system(*masscan_command) end |
#save_output(path, output, format:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Saves the masscan scan results to an output file in the given format.
166 167 168 169 |
# File 'lib/ronin/masscan/cli/commands/scan.rb', line 166 def save_output(path,output, format: ) # the format has been explicitly specified Converter.convert_file(path,output, format: format) end |