Skip to content

Commit fc97266

Browse files
committed
Handle errors more carefully
1 parent d3ebb8a commit fc97266

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

modules/auxiliary/scanner/rsync/modules_list.rb

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,16 @@ def rsync_parse_lines(response_data)
142142
end
143143

144144
def run_host(ip)
145-
connect
146-
version, motd = rsync_negotiate
147-
unless version
148-
vprint_error("#{peer} - does not appear to be rsync")
145+
begin
146+
connect
147+
version, motd = rsync_negotiate
148+
unless version
149+
vprint_error("#{peer} - does not appear to be rsync")
150+
disconnect
151+
return
152+
end
153+
rescue => e
154+
vprint_error("#{peer} - error while connecting and negotiating: #{e}")
149155
disconnect
150156
return
151157
end
@@ -161,8 +167,16 @@ def run_host(ip)
161167
)
162168
vprint_good("#{peer} - rsync MOTD: #{motd}") if motd && datastore['SHOW_MOTD']
163169

164-
modules_metadata = rsync_list
165-
disconnect
170+
modules_metadata = {}
171+
begin
172+
modules_metadata = rsync_list
173+
rescue => e
174+
vprint_error("#{peer} -- error while listing modules: #{e}")
175+
return
176+
ensure
177+
disconnect
178+
end
179+
166180
if modules_metadata.empty?
167181
print_status("#{peer} - rsync #{version}: no modules found")
168182
else
@@ -173,10 +187,15 @@ def run_host(ip)
173187
if datastore['TEST_AUTHENTICATION']
174188
table_columns << 'Authentication?'
175189
modules_metadata.each do |module_metadata|
176-
connect
177-
rsync_negotiate
178-
module_metadata[:authentication?] = get_rsync_auth_state(module_metadata[:name])
179-
disconnect
190+
begin
191+
connect
192+
rsync_negotiate
193+
module_metadata[:authentication?] = get_rsync_auth_state(module_metadata[:name])
194+
rescue => e
195+
vprint_error("#{peer} - error while testing authentication on #{module_metadata[:name]}: #{e}")
196+
ensure
197+
disconnect
198+
end
180199
end
181200
end
182201

0 commit comments

Comments
 (0)