Class: Openvas::Result

Inherits:
Client
  • Object
show all
Defined in:
lib/openvas/result.rb

Overview

Class used to interact with OpenVAS’ scans results

Constant Summary collapse

MAX_RESULTS =
1000

Constants inherited from Client

Client::BLOCK_SIZE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

connect, disconnect, query, version

Constructor Details

#initialize(result) ⇒ Result

Returns a new instance of Result.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/openvas/result.rb', line 10

def initialize(result)
  @id = result.at_xpath('@id').value
  @name = result.at_xpath('name').text
  @comment = result.at_xpath('comment').text
  @user = result.at_xpath('owner/name').text
  @host = result.at_xpath('host').text
  @port = result.at_xpath('port').text
  @severity = result.at_xpath('severity').text
  @description = result.at_xpath('description').text
  @cves = result.at_xpath('nvt').at_xpath('cve').text.split(',').map(&:strip)

  @created_at = Time.parse(result.at_xpath('creation_time').text)
  @updated_at = Time.parse(result.at_xpath('modification_time').text)
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



8
9
10
# File 'lib/openvas/result.rb', line 8

def comment
  @comment
end

#created_atObject

Returns the value of attribute created_at.



8
9
10
# File 'lib/openvas/result.rb', line 8

def created_at
  @created_at
end

#cvesObject

Returns the value of attribute cves.



8
9
10
# File 'lib/openvas/result.rb', line 8

def cves
  @cves
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/openvas/result.rb', line 8

def description
  @description
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/openvas/result.rb', line 8

def host
  @host
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/openvas/result.rb', line 8

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/openvas/result.rb', line 8

def name
  @name
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/openvas/result.rb', line 8

def port
  @port
end

#severityObject

Returns the value of attribute severity.



8
9
10
# File 'lib/openvas/result.rb', line 8

def severity
  @severity
end

#updated_atObject

Returns the value of attribute updated_at.



8
9
10
# File 'lib/openvas/result.rb', line 8

def updated_at
  @updated_at
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'lib/openvas/result.rb', line 8

def user
  @user
end

Class Method Details

.allObject



32
33
34
35
36
37
38
39
# File 'lib/openvas/result.rb', line 32

def all
  # TODO: implement pagination
  query = Nokogiri::XML::Builder.new { get_results(filter: "first=1 rows=#{MAX_RESULTS}") }

  query(query).xpath('//get_results_response/result').map do |result|
    new(result)
  end
end

.find_by(id:) ⇒ Object



41
42
43
44
# File 'lib/openvas/result.rb', line 41

def find_by(id:)
  query = Nokogiri::XML::Builder.new { get_results(result_id: id) }
  new(query(query).at_xpath('//get_results_response/result'))
end

.find_by_report_id(id) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/openvas/result.rb', line 46

def find_by_report_id(id)
  # TODO: implement pagination
  query = Nokogiri::XML::Builder.new { get_results(filter: "report_id=#{id} first=1 rows=#{MAX_RESULTS}") }

  query(query).xpath('//get_results_response/result').map do |result|
    new(result)
  end
end

Instance Method Details

#resultsObject



25
26
27
# File 'lib/openvas/result.rb', line 25

def results
  Openvas::Result.find_by_report_id(@id)
end