|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit4 < Msf::Auxiliary |
| 9 | + |
| 10 | + include Msf::Exploit::Remote::HttpClient |
| 11 | + include Msf::Auxiliary::WmapScanServer |
| 12 | + include Msf::Auxiliary::Scanner |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'HTTP Host Header Injection Detection', |
| 17 | + 'Description' => 'Checks if the host is vulnerable to Host header injection', |
| 18 | + 'Author' => |
| 19 | + [ |
| 20 | + 'Jay Turla', # @shipcod3 |
| 21 | + 'Medz Barao' # @godflux |
| 22 | + ], |
| 23 | + 'License' => MSF_LICENSE, |
| 24 | + 'References' => |
| 25 | + [ |
| 26 | + ['URL', 'http://www.skeletonscribe.net/2013/05/practical-http-host-header-attacks.html'] |
| 27 | + ] |
| 28 | + )) |
| 29 | + |
| 30 | + register_options( |
| 31 | + [ |
| 32 | + OptString.new('TARGETHOST', [true, 'The redirector target', 'evil.com']) |
| 33 | + ], self.class) |
| 34 | + end |
| 35 | + |
| 36 | + def run_host(ip) |
| 37 | + begin |
| 38 | + target_host = "#{datastore['TARGETHOST']}" |
| 39 | + res = send_request_raw( |
| 40 | + 'uri' => '/', |
| 41 | + 'method' => 'GET', |
| 42 | + 'headers' => { |
| 43 | + 'Host' => target_host, |
| 44 | + 'X-Forwarded-Host' => target_host |
| 45 | + } |
| 46 | + ) |
| 47 | + |
| 48 | + unless res |
| 49 | + vprint_error("#{peer} did not reply to our request") |
| 50 | + return |
| 51 | + end |
| 52 | + |
| 53 | + if res.headers.include?(target_host) || res.body.include?(target_host) |
| 54 | + print_good("#{peer} is vulnerable to HTTP Host header injection") |
| 55 | + report_vuln( |
| 56 | + host: ip, |
| 57 | + port: rport, |
| 58 | + proto: 'tcp', |
| 59 | + sname: ssl ? 'https' : 'http', |
| 60 | + name: 'HTTP Host header injection', |
| 61 | + refs: self.references |
| 62 | + ) |
| 63 | + else |
| 64 | + vprint_error("#{peer} returned #{res.code} #{res.message}") |
| 65 | + end |
| 66 | + rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout |
| 67 | + rescue ::Timeout::Error, ::Errno::EPIPE |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | +end |
0 commit comments