From 38504b39a8abcfc4db26652f2b92a23ae5578ac4 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Tue, 24 May 2011 21:48:22 +0000 Subject: [PATCH] Warn the user if there's a truncated nmap file. git-svn-id: file:///home/svn/framework3/trunk@12704 4d416f70-5f16-0410-b530-b9f4589650da --- lib/rex/parser/nmap_nokogiri.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/rex/parser/nmap_nokogiri.rb b/lib/rex/parser/nmap_nokogiri.rb index 87db7f070a..7147c6ca7f 100644 --- a/lib/rex/parser/nmap_nokogiri.rb +++ b/lib/rex/parser/nmap_nokogiri.rb @@ -33,6 +33,7 @@ module Rex @args = args @db = db @state = {} + @state[:current_tag] = {} @block = block if block @report_data = {:wspace => args[:wspace]} super() @@ -106,13 +107,14 @@ module Rex end return attr_pairs end - + # Triggered every time a new element is encountered. We keep state # ourselves with the @state variable, turning things on when we # get here (and turning things off when we exit in end_element()). def start_element(name=nil,attrs=[]) attrs = normalize_attrs(attrs) block = @block + @state[:current_tag][name] = true case name when "host" @state[:in_host] = true @@ -270,6 +272,7 @@ module Rex # When we exit a tag, this is triggered. def end_element(name=nil) block = @block + @state[:current_tag].delete name case name when "os" collect_os_data @@ -299,7 +302,17 @@ module Rex report_uptime(host_object) report_traceroute(host_object) end - @state = {} + @state.delete_if {|k| k != :current_tag} + end + end + + def end_document + block = @block + unless @state[:current_tag].empty? + missing_ends = @state[:current_tag].keys.map {|x| "'#{x}'"}.join(", ") + msg = "Warning, the provided file is incomplete, and there may be missing\n" + msg << "data. The following tags were not closed: #{missing_ends}." + db.emit(:warning,msg,&block) end end