Module: Schatz::Input::ParserHelper

Included in:
IncrExport, IncrLineParser, TextExport, TxtLineParser
Defined in:
lib/schatz/input/parser.rb

Constant Summary collapse

Regexp.new '(https?):\/\/([a-zA-Z0-9\.\-]+\.?d?b?.com):?(\d{1,5}*)'
Regexp.new '(gcm\d{12}|GCM\d{12}).*(https?):\/\/([a-zA-Z0-9\.\-]+\.?d?b?.com):?(\d{1,5}*).*'
SOURCE_SUBNET =
Regexp.new '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\ *\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
GCM_NUMBER =
Regexp.new 'gcm\d{12}|GCM\d{12}'
REGEXP_HOST =
Regexp.new '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.+(\d{1,5}[\-\,]?)+$'
REGEXP_HOST_PORTS =
Regexp.new '^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\ +(\d{1,5}\-\d{1,5}|\d{1,5}(\,\d{1,5})*)$'
ONE_PORT =
Regexp.new '^\d{1,5}$'
ONE_HYPHEN =
Regexp.new '^\d{1,5}(\-)+\d{1,5}$'
ONE_OR_MORE_COMMA =
Regexp.new'^\d{1,5}(,\d{1,5})+$'
IP_ADDRESS =
Regexp.new '(10\.\d{1,3}\.\d{1,3}\.\d{1,3})(?#matches ip address)(?!.*255\.\d{1,3}\.\d{1,3}\.\d{1,3})'
PORTS_WITH_PROTOCOL =
Regexp.new '([\d\-\,]{1,450}) ?(TCP|UDP)'
CONVERSATION_HTML =
Regexp.new "(#{GCM_NUMBER.source}).*#{IP_ADDRESS.source}.*#{PORTS_WITH_PROTOCOL.source}.*"
CONVERSATION_ROW =
Regexp.new ".*#{IP_ADDRESS.source}.*#{PORTS_WITH_PROTOCOL.source}.*"

Instance Method Summary collapse

Instance Method Details

#parse_ports_field(ports) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/schatz/input/parser.rb', line 31

def parse_ports_field(ports)
  raise ArgumentError, "received nil instead of string for ports" unless ports 
  raise ArgumentError, "received blank instead of string for ports" if ports.empty?        
  ports.gsub!(/ /, "")
case ports
  when ONE_HYPHEN
    start_range, end_range = ports.split("-")
    [*start_range..end_range].map(&:to_i)
  when ONE_OR_MORE_COMMA
    ports.split(",").map(&:to_i)
  when ONE_PORT
    [ports.to_i]
  else ports
    raise ExportedIncrFieldErrorPorts, "for #{ports}"
  end
end

#push_connection(host, port, protocol, gcm, hosts) ⇒ Object



48
49
50
# File 'lib/schatz/input/parser.rb', line 48

def push_connection(host, port, protocol, gcm, hosts)
  hosts << {:host => host, :port => port.to_i, :protocol => protocol, :gcm => gcm}
end