@@ -40,12 +40,18 @@ def run
40
40
41
41
def run_host ( target_host )
42
42
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' )
45
46
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
49
55
server_header = nil
50
56
location_header = nil
51
57
if !res . headers . nil?
@@ -54,34 +60,38 @@ def run_host(target_host)
54
60
server_header = val if key . downcase == 'server'
55
61
end
56
62
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
58
70
end
59
71
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 )
77
88
end
78
89
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
80
91
end
81
92
end
82
93
83
94
rescue ::Rex ::ConnectionRefused , ::Rex ::HostUnreachable , ::Rex ::ConnectionTimeout
84
95
rescue ::Timeout ::Error , ::Errno ::EPIPE
85
- end
86
96
end
87
97
end
0 commit comments