Skip to content

Commit 62d6746

Browse files
committed
Updated code style as per @hmoore-r7's instructions
1 parent b8f7c80 commit 62d6746

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

modules/auxiliary/scanner/http/title.rb

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ def run
4040

4141
def run_host(target_host)
4242
begin
43-
res = send_request_cgi('uri' => '/',
44-
'method' => 'GET')
43+
# Send a normal GET request
44+
res = send_request_cgi('uri' => '/',
45+
'method' => 'GET')
4546

46-
if res.nil?
47-
print_error("No response from #{target_host}:#{rport}") if datastore['SHOW_ERRORS'] == true
48-
else
47+
# If no response, quit now
48+
if res.nil?
49+
print_error("[#{target_host}:#{rport}] No response") if datastore['SHOW_ERRORS'] == true
50+
return
51+
end
52+
53+
# Retrieve the headers to capture the Location and Server header
54+
# Note that they are case-insensitive but stored in a hash
4955
server_header = nil
5056
location_header = nil
5157
if !res.headers.nil?
@@ -54,34 +60,38 @@ def run_host(target_host)
5460
server_header = val if key.downcase == 'server'
5561
end
5662
else
57-
print_error("No headers from #{target_host}:#{rport}") if datastore['SHOW_ERRORS'] == true
63+
print_error("[#{target_host}:#{rport}] No HTTP headers") if datastore['SHOW_ERRORS'] == true
64+
end
65+
66+
# If the body is blank, just stop now as there is no chance of a title
67+
if res.body.nil?
68+
print_error("[#{target_host}:#{rport}] No webpage body") if datastore['SHOW_ERRORS'] == true
69+
return
5870
end
5971

60-
if !res.body.nil?
61-
# Very basic, just match the first title tag we come to.
62-
rx = %r{<title>[\n\t\s]*(?<title>.+?)[\s\n\t]*</title>}im.match(res.body.to_s)
63-
if rx
64-
rx[:title].strip!
65-
if rx[:title] != ''
66-
rx_title = CGI.unescapeHTML(rx[:title])
67-
print_status("[#{target_host}:#{rport}] [C:#{res.code}] [R:#{location_header}] [S:#{server_header}] #{rx_title}") if datastore['SHOW_TITLES'] == true
68-
if datastore['STORE_NOTES'] == true
69-
notedata = { code: res.code, port: rport, server: server_header, title: rx_title, redirect: location_header }
70-
report_note(host: target_host, type: "http.title", data: notedata)
71-
end
72-
else
73-
print_error("No webpage title from #{target_host}:#{rport}") if datastore['SHOW_ERRORS'] == true
74-
end
75-
else
76-
print_error("No webpage title from #{target_host}:#{rport}") if datastore['SHOW_ERRORS'] == true
72+
# Very basic, just match the first title tag we come to. If the match fails,
73+
# there is no chance that we will have a title
74+
rx = %r{<title>[\n\t\s]*(?<title>.+?)[\s\n\t]*</title>}im.match(res.body.to_s)
75+
unless rx
76+
print_error("[#{target_host}:#{rport}] No webpage title") if datastore['SHOW_ERRORS'] == true
77+
return
78+
end
79+
80+
# Last bit of logic to capture the title
81+
rx[:title].strip!
82+
if rx[:title] != ''
83+
rx_title = CGI.unescapeHTML(rx[:title])
84+
print_status("[#{target_host}:#{rport}] [C:#{res.code}] [R:#{location_header}] [S:#{server_header}] #{rx_title}") if datastore['SHOW_TITLES'] == true
85+
if datastore['STORE_NOTES'] == true
86+
notedata = { code: res.code, port: rport, server: server_header, title: rx_title, redirect: location_header }
87+
report_note(host: target_host, type: "http.title", data: notedata)
7788
end
7889
else
79-
print_error("No webpage body from #{target_host}:#{rport}") if datastore['SHOW_ERRORS'] == true
90+
print_error("[#{target_host}:#{rport}] No webpage title") if datastore['SHOW_ERRORS'] == true
8091
end
8192
end
8293

8394
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
8495
rescue ::Timeout::Error, ::Errno::EPIPE
85-
end
8696
end
8797
end

0 commit comments

Comments
 (0)