This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from marcuscarey/patch-1
Add support for passing in XML strings to Nessus::Parse.new
- Loading branch information
Showing
4 changed files
with
68 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
#!/usr/bin/env ruby | ||
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__),'..','lib')) | ||
|
||
#!/usr/bin/env ruby | ||
require 'rubygems' | ||
require 'nessus' | ||
|
||
# Ruby-Nessus Example | ||
# | ||
# This proc is called by scan.each_host in each variation of Nessus::Parse | ||
def print_info(host) | ||
puts host.ip | ||
puts host.hostname | ||
puts host.os_name | ||
puts host.runtime | ||
|
||
Nessus::Parse.new('example_v1.nessus') do |scan| | ||
|
||
scan.each_host do |host| | ||
puts host.ip | ||
puts host.hostname | ||
puts host.os_name | ||
puts host.runtime | ||
|
||
#puts host.mac_addr | ||
# puts host.event_percentage_for('icmp', true) | ||
# puts host.ports.inspect | ||
# | ||
# puts "\n" | ||
# | ||
host.each_event do |event| | ||
|
||
puts "=> #{event.name}" if event.name | ||
# puts event.synopsis if event.synopsis | ||
# puts "\n" | ||
# puts event.output | ||
# puts "\n" | ||
# puts event.patch_publication_date.pretty if event.patch_publication_data | ||
# puts event.see_also unless event.see_also.empty? | ||
# puts event.synopsis if event.synopsis | ||
# puts event.solution if event.solution | ||
|
||
end | ||
# | ||
# puts host.mac_addr | ||
# puts host.event_percentage_for('icmp', true) | ||
# puts host.ports.inspect | ||
|
||
host.each_event do |event| | ||
puts "=> #{event.name}" if event.name | ||
# puts event.synopsis if event.synopsis | ||
# puts "\n" | ||
# puts event.output | ||
# puts "\n" | ||
|
||
|
||
# puts event.patch_publication_date.pretty if event.patch_publication_data | ||
# puts event.see_also unless event.see_also.empty? | ||
# puts event.synopsis if event.synopsis | ||
# puts event.solution if event.solution | ||
end | ||
|
||
|
||
end | ||
|
||
# From a file: | ||
puts '+ Using a Nessus XML file:' | ||
Nessus::Parse.new('example_v1.nessus') do |scan| | ||
scan.each_host(&method(:print_info)) | ||
end | ||
|
||
puts | ||
|
||
# From a string: | ||
puts '+ Using an XML string:' | ||
Nessus::Parse.new(nil, { :xml => File.read('example_v1.nessus') }) do |scan| | ||
scan.each_host(&method(:print_info)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
module Helpers | ||
v1 = File.join(File.dirname(__FILE__),'example_v1.nessus') | ||
v2 = File.join(File.dirname(__FILE__),'example_v2.nessus') | ||
DOT_NESSUS_V1 = Nokogiri::XML.parse(File.open(v1).read) | ||
DOT_NESSUS_V2 = Nokogiri::XML.parse(File.open(v2).read) | ||
end | ||
DOT_NESSUS_V1_PATH = File.join(File.dirname(__FILE__),'example_v1.nessus') | ||
DOT_NESSUS_V2_PATH = File.join(File.dirname(__FILE__),'example_v2.nessus') | ||
|
||
DOT_NESSUS_V1_DOC = File.read(DOT_NESSUS_V1_PATH) | ||
DOT_NESSUS_V2_DOC = File.read(DOT_NESSUS_V2_PATH) | ||
|
||
DOT_NESSUS_V1 = Nokogiri::XML.parse(DOT_NESSUS_V1_DOC) | ||
DOT_NESSUS_V2 = Nokogiri::XML.parse(DOT_NESSUS_V2_DOC) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require_relative '../spec_helper' | ||
require_relative '../helpers/xml' | ||
|
||
describe 'Nessus::Parse' do | ||
it 'should parse a valid v1 .nessus file' do | ||
lambda { Nessus::Parse.new(Helpers::DOT_NESSUS_V1_PATH) }.should_not raise_error | ||
end | ||
|
||
it 'should parse a valid v2 .nessus file' do | ||
lambda { Nessus::Parse.new(Helpers::DOT_NESSUS_V2_PATH) }.should_not raise_error | ||
end | ||
|
||
it 'should parse a valid v1 .nessus string' do | ||
options = { :xml => Helpers::DOT_NESSUS_V1_DOC } | ||
lambda { Nessus::Parse.new(nil, options) }.should_not raise_error | ||
end | ||
|
||
it 'should parse a valid v2 .nessus string' do | ||
options = { :xml => Helpers::DOT_NESSUS_V2_DOC } | ||
lambda { Nessus::Parse.new(nil, options) }.should_not raise_error | ||
end | ||
end |