From 4dcbd7c1aebcfa83d16f9264cdcc95227a276d7f Mon Sep 17 00:00:00 2001 From: Brian Patterson Date: Mon, 1 Feb 2016 16:11:06 -0600 Subject: [PATCH] Add a nokogiri xml stream parser for Burp issue xml and rename original burp parser to burp session parser so both are supported. --- lib/msf/core/db_manager/import.rb | 9 +- lib/msf/core/db_manager/import/burp_issue.rb | 20 +++ .../import/{burp.rb => burp_session.rb} | 2 +- lib/msf/ui/console/command_dispatcher/db.rb | 1 + lib/rex/parser/burp_issue_nokogiri.rb | 139 ++++++++++++++++++ lib/rex/parser/burp_session_nokogiri.rb | 2 +- lib/rex/parser/nokogiri_doc_mixin.rb | 5 + .../ui/console/command_dispatcher/db_spec.rb | 1 + 8 files changed, 175 insertions(+), 4 deletions(-) create mode 100644 lib/msf/core/db_manager/import/burp_issue.rb rename lib/msf/core/db_manager/import/{burp.rb => burp_session.rb} (96%) create mode 100644 lib/rex/parser/burp_issue_nokogiri.rb diff --git a/lib/msf/core/db_manager/import.rb b/lib/msf/core/db_manager/import.rb index c93fb6cb5b..c5a0e9d8d4 100644 --- a/lib/msf/core/db_manager/import.rb +++ b/lib/msf/core/db_manager/import.rb @@ -16,7 +16,8 @@ module Msf::DBManager::Import autoload :Acunetix, 'msf/core/db_manager/import/acunetix' autoload :Amap, 'msf/core/db_manager/import/amap' autoload :Appscan, 'msf/core/db_manager/import/appscan' - autoload :Burp, 'msf/core/db_manager/import/burp' + autoload :BurpIssue, 'msf/core/db_manager/import/burp_issue' + autoload :BurpSession, 'msf/core/db_manager/import/burp_session' autoload :CI, 'msf/core/db_manager/import/ci' autoload :Foundstone, 'msf/core/db_manager/import/foundstone' autoload :FusionVM, 'msf/core/db_manager/import/fusion_vm' @@ -41,7 +42,8 @@ module Msf::DBManager::Import include Msf::DBManager::Import::Acunetix include Msf::DBManager::Import::Amap include Msf::DBManager::Import::Appscan - include Msf::DBManager::Import::Burp + include Msf::DBManager::Import::BurpIssue + include Msf::DBManager::Import::BurpSession include Msf::DBManager::Import::CI include Msf::DBManager::Import::Foundstone include Msf::DBManager::Import::FusionVM @@ -267,6 +269,9 @@ module Msf::DBManager::Import elsif (data[0,1024] =~ /]+)')[1] + @state[:refs] = ["URI-#{uri}"] + end + + def report_web_host_info + return unless @state[:host] + address = Rex::Socket.resolv_to_dotted(@state[:host]) rescue nil + host_info = {:workspace => @args[:wspace]} + host_info[:address] = address + host_info[:name] = @state[:host] + db_report(:host, host_info) + end + + def report_web_service_info + return unless @state[:host] + return unless @state[:port] + return unless @state[:proto] + return unless @state[:service_name] + service_info = {} + service_info[:host] = @state[:host] + service_info[:port] = @state[:port] + service_info[:proto] = @state[:proto] + service_info[:name] = @state[:service_name] + @state[:service_object] = db_report(:service, service_info) + end + + def report_vuln + return unless @state[:service_object] + return unless @state[:vuln_name] + return unless @state[:issue_detail] + return unless @state[:refs] + vuln_info = {} + vuln_info[:service_id] = @state[:service_object].id + vuln_info[:host] = @state[:host] + vuln_info[:name] = @state[:vuln_name] + vuln_info[:info] = @state[:issue_detail] + vuln_info[:refs] = @state[:refs] + @state[:vuln_object] = db_report(:vuln, vuln_info) + end + + def in_issue + return false unless in_tag("issue") + return false unless in_tag("issues") + return true + end + + def has_text + return false unless @text + return false if @text.strip.empty? + @text = @text.strip + end + end + + end +end + diff --git a/lib/rex/parser/burp_session_nokogiri.rb b/lib/rex/parser/burp_session_nokogiri.rb index 2822fa28bf..057c5dae53 100644 --- a/lib/rex/parser/burp_session_nokogiri.rb +++ b/lib/rex/parser/burp_session_nokogiri.rb @@ -157,7 +157,7 @@ module Rex host_info = {:workspace => @args[:wspace]} host_info[:address] = @state[:web_site].service.host.address host_info[:name] = @state[:uri].host - report_db(:host, host_info) + db_report(:host, host_info) end def report_web_service_info diff --git a/lib/rex/parser/nokogiri_doc_mixin.rb b/lib/rex/parser/nokogiri_doc_mixin.rb index bfee26fa8c..9e59c56061 100644 --- a/lib/rex/parser/nokogiri_doc_mixin.rb +++ b/lib/rex/parser/nokogiri_doc_mixin.rb @@ -200,6 +200,11 @@ module Parser return attr_pairs end + # Removes HTML from a string + def strip_html_tags(text) + return text.gsub!(/(<[^>]*>)|\n|\t/s) {" "} + end + # This breaks xml-encoded characters, so need to append. # It's on the end_element tag name to turn the appending # off and clear out the data. diff --git a/spec/lib/msf/ui/console/command_dispatcher/db_spec.rb b/spec/lib/msf/ui/console/command_dispatcher/db_spec.rb index 66a8edcde3..28605ad12b 100644 --- a/spec/lib/msf/ui/console/command_dispatcher/db_spec.rb +++ b/spec/lib/msf/ui/console/command_dispatcher/db_spec.rb @@ -340,6 +340,7 @@ RSpec.describe Msf::Ui::Console::CommandDispatcher::Db do " Amap Log", " Amap Log -m", " Appscan", + " Burp Issue XML", " Burp Session XML", " CI", " Foundstone",