Skip to content

Commit 2305e60

Browse files
committed
Land rapid7#6261, module ref verbose + timeout opts
2 parents 493e476 + 467267b commit 2305e60

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

tools/modules/module_reference.rb

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ def types
4242
STATUS_DOWN = 'Down'
4343
STATUS_UNSUPPORTED = 'Unsupported'
4444

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
5254

5355
opts = Rex::Parser::Arguments.new(
5456
"-h" => [ false, "Help menu." ],
@@ -58,7 +60,9 @@ def types
5860
"-f" => [ true, "Filter based on Module Type [All,Exploit,Payload,Post,NOP,Encoder,Auxiliary] (Default = ALL)."],
5961
"-t" => [ true, "Type of Reference to sort by #{types.keys}"],
6062
"-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"]
6266
)
6367

6468
flags = []
@@ -95,6 +99,10 @@ def types
9599
exit
96100
end
97101
type = val
102+
when "-i"
103+
http_timeout = /^\d+/ === val ? val.to_i : 20
104+
when "-v"
105+
$verbose = true
98106
when "-x"
99107
flags << "Regex: #{val}"
100108
match = Regexp.new(val)
@@ -112,14 +120,22 @@ def get_ipv4_addr(hostname)
112120
Rex::Socket::getaddresses(hostname, false)[0]
113121
end
114122

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}")
117133

118134
begin
119135
uri = URI(uri)
120136
rhost = get_ipv4_addr(uri.host)
121137
rescue SocketError, URI::InvalidURIError => e
122-
#puts "Return false 1: #{e.message}"
138+
vprint_debug("#{e.message} in #is_url_alive?")
123139
return false
124140
end
125141

@@ -133,22 +149,23 @@ def is_url_alive?(uri)
133149
end
134150

135151
begin
136-
cli.connect
152+
cli.connect(http_timeout)
137153
req = cli.request_raw('uri'=>path, 'vhost'=>vhost)
138-
res = cli.send_recv(req)
154+
res = cli.send_recv(req, http_timeout)
139155
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}")
141157
return false
142158
ensure
143159
cli.close
144160
end
145161

146162
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}")
149164
return false
150165
end
151166

167+
vprint_debug("Good: #{uri}")
168+
152169
true
153170
end
154171

@@ -200,7 +217,7 @@ def save_results(path, results)
200217
if check
201218
if types.has_key?(ctx_id)
202219
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)
204221
status = STATUS_ALIVE
205222
else
206223
bad_refs_count += 1

0 commit comments

Comments
 (0)