Class: Risu::Parsers::Nessus::NessusDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/risu/parsers/nessus/nessus_document.rb

Overview

A Object to represents the Nessus XML file in memory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ NessusDocument

Creates a instance of the NessusDocument class



31
32
33
34
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 31

def initialize document
	@document = document
	@new_tags = Array.new
end

Instance Attribute Details

#new_tagsObject

Returns the value of attribute new_tags.



28
29
30
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 28

def new_tags
  @new_tags
end

Instance Method Details

#fix_ipsObject

Fixes the ip field if nil and replaces it with the name if its an ip



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 77

def fix_ips
	@hosts = Host.all

	@hosts.each do |host|
		if host.ip == nil
			begin
				ip = IPAddr.new host.name
				host.ip = ip.to_string
				host.save
			rescue ArgumentError
				next
			end
		end
	end
end

#parseObject

Invokes the SAX parser on the XML document



66
67
68
69
70
71
72
73
74
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 66

def parse
	@parser = LibXML::XML::SaxParser.file @document
	@parser.callbacks = NessusSaxListener.new
	@parser.parse

	#require 'pry'
	#binding.pry
	@new_tags == @parser.callbacks.new_tags
end

#valid?Boolean

Checks the validness of a NessusDocument

Returns:

  • (Boolean)

    True if valid, False if invalid



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/risu/parsers/nessus/nessus_document.rb', line 39

def valid?
	parser = nil

	if File.exist?(@document)
		parser = LibXML::XML::Parser.file @document
	elsif @document.class == "String"
		parser = LibXML::XML::Parser.string @document
	else
		return false
	end

	doc = parser.parse

	if doc.root.name == nil
		return false
	end

	if doc.root.name == "NessusClientData_v2" #.nessus v2
		return true
	elsif doc.root.name == "NessusClientData" #.nessus v1
		return false
	else
		return false
	end
end