Skip to content

Commit 202c5e0

Browse files
committed
Land rapid7#5333, HTML Title Grabber
2 parents b2ef4be + faec584 commit 202c5e0

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 Metasploit3 < Msf::Auxiliary
9+
# Exploit mixins should be called first
10+
include Msf::Exploit::Remote::HttpClient
11+
# Scanner mixin should be near last
12+
include Msf::Auxiliary::Scanner
13+
14+
def initialize
15+
super(
16+
'Name' => 'HTTP HTML Title Tag Content Grabber',
17+
'Description' => %q{
18+
Generates a GET request to the webservers provided and returns the server header,
19+
HTML title attribute and location header (if set). Useful for rapidly identifying
20+
interesting web applications en mass.
21+
},
22+
'Author' => 'Stuart Morgan <stuart.morgan[at]mwrinfosecurity.com>',
23+
'License' => MSF_LICENSE,
24+
)
25+
26+
register_options(
27+
[
28+
OptBool.new('STORE_NOTES', [ true, 'Store the captured information in notes. Use "notes -t http.title" to view', true ]),
29+
OptBool.new('SHOW_ERRORS', [ true, 'Show error messages relating to grabbing titles on the console', true ]),
30+
OptBool.new('SHOW_TITLES', [ true, 'Show the titles on the console as they are grabbed', true ]),
31+
OptString.new('TARGETURI', [true, 'The base path', '/'])
32+
], self.class)
33+
34+
deregister_options('VHOST')
35+
end
36+
37+
def run
38+
if datastore['STORE_NOTES'] == false && datastore['SHOW_ERRORS'] == false && datastore['SHOW_TITLES'] == false
39+
print_error("Notes storage is false, errors have been turned off and titles are not being shown on the console. There isn't much point in running this module.")
40+
else
41+
super
42+
end
43+
end
44+
45+
def run_host(target_host)
46+
begin
47+
# Send a normal GET request
48+
res = send_request_cgi(
49+
'uri' => normalize_uri(target_uri.path)
50+
)
51+
52+
# If no response, quit now
53+
if res.nil?
54+
print_error("[#{target_host}:#{rport}] No response") if datastore['SHOW_ERRORS'] == true
55+
return
56+
end
57+
58+
# Retrieve the headers to capture the Location and Server header
59+
# Note that they are case-insensitive but stored in a hash
60+
server_header = nil
61+
location_header = nil
62+
if !res.headers.nil?
63+
res.headers.each do |key, val|
64+
location_header = val if key.downcase == 'location'
65+
server_header = val if key.downcase == 'server'
66+
end
67+
else
68+
print_error("[#{target_host}:#{rport}] No HTTP headers") if datastore['SHOW_ERRORS'] == true
69+
end
70+
71+
# If the body is blank, just stop now as there is no chance of a title
72+
if res.body.nil?
73+
print_error("[#{target_host}:#{rport}] No webpage body") if datastore['SHOW_ERRORS'] == true
74+
return
75+
end
76+
77+
# Very basic, just match the first title tag we come to. If the match fails,
78+
# there is no chance that we will have a title
79+
rx = %r{<title>[\n\t\s]*(?<title>.+?)[\s\n\t]*</title>}im.match(res.body.to_s)
80+
unless rx
81+
print_error("[#{target_host}:#{rport}] No webpage title") if datastore['SHOW_ERRORS'] == true
82+
return
83+
end
84+
85+
# Last bit of logic to capture the title
86+
rx[:title].strip!
87+
if rx[:title] != ''
88+
rx_title = Rex::Text.html_decode(rx[:title])
89+
print_status("[#{target_host}:#{rport}] [C:#{res.code}] [R:#{location_header}] [S:#{server_header}] #{rx_title}") if datastore['SHOW_TITLES'] == true
90+
if datastore['STORE_NOTES'] == true
91+
notedata = { code: res.code, port: rport, server: server_header, title: rx_title, redirect: location_header }
92+
report_note(host: target_host, type: "http.title", data: notedata)
93+
end
94+
else
95+
print_error("[#{target_host}:#{rport}] No webpage title") if datastore['SHOW_ERRORS'] == true
96+
end
97+
end
98+
99+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
100+
rescue ::Timeout::Error, ::Errno::EPIPE
101+
end
102+
end

0 commit comments

Comments
 (0)