Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HTML tag parsing to work with Acunetix 360 #40

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ v4.5.0 (August 2022)

v4.4.0 (June 2022)
- Registers template mappings locally
- Update HTML tag parsing for Acunetix 360

v4.3.0 (April 2022)
- No changes
Expand Down
39 changes: 23 additions & 16 deletions lib/acunetix/concerns/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,39 @@ def cleanup_html(source)

format_table(result)

result.gsub!(/"/, '"')
result.gsub!(/&/, '&')
result.gsub!(/&lt;/, '<')
result.gsub!(/&gt;/, '>')

result.gsub!(/<h[0-9] >(.*?)<\/h[0-9]>/) { "\n\n*#{$1.strip}*\n\n" }
result.gsub!(/<b>(.*?)<\/b>/) { "*#{$1.strip}*" }
result.gsub!(/<br\/>/, "\n")
result.gsub!(/<br\/>|<br \/>/, "\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you simplify this with an optional space?

result.gsub!(/<div(.*?)>|<\/div>/, '')
result.gsub!(/<span.*?>(.*?)<\/span>/m){"#{$1.strip}"}
result.gsub!(/<span.*?>|<\/span>/, '') #repeating again to deal with nested/empty/incomplete span tags

result.gsub!(/<a (.*?)href='(.*?)'><i(.*?)><\/i>(.*?)<\/a>/m) { "\"#{$4}\":#{$2}" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this one should cover the next one (L19) so we don't need multiple regex's to parse the same tag.

result.gsub!(/<a.*?>(.*?)<\/a>/m, '\1')
result.gsub!(/<font.*?>(.*?)<\/font>/m, '\1')
result.gsub!(/<h2>(.*?)<\/h2>/) { "*#{$1.strip}*" }
result.gsub!(/<i>(.*?)<\/i>/, '\1')
result.gsub!(/<p.*?>(.*?)<\/p>/) { "\np. #{$1.strip}\n" }
result.gsub!(/<code><pre.*?>(.*?)<\/pre><\/code>/m){|m| "\n\nbc.. #{$1.strip}\n\np. \n" }
result.gsub!(/<code>(.*?)<\/code>/) { "@#{$1.strip}@" }
result.gsub!(/<pre.*?>(.*?)<\/pre>/m){|m| "\n\nbc.. #{$1.strip}\n\np. \n" }

result.gsub!(/<li.*?>([\s\S]*?)<\/li>/m){"\n* #{$1.strip}"}
result.gsub!(/<ul>([\s\S]*?)<\/ul>/m){ "#{$1.strip}\n" }
result.gsub!(/<em>(.*?)<\/em>/) { "_#{$1.strip}_" }
result.gsub!(/<p.*?>(.*?)<\/p>/) { "p. #{$1.strip}\n\n" }
result.gsub!(/<code><pre.*?>(.*?)<\/pre><\/code>/m){|m| "\n\nbc.. #{$1}\n\np. \n" }
result.gsub!(/<code>(.*?)<\/code>/) { "\n\nbc. #{$1}\n\n" }
result.gsub!(/<pre.*?>(.*?)<\/pre>/) { "\n\nbc. #{$1}\n\n" }
result.gsub!(/<pre.*?>(.*?)<\/pre>/m){|m| "\n\nbc.. #{$1}\n\np. \n" }

result.gsub!(/<li.*?>([\s\S]*?)<\/li>/m){"\n* #{$1}"}
aapomm marked this conversation as resolved.
Show resolved Hide resolved
result.gsub!(/<ul>([\s\S]*?)<\/ul>/m){ "#{$1}\n" }
result.gsub!(/(<ul>)|(<\/ul>|(<ol>)|(<\/ol>))/, "\n")
result.gsub!(/<li>/, "\n* ")
result.gsub!(/<\/li>/, "\n")
result.gsub!(/<strong>(.*?)<\/strong>/m) { "*#{$1}*" }

result.gsub!(/&quot;/, '"')
result.gsub!(/&amp;/, '&')
result.gsub!(/&lt;/, '<')
result.gsub!(/&gt;/, '>')

result.gsub!(/<strong>(.*?)<\/strong>/) { "*#{$1.strip}*" }
result.gsub!(/<span.*?>(.*?)<\/span>/m){"#{$1.strip}\n"}
# Cleanup lingering <p></p>
Copy link
Member

@etdsoft etdsoft Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rachkor is this really an issue? We have this and L16 "cleanup" lines, is the code so bad that they include random <span> and <p> tags all over the place? It seems we're doing something wrong with our parsing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will only catch the nested <p> tags and it doesn't seem like there's any in the sample files. Removed ✅

result.gsub!(/<p.*?>(.*?)<\/p>/m) { $1 }

result
end
Expand Down Expand Up @@ -68,7 +75,7 @@ def format_table(str)

# Some of the values have embedded HTML conent that we need to strip
def tags_with_html_content
[:details, :description, :detailed_information, :impact, :recommendation]
[:details, :description, :detailed_information, :impact, :recommendation, :remedial_actions, :remedial_procedure, :external_references]
end

def tags_with_commas
Expand Down
101 changes: 101 additions & 0 deletions spec/fixtures/files/acunetix_360.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8" ?>
<acunetix-360>
<target>
<scan-id>scan id</scan-id>
<url>www.google.com/</url>
<initiated>06/01/2022</initiated>
<duration>00:00:50.9910251</duration>
</target>
<vulnerabilities>
<vulnerability>
<LookupId>d202b64e-8451-407c-3680-abdc02f0038f</LookupId>
<url>http://aspnet.testsparker.com/blog/%27))%20WAITFOR%20DELAY%20%270%3a0%3a25%27--/</url>
<type>ConfirmedBlindSqlInjection</type>
<name>Blind SQL Injection</name>
<severity>Critical</severity>
<certainty>100</certainty>
<confirmed>True</confirmed>
<state>Present</state>
<FirstSeenDate>6/16/2020 1:41:23 PM +00:00</FirstSeenDate>
<LastSeenDate>6/16/2020 1:41:23 PM +00:00</LastSeenDate>
<classification>
<owasp>A1</owasp>
<wasc>19</wasc>
<cwe>89</cwe>
<capec>66</capec>
<pci32>6.5.1</pci32>
<hipaa>164.306(a), 164.308(a)</hipaa>
<owasppc></owasppc>
<iso27001>A.14.2.5</iso27001>


<cvss>
<vector>CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N</vector>

<score>
<type>Base</type>
<value>8.6</value>
<severity>High</severity>
</score>
<score>
<type>Temporal</type>
<value>8.6</value>
<severity>High</severity>
</score>
<score>
<type>Environmental</type>
<value>8.6</value>
<severity>High</severity>
</score>

</cvss>



<cvss31>
<vector>CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N</vector>

<score>
<type>Base</type>
<value>8.6</value>
<severity>High</severity>
</score>
<score>
<type>Temporal</type>
<value>8.6</value>
<severity>High</severity>
</score>
<score>
<type>Environmental</type>
<value>8.6</value>
<severity>High</severity>
</score>

</cvss31>
</classification>

<description><![CDATA[<p>Acunetix 360 identified a Blind SQL Injection, which occurs when data input by a user is interpreted as an SQL command rather than as normal data by the backend database.</p>
<p>This is an extremely common vulnerability and its successful exploitation can have critical implications.</p>
<p>Acunetix 360 <strong>confirmed</strong> the vulnerability by executing a test SQL query on the backend database. In these tests, SQL injection was not obvious, but the different responses from the page based on the injection test allowed us to identify and confirm the SQL injection.</p>]]></description>
<impact><![CDATA[<div>Depending on the backend database, the database connection settings, and the operating system, an attacker can mount one or more of the following attacks successfully:
<ul>
<li>Reading, updating and deleting arbitrary data or tables from the database</li>
<li>Executing commands on the underlying operating system</li>
</ul>
</div>]]></impact>
<remedial-actions><![CDATA[<div>
<ol>
<li>See the remedy for solution.</li>
<li>If you are not using a database access layer (DAL), consider using one. This will help you centralize the issue. You can also use ORM (<em>object relational mapping</em>). Most of the ORM systems use only parameterized queries and this can solve the whole SQL injection problem.</li>
<li>Locate the all dynamically generated SQL queries and convert them to parameterized queries. <em>(If you decide to use a DAL/ORM, change all legacy code to use these new libraries.)</em></li>
<li>Use your weblogs and application logs to see if there were any previous but undetected attacks to this resource.</li>
</ol>
</div>]]></remedial-actions>
<exploitation-skills><![CDATA[<div>There are numerous freely available tools to exploit SQL injection vulnerabilities. This is a complex area with many dependencies; however, it should be noted that the numerous resources available in this area have raised both attacker awareness of the issues and their ability to discover and leverage them. SQL injection is one of the most common web application vulnerabilities.</div>]]></exploitation-skills>
<remedial-procedure><![CDATA[<div>A robust method for mitigating the threat of SQL injection-based vulnerabilities is to use parameterized queries (<em>prepared statements</em>). Almost all modern languages provide built-in libraries for this. Wherever possible, do not create dynamic SQL queries or SQL queries with string concatenation.</div>]]></remedial-procedure>
<remedy-references><![CDATA[<div><ul><li><a target='_blank' href='https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet'><i class='icon-external-link'></i>SQL injection Prevention Cheat Sheet</a></li><li><a target='_blank' href='http://bobby-tables.com'><i class='icon-external-link'></i>A guide to preventing SQL injection</a></li></ul></div>]]></remedy-references>
<external-references><![CDATA[<div><ul><li><a target='_blank' href='https://link1.com'><i class='icon-external-link'></i>Link 1</a></li><li><a target='_blank' href='https://link2.com'><i class='icon-external-link'></i>Link 2</a></li></ul></div>]]></external-references>
<proof-of-concept></proof-of-concept>
</vulnerability>
<vulnerabilities>
</acunetix-360>
46 changes: 46 additions & 0 deletions spec/upload_acunetix_360_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'
require 'ostruct'
require 'byebug'
module Dradis::Plugins
describe 'Acunetix upload plugin' do
before(:each) do
templates_dir = File.expand_path('../../templates', __FILE__)
expect_any_instance_of(Dradis::Plugins::TemplateService)
.to receive(:default_templates_dir).and_return(templates_dir)

plugin = Dradis::Plugins::Acunetix

@content_service = Dradis::Plugins::ContentService::Base.new(plugin: plugin)

allow(@content_service).to receive(:create_note) do |args|
OpenStruct.new(args)
end
allow(@content_service).to receive(:create_node) do |args|
OpenStruct.new(args)
end
allow(@content_service).to receive(:create_issue) do |args|
OpenStruct.new(args)
end
allow(@content_service).to receive(:create_evidence) do |args|
OpenStruct.new(args)
end

@importer = plugin::Importer.new(
content_service: @content_service
)
end

describe "Source HTML parsing" do
it "parses links in <external-references> tag" do

expect(@content_service).to receive(:create_issue) do |args|
expect(args[:text]).to include('"Link 1":https://link1.com')
expect(args[:text]).to include('"Link 2":https://link2.com')
OpenStruct.new(args)
end.once

@importer.import(file: 'spec/fixtures/files/acunetix_360.xml')
end
end
end
end
9 changes: 9 additions & 0 deletions templates/vulnerability_360.template
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@

#[CVSS3Environmental]#
%vulnerability_360.cvss31_environmental%

#[Remedial Actions]#
%vulnerability_360.remedial_actions%

#[Remedial Procedure]#
%vulnerability_360.remedial_procedure%

#[References]#
%vulnerability_360.external_references%