Class: Risu::Parsers::Nexpose::SimpleNexpose

Inherits:
Object
  • Object
show all
Includes:
LibXML::XML::SaxParser::Callbacks
Defined in:
lib/risu/parsers/nexpose/simple_nexpose.rb

Constant Summary collapse

VALID_FINGERPRINTS =
{
	"description" => :os,
	"vendor" => nil,
	"family" => nil,
	"product" => nil,
	"version" => nil,
	"device-class" => :system_type,
	"architecture" => nil
}

Instance Method Summary collapse

Constructor Details

#initializeSimpleNexpose

Returns a new instance of SimpleNexpose.



42
43
44
45
46
# File 'lib/risu/parsers/nexpose/simple_nexpose.rb', line 42

def initialize
	@vals = Hash.new

	@report = Report.create
end

Instance Method Details

#on_characters(text) ⇒ Object

Called when the inner text of a element is reached

Parameters:

  • text


71
72
73
74
75
76
77
# File 'lib/risu/parsers/nexpose/simple_nexpose.rb', line 71

def on_characters(text)
	if @vals[@tag] == nil then
		@vals[@tag] = text
	else
		@vals[@tag] << text
	end
end

#on_end_element(element) ⇒ Object

Called when the end of the XML element is reached

Parameters:

  • element


82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/risu/parsers/nexpose/simple_nexpose.rb', line 82

def on_end_element(element)
	@tag = nil
	case element
		when "device"
			@in_device = false
		when "description"
			if @in_device && @in_fingerprint
				@rh.attributes = { VALID_FINGERPRINTS[element] => @vals[element].gsub("\n", ",") } if VALID_FINGERPRINTS.key?(element)
				@rh.save
			end
		when "fingerprint"
			@in_fingerprint = false
	end
end

#on_start_element(element, attributes) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/risu/parsers/nexpose/simple_nexpose.rb', line 50

def on_start_element(element, attributes)
	@tag = element
	@vals[@tag] = ""
	puts element

	case element
		when "device"
			@in_device = true
			@rh = @report.hosts.create
			@rh.name = attributes["address"]
			@rh.ip = attributes["address"]
			@rh.save
		when "fingerprint"
			@in_fingerprint = true
	end

end