Class: Ronin::Nmap::CLI::Commands::New Private

Inherits:
Ronin::Nmap::CLI::Command show all
Includes:
Core::CLI::Generator
Defined in:
lib/ronin/nmap/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.

Generates a new nmap ruby script.

Usage

ronin-nmap new [options] FILE

Options

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

Arguments

FILE                             The path to the new nmap ruby script.

Examples

ronin-nmap new scanner.rb --ports 22,80,443,8000-9000 --target example.com
ronin-nmap new parser.rb --parser --xml-file path/to/nmap.xml --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-nmap new command.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for the command.



160
161
162
163
164
165
166
# File 'lib/ronin/nmap/cli/commands/new.rb', line 160

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

  @script_type = :scanner
  @targets     = []
  @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})


152
153
154
# File 'lib/ronin/nmap/cli/commands/new.rb', line 152

def features
  @features
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)


142
143
144
# File 'lib/ronin/nmap/cli/commands/new.rb', line 142

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)


127
128
129
# File 'lib/ronin/nmap/cli/commands/new.rb', line 127

def script_type
  @script_type
end

#syn_scanBoolean (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.

Specifies whether to enable SYN scanning.

Returns:

  • (Boolean)


137
138
139
# File 'lib/ronin/nmap/cli/commands/new.rb', line 137

def syn_scan
  @syn_scan
end

#targetsArray<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 targets to scan.

Returns:

  • (Array<String>)


147
148
149
# File 'lib/ronin/nmap/cli/commands/new.rb', line 147

def targets
  @targets
end

#xml_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 XML file to write to or parse.

Returns:

  • (String, nil)


132
133
134
# File 'lib/ronin/nmap/cli/commands/new.rb', line 132

def xml_file
  @xml_file
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.



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/ronin/nmap/cli/commands/new.rb', line 195

def parse_port_range(ports)
  case ports
  when '-' then '-'
  else
    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/
        start = port.chomp('-')

        (start.to_i..)
      when /\A-\d+\z/
        stop = port[1..]

        (..stop.to_i)
      when /\A\d+\z/
        port.to_i
      else
        raise(ArgumentError,"invalid port range: #{ports.inspect}")
      end
    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-nmap new command.

Parameters:

  • file (String)

    The path to the new nmap ruby script.



174
175
176
177
178
179
180
181
# File 'lib/ronin/nmap/cli/commands/new.rb', line 174

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

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

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