From cb20a7f9f1236442d74d715190fea6b92d42a253 Mon Sep 17 00:00:00 2001 From: Rachael Carder Date: Tue, 30 May 2023 16:18:41 -0500 Subject: [PATCH 1/2] Parse code tags as inline code --- CHANGELOG.md | 3 +++ lib/dradis/plugins/nexpose/gem_version.rb | 2 +- lib/nexpose/vulnerability.rb | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfedf45..b3c8f21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ v4.X.X (XXXX 2023) + - Parse code tags as inline code, not just paragraph preformat tags + +v4.9.0 (June 2023) - Parse inline code, not just code blocks - Wrap ciphers in the `ssl-weak-message-authentication-code-algorithms` finding diff --git a/lib/dradis/plugins/nexpose/gem_version.rb b/lib/dradis/plugins/nexpose/gem_version.rb index c11cd8f..6428cfe 100644 --- a/lib/dradis/plugins/nexpose/gem_version.rb +++ b/lib/dradis/plugins/nexpose/gem_version.rb @@ -9,7 +9,7 @@ def self.gem_version module VERSION MAJOR = 4 MINOR = 9 - TINY = 0 + TINY = 1 PRE = nil STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") diff --git a/lib/nexpose/vulnerability.rb b/lib/nexpose/vulnerability.rb index cd3cdef..d3cb629 100644 --- a/lib/nexpose/vulnerability.rb +++ b/lib/nexpose/vulnerability.rb @@ -120,6 +120,7 @@ def cleanup_html(source) text = $1 text[/\n/] ? "\nbc.. #{ text }\n\np. " : "@#{text}@" end + result.gsub!(/(.*?)<\/code>/){"@#{ $1 }@"} result.gsub!(/(.*?)<\/Paragraph>/m){|m| "#{ $1 }\n"} result.gsub!(/|<\/Paragraph>/, '') result.gsub!(/(.*?)<\/UnorderedList>/m){|m| "#{ $2 }"} From 5b6b59963e5c2c94dadc1f020b64a37545eafcb8 Mon Sep 17 00:00:00 2001 From: Aaron Manaloto Date: Tue, 23 Apr 2024 19:16:34 +0800 Subject: [PATCH 2/2] Add spec and appease rubocop --- lib/nexpose/vulnerability.rb | 35 ++++++++++++++++------------------- spec/fixtures/files/full.xml | 2 +- spec/nexpose_upload_spec.rb | 11 ++++++++++- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/nexpose/vulnerability.rb b/lib/nexpose/vulnerability.rb index 1f82407..25f22e8 100644 --- a/lib/nexpose/vulnerability.rb +++ b/lib/nexpose/vulnerability.rb @@ -20,7 +20,7 @@ def initialize(xml_node) def supported_tags [ # attributes - :added, :cvss_score, :cvss_vector, :modified, :nexpose_id, :pci_severity, + :added, :cvss_score, :cvss_vector, :modified, :nexpose_id, :pci_severity, :published, :risk_score, :severity, :title, # simple tags @@ -34,10 +34,9 @@ def supported_tags ] end - # This allows external callers (and specs) to check for implemented # properties - def respond_to?(method, include_private=false) + def respond_to?(method, include_private = false) return true if supported_tags.include?(method.to_sym) super end @@ -49,7 +48,6 @@ def respond_to?(method, include_private=false) # attribute, simple descendent or collection that it maps to in the XML # tree. def method_missing(method, *args) - # We could remove this check and return nil for any non-recognized tag. # The problem would be that it would make tricky to debug problems with # typos. For instance: <>.potr would return nil instead of raising an @@ -62,11 +60,11 @@ def method_missing(method, *args) # First we try the attributes. In Ruby we use snake_case, but in XML # CamelCase is used for some attributes translations_table = { - :nexpose_id => 'id', - :pci_severity => 'pciSeverity', - :risk_score => 'riskScore', - :cvss_score => 'cvssScore', - :cvss_vector =>'cvssVector' + nexpose_id: 'id', + pci_severity: 'pciSeverity', + risk_score: 'riskScore', + cvss_score: 'cvssScore', + cvss_vector: 'cvssVector' } method_name = translations_table.fetch(method, method.to_s) @@ -96,7 +94,7 @@ def method_missing(method, *args) return @xml.xpath("//test[@id='#{vuln_id}']/Paragraph"). text.split("\n"). collect(&:strip). - reject{|line| line.empty?}.join("\n") + reject { |line| line.empty? }.join("\n") end nil @@ -106,13 +104,13 @@ def method_missing(method, *args) def add_bc_to_ssl_cipher_list(source) result = source.to_s - result.gsub!(/\n(.*?)!(.*?)/){"\nbc. #{ $1 }!#{ $2 }\n"} + result.gsub!(/\n(.*?)!(.*?)/) { "\nbc. #{ $1 }!#{ $2 }\n" } result end def cleanup_html(source) result = source.to_s - result.gsub!(/(.*?)<\/ContainerBlockElement>/m){|m| "#{ $1 }"} + result.gsub!(/(.*?)<\/ContainerBlockElement>/m) { |m| "#{ $1 }" } result.gsub!(/(\s*)(.*?)<\/Paragraph>(\s*)<\/Paragraph>/mi) do text = $2 text[/\n/] ? "\nbc.. #{ text }\n\np. " : "@#{text}@" @@ -121,11 +119,11 @@ def cleanup_html(source) text = $1 text[/\n/] ? "\nbc.. #{ text }\n\np. " : "@#{text}@" end - result.gsub!(/(.*?)<\/code>/){"@#{ $1 }@"} - result.gsub!(/(.*?)<\/Paragraph>/m){|m| "#{ $1 }\n"} + result.gsub!(/(.*?)<\/code>/) { "@#{ $1 }@" } + result.gsub!(/(.*?)<\/Paragraph>/m) { |m| "#{ $1 }\n" } result.gsub!(/|<\/Paragraph>/, '') - result.gsub!(/(.*?)<\/UnorderedList>/m){|m| "#{ $2 }"} - result.gsub!(/(.*?)<\/OrderedList>/m){|m| "#{ $2 }"} + result.gsub!(/(.*?)<\/UnorderedList>/m) { |m| "#{ $2 }" } + result.gsub!(/(.*?)<\/OrderedList>/m) { |m| "#{ $2 }" } result.gsub!(/|<\/ListItem>/, '') result.gsub!(/ /, '') result.gsub!(/ /, '') @@ -142,10 +140,10 @@ def cleanup_nested(source) result = source.to_s result.gsub!(//, '') result.gsub!(/<\/references>/, '') - result.gsub!(/(.*?)<\/reference>/i) {"#{$1.strip}: #{$2.strip}\n"} + result.gsub!(/(.*?)<\/reference>/i) { "#{$1.strip}: #{$2.strip}\n" } result.gsub!(//, '') result.gsub!(/<\/tags>/, '') - result.gsub!(/(.*?)<\/tag>/) {"#{$1}\n"} + result.gsub!(/(.*?)<\/tag>/) { "#{$1}\n" } result.gsub!(/ /, '') result end @@ -157,6 +155,5 @@ def tags_with_html_content def tags_with_nested_content [:references, :tags] end - end end diff --git a/spec/fixtures/files/full.xml b/spec/fixtures/files/full.xml index a8868dc..d6d2d94 100644 --- a/spec/fixtures/files/full.xml +++ b/spec/fixtures/files/full.xml @@ -68,7 +68,7 @@ - A flaw was found in the default error response for status code 400. This flaw could be used by an attacker to expose "httpOnly" cookies when no custom ErrorDocument is specified. + A flaw was found in the default error response for status code 400. This flaw could be used by an attacker to expose httpOnly cookies when no custom ErrorDocument is specified. diff --git a/spec/nexpose_upload_spec.rb b/spec/nexpose_upload_spec.rb index 78f40eb..f8e78e7 100644 --- a/spec/nexpose_upload_spec.rb +++ b/spec/nexpose_upload_spec.rb @@ -170,7 +170,7 @@ expect(args[:content]).to include("#[Content]#\nThe following NTP variables") OpenStruct.new(args) end.once - + expect(@content_service).to receive(:create_evidence) do |args| expect(args[:content]).to include("#[Content]#\nVulnerable URL:") OpenStruct.new(args) @@ -187,6 +187,15 @@ @importer.import(file: @fixtures_dir + '/full.xml') end + + it 'transforms the markup' do + expect(@content_service).to receive(:create_issue) do |args| + expect(args[:text]).to include('@httpOnly@') + OpenStruct.new(args) + end + + @importer.import(file: @fixtures_dir + '/full.xml') + end end describe 'Importer: Full with duplicate nodes' do