Module: Ronin::Masscan

Defined in:
lib/ronin/masscan.rb,
lib/ronin/masscan/cli.rb,
lib/ronin/masscan/root.rb,
lib/ronin/masscan/version.rb,
lib/ronin/masscan/importer.rb,
lib/ronin/masscan/converter.rb,
lib/ronin/masscan/converters.rb,
lib/ronin/masscan/exceptions.rb,
lib/ronin/masscan/cli/command.rb,
lib/ronin/masscan/cli/port_list.rb,
lib/ronin/masscan/cli/importable.rb,
lib/ronin/masscan/converters/csv.rb,
lib/ronin/masscan/converters/json.rb,
lib/ronin/masscan/cli/commands/new.rb,
lib/ronin/masscan/cli/commands/dump.rb,
lib/ronin/masscan/cli/commands/grep.rb,
lib/ronin/masscan/cli/commands/scan.rb,
lib/ronin/masscan/cli/commands/print.rb,
lib/ronin/masscan/cli/commands/import.rb,
lib/ronin/masscan/cli/commands/convert.rb,
lib/ronin/masscan/cli/filtering_options.rb,
lib/ronin/masscan/cli/commands/completion.rb

Overview

Top-level methods for ronin-masscan.

Defined Under Namespace

Modules: Converter, Converters, Importer Classes: CLI, Exception, NotInstalled, ScanFailed

Constant Summary collapse

CACHE_DIR =

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.

The ~/.cache/ronin-masscan cache directory.

Core::Home.cache_dir('ronin-masscan')
ROOT =

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.

Path to ronin-masscan root directory.

File.expand_path(File.join(__dir__,'..','..','..'))
VERSION =

ronin-masscan version

'0.1.0'

Class Method Summary collapse

Class Method Details

.parse(path, **kwargs) ⇒ ::Masscan::OutputFile

Parses a masscan output file.

Parameters:

  • path (String)

    The path to the output file.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for ::Masscan::OutputFile.new.

Options Hash (**kwargs):

  • :format (:binary, :list, :json, :ndjson)

    The format of the output file. If not specified, the format will be inferred from the path's file extension.

Returns:

  • (::Masscan::OutputFile)

    The parsed masscan output file.

Raises:

  • (ArgumentError)

    The output format was not given and it cannot be inferred.

See Also:



110
111
112
# File 'lib/ronin/masscan.rb', line 110

def self.parse(path,**kwargs)
  ::Masscan::OutputFile.new(path,**kwargs)
end

.scan(*ips, **kwargs, &block) ⇒ ::Masscan::OutputFile

Runs masscan and parses the saved output data.

Parameters:

  • ips (Array<#to_s>)

    The IP addresses to scan.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for masscan.

Returns:

  • (::Masscan::OutputFile)

    If the masscan command was sucessful, the parsed masscan data will be returned.

Raises:

See Also:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ronin/masscan.rb', line 63

def self.scan(*ips,**kwargs,&block)
  masscan = ::Masscan::Command.new(ips: ips, **kwargs,&block)

  masscan.ips ||= ips

  unless masscan.output_file
    FileUtils.mkdir_p(CACHE_DIR)
    tempfile = Tempfile.new(['masscan', '.json'], CACHE_DIR)

    masscan.output_file = tempfile.path
  end

  status = masscan.run_command

  case status
  when nil
    raise(NotInstalled,"the masscan command is not installed")
  when false
    raise(ScanFailed,"masscan scan failed: #{masscan.command_argv.join(' ')}")
  else
    parse(masscan.output_file)
  end
end