Class: Ronin::Masscan::CLI::Commands::New Private

Inherits:
Ronin::Masscan::CLI::Command show all
Includes:
Core::CLI::Generator
Defined in:
lib/ronin/masscan/cli/commands/new.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.

Usage

ronin-masscan new [options] FILE

Options

    --parser                     Generate a masscan output file parser script
    --scanner                    Generate a masscan scanner script
    --printing                   Adds additional printing of the masscan scan data
    --import                     Also import the masscan scan data
    --output-file OUTPUT_FILE    Sets the output file to write to or parse
-p {PORT | [PORT1]-[PORT2]},..., Sets the port range to scan
    --ports
    --ips {IP | IP-range}[,..]   Sets the targets to scan (Defaults: ARGV[0])
-h, --help                       Print help information

Arguments

PATH                             The path to the new masscan ruby script

Examples

ronin-masscan new scanner.rb --ports 22,80,443,8000-9000 --ips '192.168.1.*'
ronin-masscan new parser.rb --parser --output-file path/to/masscan.bin --printing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ New

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.

Initializes the ronin-masscan new command.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for the command.



149
150
151
152
153
154
155
# File 'lib/ronin/masscan/cli/commands/new.rb', line 149

def initialize(**kwargs)
  super(**kwargs)

  @script_type = :scanner
  @ips         = []
  @features    = {}
end

Instance Attribute Details

#featuresHash{Symbol => Boolean} (readonly)

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.

Additional features.

Returns:

  • (Hash{Symbol => Boolean})


141
142
143
# File 'lib/ronin/masscan/cli/commands/new.rb', line 141

def features
  @features
end

#ipsArray<String> (readonly)

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.

The IP addresses or ranges to scan.

Returns:

  • (Array<String>)


136
137
138
# File 'lib/ronin/masscan/cli/commands/new.rb', line 136

def ips
  @ips
end

#output_fileString? (readonly)

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.

The optioanl output file to write to or parse.

Returns:

  • (String, nil)


126
127
128
# File 'lib/ronin/masscan/cli/commands/new.rb', line 126

def output_file
  @output_file
end

#portsArray<Integer, Range(Integer,Integer)>? (readonly)

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.

The optional ports to scan.

Returns:

  • (Array<Integer, Range(Integer,Integer)>, nil)


131
132
133
# File 'lib/ronin/masscan/cli/commands/new.rb', line 131

def ports
  @ports
end

#script_type:scanner, :parser (readonly)

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.

The script type.

Returns:

  • (:scanner, :parser)


121
122
123
# File 'lib/ronin/masscan/cli/commands/new.rb', line 121

def script_type
  @script_type
end

Instance Method Details

#parse_port_range(ports) ⇒ Array<Integer, Range(Integer,Integer)>

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.

Parses a port range.

Parameters:

  • ports (String)

    The port range to parse.

Returns:

  • (Array<Integer, Range(Integer,Integer)>)

    The parsed port range.

Raises:

  • (ArgumentError)

    An invalid port range was given.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/ronin/masscan/cli/commands/new.rb', line 184

def parse_port_range(ports)
  ports.split(',').map do |port|
    case port
    when /\A\d+-\d+\z/
      start, stop = port.split('-',2)

      (start.to_i..stop.to_i)
    when /\A\d+\z/
      port.to_i
    else
      raise(ArgumentError,"invalid port range: #{ports.inspect}")
    end
  end
end

#run(file) ⇒ 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 new command.

Parameters:

  • file (String)

    The path to the new masscan ruby script.



163
164
165
166
167
168
169
170
# File 'lib/ronin/masscan/cli/commands/new.rb', line 163

def run(file)
  @directory  = File.dirname(file)

  mkdir @directory unless File.directory?(@directory)

  erb "script.rb.erb", file
  chmod '+x', file
end