Sha256: d73e7df344eb53779e8ef9390329387a9e46f652817f5ced060a562df415cca7

Contents?: true

Size: 1.83 KB

Versions: 35

Compression:

Stored size: 1.83 KB

Contents

require 'rexml/document'
require 'rex/ui'

module Rex
module Parser


class IP360XMLStreamParser

	attr_accessor :on_found_host

	def initialize(&block)
		reset_state
		on_found_host = block if block
	end

	def reset_state
		@host = {'hname' => nil, 'hid' => nil, 'addr' => nil, 'mac' => nil, 'os' => nil,
			'vulns' => ['vuln' => {'vulnid' => nil, 'port' => nil, 'proto' => nil} ],
			'apps' => ['app' => {'appid' => nil, 'svcid' => nil, 'port' => nil, 'proto' => nil } ],
		}
		@state = :generic_state
	end

	def tag_start(name, attributes)
		case name
		when "host"
			@host['hid'] = attributes['persistent_id']
		when "ip"
			@state = :is_ip
		when "dnsName"
			@state = :is_fqdn
		when "macAddress"
			@state = :is_mac
		when "os"
			@host['os'] = attributes['id']	
		when "vulnerability"
			@x = Hash.new	
			@x['vulnid'] = attributes['id']
		when "port"
			@state = :is_port
		when "protocol"
			@state = :is_proto
		when "application"
			@y = Hash.new
			@y['appid'] = attributes['application_id']
			@y['svcid'] = attributes['svcid']
			@y['port'] = attributes['port']
			@y['proto'] = attributes['protocol']
			@host['apps'].push @y
		end
	end
	
	def text(str)
		case @state
		when :is_fqdn
			@host['hname'] = str
		when :is_ip
			@host['addr'] = str
		when :is_mac
			@host['mac'] = str
		when :is_port
			@x['port'] = str
		when :is_proto
			@x['proto'] = str
		end
	end

	def tag_end(name)
		case name
		when "host"
			on_found_host.call(@host) if on_found_host
			reset_state
		when "vulnerability"
			@host['vulns'].push @x
		end
		@state = :generic_state
	end

	def cdata(d)
		#do nothing
	end

	# We don't need these methods, but they're necessary to keep REXML happy
	#
	def xmldecl(version, encoding, standalone) # :nodoc:
	end
	def comment(str) # :nodoc:
	end
	def instruction(name, instruction) # :nodoc:
	end
	def attlist # :nodoc:
	end
end

end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/parser/ip360_xml.rb
librex-0.0.63 lib/rex/parser/ip360_xml.rb
librex-0.0.54 lib/rex/parser/ip360_xml.rb
librex-0.0.53 lib/rex/parser/ip360_xml.rb
librex-0.0.52 lib/rex/parser/ip360_xml.rb
librex-0.0.51 lib/rex/parser/ip360_xml.rb
librex-0.0.50 lib/rex/parser/ip360_xml.rb
librex-0.0.49 lib/rex/parser/ip360_xml.rb
librex-0.0.48 lib/rex/parser/ip360_xml.rb
librex-0.0.47 lib/rex/parser/ip360_xml.rb
librex-0.0.46 lib/rex/parser/ip360_xml.rb
librex-0.0.44 lib/rex/parser/ip360_xml.rb
librex-0.0.43 lib/rex/parser/ip360_xml.rb
librex-0.0.42 lib/rex/parser/ip360_xml.rb
librex-0.0.41 lib/rex/parser/ip360_xml.rb
librex-0.0.40 lib/rex/parser/ip360_xml.rb
librex-0.0.39 lib/rex/parser/ip360_xml.rb
librex-0.0.38 lib/rex/parser/ip360_xml.rb
librex-0.0.37 lib/rex/parser/ip360_xml.rb
librex-0.0.36 lib/rex/parser/ip360_xml.rb