@@ -42,13 +42,15 @@ def types
42
42
STATUS_DOWN = 'Down'
43
43
STATUS_UNSUPPORTED = 'Unsupported'
44
44
45
- sort = 0
46
- filter = 'All'
47
- filters = [ 'all' , 'exploit' , 'payload' , 'post' , 'nop' , 'encoder' , 'auxiliary' ]
48
- type = 'ALL'
49
- match = nil
50
- check = false
51
- save = nil
45
+ sort = 0
46
+ filter = 'All'
47
+ filters = [ 'all' , 'exploit' , 'payload' , 'post' , 'nop' , 'encoder' , 'auxiliary' ]
48
+ type = 'ALL'
49
+ match = nil
50
+ check = false
51
+ save = nil
52
+ http_timeout = 20
53
+ $verbose = false
52
54
53
55
opts = Rex ::Parser ::Arguments . new (
54
56
"-h" => [ false , "Help menu." ] ,
@@ -58,7 +60,9 @@ def types
58
60
"-f" => [ true , "Filter based on Module Type [All,Exploit,Payload,Post,NOP,Encoder,Auxiliary] (Default = ALL)." ] ,
59
61
"-t" => [ true , "Type of Reference to sort by #{ types . keys } " ] ,
60
62
"-x" => [ true , "String or RegEx to try and match against the Reference Field" ] ,
61
- "-o" => [ true , "Save the results to a file" ]
63
+ "-o" => [ true , "Save the results to a file" ] ,
64
+ "-i" => [ true , "Set an HTTP timeout" ] ,
65
+ "-v" => [ false , "Verbose" ]
62
66
)
63
67
64
68
flags = [ ]
@@ -95,6 +99,10 @@ def types
95
99
exit
96
100
end
97
101
type = val
102
+ when "-i"
103
+ http_timeout = /^\d +/ === val ? val . to_i : 20
104
+ when "-v"
105
+ $verbose = true
98
106
when "-x"
99
107
flags << "Regex: #{ val } "
100
108
match = Regexp . new ( val )
@@ -112,14 +120,22 @@ def get_ipv4_addr(hostname)
112
120
Rex ::Socket ::getaddresses ( hostname , false ) [ 0 ]
113
121
end
114
122
115
- def is_url_alive? ( uri )
116
- #puts "URI: #{uri}"
123
+ def vprint_debug ( msg = '' )
124
+ print_debug ( msg ) if $verbose
125
+ end
126
+
127
+ def print_debug ( msg = '' )
128
+ $stderr. puts "[*] #{ msg } "
129
+ end
130
+
131
+ def is_url_alive? ( uri , http_timeout )
132
+ print_debug ( "Checking: #{ uri } " )
117
133
118
134
begin
119
135
uri = URI ( uri )
120
136
rhost = get_ipv4_addr ( uri . host )
121
137
rescue SocketError , URI ::InvalidURIError => e
122
- #puts "Return false 1: #{e.message}"
138
+ vprint_debug ( " #{ e . message } in #is_url_alive?" )
123
139
return false
124
140
end
125
141
@@ -133,22 +149,23 @@ def is_url_alive?(uri)
133
149
end
134
150
135
151
begin
136
- cli . connect
152
+ cli . connect ( http_timeout )
137
153
req = cli . request_raw ( 'uri' => path , 'vhost' => vhost )
138
- res = cli . send_recv ( req )
154
+ res = cli . send_recv ( req , http_timeout )
139
155
rescue Errno ::ECONNRESET , Rex ::ConnectionError , Rex ::ConnectionRefused , Rex ::HostUnreachable , Rex ::ConnectionTimeout , Rex ::UnsupportedProtocol , ::Timeout ::Error , Errno ::ETIMEDOUT => e
140
- #puts "Return false 2: #{e.message}"
156
+ vprint_debug ( " #{ e . message } for #{ uri } " )
141
157
return false
142
158
ensure
143
159
cli . close
144
160
end
145
161
146
162
if res . nil? || res . code == 404 || res . body =~ /<title>.*not found<\/ title>/i
147
- #puts "Return false 3: HTTP #{res.code}"
148
- #puts req.to_s
163
+ vprint_debug ( "URI returned a not-found response: #{ uri } " )
149
164
return false
150
165
end
151
166
167
+ vprint_debug ( "Good: #{ uri } " )
168
+
152
169
true
153
170
end
154
171
@@ -200,7 +217,7 @@ def save_results(path, results)
200
217
if check
201
218
if types . has_key? ( ctx_id )
202
219
uri = types [ r . ctx_id . upcase ] . gsub ( /\# {in_ctx_val}/ , r . ctx_val )
203
- if is_url_alive? ( uri )
220
+ if is_url_alive? ( uri , http_timeout )
204
221
status = STATUS_ALIVE
205
222
else
206
223
bad_refs_count += 1
0 commit comments