7
7
require 'cgi'
8
8
9
9
class Metasploit3 < Msf ::Auxiliary
10
-
11
10
# Exploit mixins should be called first
12
11
include Msf ::Exploit ::Remote ::HttpClient
13
12
# Scanner mixin should be near last
@@ -25,53 +24,46 @@ def initialize
25
24
[
26
25
OptBool . new ( 'STORE_NOTES' , [ true , 'Store the captured information in notes. Use "notes -t http.title" to view' , true ] ) ,
27
26
OptBool . new ( 'SHOW_ERRORS' , [ true , 'Show error messages relating to grabbing titles on the console' , true ] ) ,
28
- OptBool . new ( 'SHOW_TITLES' , [ true , 'Show the titles on the console as they are grabbed' , true ] ) ,
29
- ] , self . class )
27
+ OptBool . new ( 'SHOW_TITLES' , [ true , 'Show the titles on the console as they are grabbed' , true ] )
28
+ ] , self . class )
30
29
31
30
deregister_options ( 'VHOST' )
32
31
end
33
32
34
33
def run_host ( target_host )
35
34
begin
36
- res = send_request_cgi ( {
37
- 'uri' => '/' ,
38
- 'method' => 'GET' ,
39
- } )
35
+ res = send_request_cgi ( 'uri' => '/' ,
36
+ 'method' => 'GET' )
40
37
41
38
if res . nil?
42
39
print_error ( "No response from #{ target_host } :#{ rport } " ) if datastore [ 'SHOW_ERRORS' ] == true
43
- else
40
+ else
44
41
server_header = nil
45
42
location_header = nil
46
- if not res . headers . nil?
47
- res . headers . each do |key , val |
48
- location_header = val if key . downcase == 'location'
49
- server_header = val if key . downcase == 'server'
43
+ if ! res . headers . nil?
44
+ res . headers . each do |key , val |
45
+ location_header = val if key . downcase == 'location'
46
+ server_header = val if key . downcase == 'server'
50
47
end
51
48
else
52
49
print_error ( "No headers from #{ target_host } :#{ rport } " ) if datastore [ 'SHOW_ERRORS' ] == true
53
50
end
54
51
55
- if not res . body . nil?
56
- # Very basic, just match the first title tag we come to.
57
- rx = /<title>[\n \t \s ]*(?<title>.+?)[\s \n \t ]*<\/ title>/im . match ( res . body . to_s )
58
- if rx
59
- rx [ :title ] . strip!
60
- if not rx [ :title ] == ''
61
- rx_title = CGI . unescapeHTML ( rx [ :title ] )
62
- print_status ( "[#{ target_host } :#{ rport } ] [C:#{ res . code } ] [R:#{ location_header } ] [S:#{ server_header } ] #{ rx_title } " ) if datastore [ 'SHOW_TITLES' ] == true
63
- if datastore [ 'STORE_NOTES' ] == true then
64
- notedata = { code : res . code , port : rport , server : server_header , title : rx_title , redirect : location_header }
65
- report_note ( :host => target_host , :type => "http.title" , :data => notedata )
66
- end
67
- else
68
- print_error ( "No webpage title from #{ target_host } :#{ rport } " ) if datastore [ 'SHOW_ERRORS' ] == true
69
- end
70
- else
71
- print_error ( "No webpage title from #{ target_host } :#{ rport } " ) if datastore [ 'SHOW_ERRORS' ] == true
52
+ if !res . body . nil?
53
+ # Very basic, just match the first title tag we come to.
54
+ rx = %r{<title>[\n \t \s ]*(?<title>.+?)[\s \n \t ]*</title>}im . match ( res . body . to_s . strip )
55
+ if rx && rx [ :title ] != ''
56
+ rx_title = CGI . unescapeHTML ( rx [ :title ] )
57
+ print_status ( "[#{ target_host } :#{ rport } ] [C:#{ res . code } ] [R:#{ location_header } ] [S:#{ server_header } ] #{ rx_title } " ) if datastore [ 'SHOW_TITLES' ] == true
58
+ if datastore [ 'STORE_NOTES' ] == true
59
+ notedata = { code : res . code , port : rport , server : server_header , title : rx_title , redirect : location_header }
60
+ report_note ( host : target_host , type : "http.title" , data : notedata )
72
61
end
62
+ else
63
+ print_error ( "No webpage title from #{ target_host } :#{ rport } " ) if datastore [ 'SHOW_ERRORS' ] == true
64
+ end
73
65
else
74
- print_error ( "No webpage body from #{ target_host } :#{ rport } " ) if datastore [ 'SHOW_ERRORS' ] == true
66
+ print_error ( "No webpage body from #{ target_host } :#{ rport } " ) if datastore [ 'SHOW_ERRORS' ] == true
75
67
end
76
68
end
77
69
0 commit comments