Class: Nikto::XML

Inherits:
Object
  • Object
show all
Defined in:
lib/nikto/xml.rb,
lib/nikto/xml/item.rb,
lib/nikto/xml/statistics.rb,
lib/nikto/xml/scan_details.rb

Overview

Represents an nikto XML file or XML data.

Example

require 'nikto/xml'

Nikto::XML.open('nikto.xml') do |xml|
  xml.each_scan_details do |scan_details|
    puts "#{scan_details.site_name}"

    scan_details.each_item do |item|
      puts "  #{item.uri}"
      puts
      puts "    #{item.description}"
      puts
    end
  end
end

Defined Under Namespace

Classes: Item, ScanDetails, Statistics

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, path: nil) {|xml| ... } ⇒ XML

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new XML object.

Parameters:

  • doc (Nokogiri::XML)

    The parsed XML document.

  • path (String, nil) (defaults to: nil)

    The path to the XML file.

Yields:

  • (xml)

    If a block is given, it will be passed the newly created XML parser.

Yield Parameters:

  • xml (XML)

    The newly created XML parser.



58
59
60
61
62
63
# File 'lib/nikto/xml.rb', line 58

def initialize(doc, path: nil)
  @doc  = doc
  @path = File.expand_path(path) if path

  yield self if block_given?
end

Instance Attribute Details

#docNokogiri::XML (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The parsed XML document.

Returns:

  • (Nokogiri::XML)


33
34
35
# File 'lib/nikto/xml.rb', line 33

def doc
  @doc
end

#pathString? (readonly)

The path to the XML file.

Returns:

  • (String, nil)


38
39
40
# File 'lib/nikto/xml.rb', line 38

def path
  @path
end

Class Method Details

.open(path) {|xml| ... } ⇒ XML

Opens an parses an XML file.

Parameters:

  • path (String)

    The path to the XML file.

Yields:

  • (xml)

    If a block is given, it will be passed the newly created XML parser.

Yield Parameters:

  • xml (XML)

    The newly created XML parser.

Returns:

  • (XML)

    The parsed XML.



105
106
107
108
109
110
# File 'lib/nikto/xml.rb', line 105

def self.open(path,&block)
  path = File.expand_path(path)
  doc  = Nokogiri::XML(File.open(path))

  new(doc, path: path, &block)
end

.parse(xml) {|xml| ... } ⇒ XML

Parses the given XML String.

Parameters:

  • xml (String)

    The XML String.

Yields:

  • (xml)

    If a block is given, it will be passed the newly created XML parser.

Yield Parameters:

  • xml (XML)

    The newly created XML parser.

Returns:

  • (XML)

    The parsed XML.



83
84
85
# File 'lib/nikto/xml.rb', line 83

def self.parse(xml,&block)
  new(Nokogiri::XML(xml),&block)
end

Instance Method Details

#each_scan_details {|scan_details| ... } ⇒ Enumerator Also known as: each_target

Parses each scandetails child element.

Yields:

  • (scan_details)

    If a block is given, it will be yielded each scan details object.

Yield Parameters:

  • scan_details (ScanDetails)

    A scan details object.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.



184
185
186
187
188
189
190
# File 'lib/nikto/xml.rb', line 184

def each_scan_details
  return enum_for(__method__) unless block_given?

  @doc.xpath('/niktoscan/scandetails').each do |node|
    yield ScanDetails.new(node)
  end
end

#hosts_testInteger

The hoststest value.

Returns:

  • (Integer)

    The parsed value of the hoststest attribute.



118
119
120
# File 'lib/nikto/xml.rb', line 118

def hosts_test
  @hosts_test ||= @doc.root['@hoststest'].to_i
end

#nikto_xml_versionString

The Nikto XML schema version.

Returns:

  • (String)

    The value of the nxmlversion attribute.



168
169
170
# File 'lib/nikto/xml.rb', line 168

def nikto_xml_version
  @doc.root['nxmlversion']
end

#optionsString

Additional command-line options passed to nikto.

Returns:

  • (String)

    The value of the options attribute.



128
129
130
# File 'lib/nikto/xml.rb', line 128

def options
  @doc.root['options']
end

#scan_detailsArray<ScanDetails> Also known as: targets

The scan details.

Returns:



197
198
199
# File 'lib/nikto/xml.rb', line 197

def scan_details
  each_scan_details.to_a
end

#scan_elapsedString

The duration of the scan.

Returns:

  • (String)

    The value of the scanelapsed attribute.



158
159
160
# File 'lib/nikto/xml.rb', line 158

def scan_elapsed
  @doc.root['scanelapsed']
end

#scan_endTime

When the scan completed.

Returns:

  • (Time)

    The parsed value scanned attribute.



148
149
150
# File 'lib/nikto/xml.rb', line 148

def scan_end
  @scan_end ||= Time.parse(@doc.root['scanend'])
end

#scan_startTime

When the scan started.

Returns:

  • (Time)

    The parsed value of the scanstart attribute.



138
139
140
# File 'lib/nikto/xml.rb', line 138

def scan_start
  @scan_start ||= Time.parse(@doc.root['scanstart'])
end

#targetScanDetails?

The first scan details object.

Returns:



210
211
212
# File 'lib/nikto/xml.rb', line 210

def target
  each_target.first
end

#to_sString

Converts the XML object to a String.

Returns:

  • (String)

    The path to the XML if #path is set, or the XML if the XML was parsed from a String.



221
222
223
224
225
226
227
# File 'lib/nikto/xml.rb', line 221

def to_s
  if @path
    @path
  else
    @doc.to_s
  end
end