metasploit-framework/modules/auxiliary/scanner/http/title.rb

104 lines
3.7 KiB
Ruby
Raw Normal View History

2015-05-11 16:29:22 +00:00
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Auxiliary
2015-05-11 16:29:22 +00:00
# Exploit mixins should be called first
include Msf::Exploit::Remote::HttpClient
# Scanner mixin should be near last
include Msf::Auxiliary::Scanner
def initialize
super(
2015-05-12 09:47:49 +00:00
'Name' => 'HTTP HTML Title Tag Content Grabber',
'Description' => %q{
Generates a GET request to the provided webservers and returns the server header,
HTML title attribute and location header (if set). This is useful for rapidly identifying
interesting web applications en mass.
},
'Author' => 'Stuart Morgan <stuart.morgan[at]mwrinfosecurity.com>',
2015-05-11 16:29:22 +00:00
'License' => MSF_LICENSE,
)
register_options(
[
OptBool.new('STORE_NOTES', [ true, 'Store the captured information in notes. Use "notes -t http.title" to view', true ]),
2015-05-12 16:18:21 +00:00
OptBool.new('SHOW_TITLES', [ true, 'Show the titles on the console as they are grabbed', true ]),
OptString.new('TARGETURI', [true, 'The base path', '/'])
2015-05-11 17:14:37 +00:00
], self.class)
2015-05-11 16:29:22 +00:00
deregister_options('VHOST')
end
2015-05-11 17:48:55 +00:00
def run
if !datastore['STORE_NOTES'] && !datastore['SHOW_TITLES']
print_error("Notes storage is false and titles are not being shown on the console. There isn't much point in running this module.")
2015-05-11 17:48:55 +00:00
else
2015-05-11 17:50:03 +00:00
super
2015-05-11 17:48:55 +00:00
end
end
2015-05-11 16:29:22 +00:00
def run_host(target_host)
begin
# Send a normal GET request
2015-05-11 18:48:12 +00:00
res = send_request_cgi(
2015-05-12 16:18:21 +00:00
'uri' => normalize_uri(target_uri.path)
2015-05-11 18:48:12 +00:00
)
2015-05-11 16:29:22 +00:00
# If no response, quit now
if res.nil?
vprint_error("[#{target_host}:#{rport}] No response")
return
end
# Retrieve the headers to capture the Location and Server header
# Note that they are case-insensitive but stored in a hash
2015-05-11 16:29:22 +00:00
server_header = nil
location_header = nil
2015-05-11 17:14:37 +00:00
if !res.headers.nil?
res.headers.each do |key, val|
location_header = val if key.downcase == 'location'
server_header = val if key.downcase == 'server'
2015-05-11 16:29:22 +00:00
end
else
vprint_error("[#{target_host}:#{rport}] No HTTP headers")
end
# If the body is blank, just stop now as there is no chance of a title
if res.body.nil?
vprint_error("[#{target_host}:#{rport}] No webpage body")
return
2015-05-11 16:29:22 +00:00
end
# Very basic, just match the first title tag we come to. If the match fails,
# there is no chance that we will have a title
rx = %r{<title>[\n\t\s]*(?<title>.+?)[\s\n\t]*</title>}im.match(res.body.to_s)
unless rx
vprint_error("[#{target_host}:#{rport}] No webpage title")
return
end
# Last bit of logic to capture the title
rx[:title].strip!
if rx[:title] != ''
rx_title = Rex::Text.html_decode(rx[:title])
if datastore['SHOW_TITLES']
print_status("[#{target_host}:#{rport}] [C:#{res.code}] [R:#{location_header}] [S:#{server_header}] #{rx_title}")
end
if datastore['STORE_NOTES']
notedata = { code: res.code, port: rport, server: server_header, title: rx_title, redirect: location_header, uri: datastore['TARGETURI'] }
report_note(host: target_host, port: rport, type: "http.title", data: notedata, update: :unique_data)
2015-05-11 17:14:37 +00:00
end
2015-05-11 16:29:22 +00:00
else
vprint_error("[#{target_host}:#{rport}] No webpage title")
2015-05-11 16:29:22 +00:00
end
end
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
rescue ::Timeout::Error, ::Errno::EPIPE
end
end