Class: Ronin::Masscan::CLI::Commands::Print Private

Inherits:
Ronin::Masscan::CLI::Command show all
Includes:
CommandKit::Printing::Indent, FilteringOptions
Defined in:
lib/ronin/masscan/cli/commands/print.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.

Prints the scanned IPs and ports from masscan scan file(s).

Usage

ronin-masscan print [options] MASSCAN_FILE [...]

Options

-P, --protocol tcp|udp           Filters the targets by protocol
    --ip IP                      Filters the targets by IP
    --ip-range CIDR              Filters the targets by IP range
    -p, --ports {PORT | PORT1-PORT2},...
                                 Filter targets by port number
    --with-app-protocol APP_PROTOCOL[,...]
                                 Filters targets with the app protocol
    --with-payload STRING        Filters targets containing the payload
    --with-payload-regex /REGEX/ Filters targets with the matching payload
-h, --help                       Print help information

Arguments

MASSCAN_FILE ...                 The masscan scan file(s) to parse

Instance Attribute Summary

Attributes included from FilteringOptions

#ip_ranges, #ips, #ports, #protocols, #with_app_protocols, #with_payloads

Instance Method Summary collapse

Methods included from FilteringOptions

#filter_banner_records, #filter_records, #filter_records_by_app_protocol, #filter_records_by_ip, #filter_records_by_ip_range, #filter_records_by_payload, #filter_records_by_port, #filter_records_by_protocol, #filter_status_records, included, #initialize

Instance Method Details

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.

Prints a masscan banner record.

Parameters:

  • banner (::Masscan::Banner)

    The banner record that contains additional information about the port's service.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ronin/masscan/cli/commands/print.rb', line 141

def print_banner_record(banner)
  payload      = banner.payload
  app_protocol = banner.app_protocol

  if payload.include?("\n") # multiline?
    puts app_protocol

    indent do
      payload.chomp.each_line(chomp: true) do |line|
        puts line
      end
    end
  else
    puts "#{app_protocol}\t#{payload}"
  end
end

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.

Prints the open ports for the IP.

Parameters:

  • records (Array<::Masscan::Status, ::Masscan::Banner>)


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ronin/masscan/cli/commands/print.rb', line 96

def print_records(records)
  records.group_by(&:ip).each do |ip,records_for_ip|
    puts "[ #{ip} ]"
    puts

    records_for_ip.group_by { |record|
      [record.port, record.protocol]
    }.each_value do |records_for_port|
      status  = records_for_port.first
      banners = records_for_port[1..]

      indent do
        print_status_record(status)

        unless banners.empty?
          indent do
            banners.each do |banner|
              print_banner_record(banner)
            end
          end

          puts
        end
      end
    end
  end
end

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.

Prints a masscan status record.

Parameters:

  • status (::Masscan::Status)

    The status record that indicates whether a port is open or not.



130
131
132
# File 'lib/ronin/masscan/cli/commands/print.rb', line 130

def print_status_record(status)
  puts "#{status.port}/#{status.protocol}\t#{status.status}"
end

#run(*masscan_files) ⇒ 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 print command.

Parameters:

  • masscan_files (Array<String>)

    The nmap .xml files to parse.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ronin/masscan/cli/commands/print.rb', line 76

def run(*masscan_files)
  masscan_files.each do |masscan_file|
    output_file = begin
                    ::Masscan::OutputFile.new(masscan_file)
                  rescue ArgumentError => error
                    print_error(error.message)
                    exit(1)
                  end

    records = filter_records(output_file)

    print_records(records)
  end
end