Module: Masscan::Parsers::List

Extended by:
PlainText
Defined in:
lib/masscan/parsers/list.rb

Overview

Parses the masscan -oL output format.

Constant Summary

Constants included from PlainText

PlainText::APP_PROTOCOLS, PlainText::IP_PROTOCOLS, PlainText::REASONS, PlainText::STATUSES

Class Method Summary collapse

Methods included from PlainText

parse_app_protocol, parse_ip, parse_ip_protocol, parse_reason, parse_status, parse_timestamp

Class Method Details

.open(path) {|file| ... } ⇒ File

Opens a list file for parsing.

Parameters:

  • path (String)

    The path to the file.

Yields:

  • (file)

    If a block is given, it will be passed the opened file. Once the block returns, the file will be closed.

Yield Parameters:

  • file (File)

    The opened file.

Returns:

  • (File)

    If no block was given, the opened file will be returned.



33
34
35
# File 'lib/masscan/parsers/list.rb', line 33

def self.open(path,&block)
  File.open(path,&block)
end

.parse(io) {|record| ... } ⇒ Enumerator

Parses the masscan simple list data.

Parameters:

  • io (#each_line)

    The IO object to read from.

Yields:

  • (record)

    If a block is given, it will be passed each parsed record.

Yield Parameters:

Returns:

  • (Enumerator)

    If no block is given, it will return an Enumerator.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/masscan/parsers/list.rb', line 52

def self.parse(io)
  return enum_for(__method__,io) unless block_given?

  io.each_line do |line|
    line.chomp!

    if line.start_with?('open ') || line.start_with?('closed ')
      type, ip_proto, port, ip, timestamp = line.split(' ',5)

      yield Status.new(
        status:    parse_status(type),
        protocol:  parse_ip_protocol(ip_proto),
        port:      port.to_i,
        ip:        parse_ip(ip),
        timestamp: parse_timestamp(timestamp)
      )
    elsif line.start_with?('banner ')
      type, ip_proto, port, ip, timestamp, app_proto, payload = line.split(' ',7)

      yield Banner.new(
        protocol:     parse_ip_protocol(ip_proto),
        port:         port.to_i,
        ip:           parse_ip(ip),
        timestamp:    parse_timestamp(timestamp),
        app_protocol: parse_app_protocol(app_proto),
        payload:      parse_payload(payload)
      )
    end
  end
end

.parse_payload(payload) ⇒ String

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 payload string and removes any \\xXX hex escaped characters.

Parameters:

  • payload (String)

    The payload string to unescape.

Returns:

  • (String)

    The raw payload string.



94
95
96
97
98
# File 'lib/masscan/parsers/list.rb', line 94

def self.parse_payload(payload)
  payload.gsub(/\\x[0-9a-f]{2}/) do |hex_escape|
    hex_escape[2..].to_i(16).chr
  end
end