From 4c835545a3c618da33cb316db1a0c7b2f4b29372 Mon Sep 17 00:00:00 2001 From: Spencer McIntyre Date: Mon, 25 Mar 2024 14:44:49 -0400 Subject: [PATCH] Ignore the hosts file if it can't be loaded --- lib/rex/proto/dns/resolver.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/rex/proto/dns/resolver.rb b/lib/rex/proto/dns/resolver.rb index 9b79712df2ad..6aa1345e6ace 100644 --- a/lib/rex/proto/dns/resolver.rb +++ b/lib/rex/proto/dns/resolver.rb @@ -84,8 +84,15 @@ def initialize(config = {}) raise ResolverArgumentError, "Option #{key} not valid" end end + self.static_hostnames = StaticHostnames.new(hostnames: static_hosts) - self.static_hostnames.parse_hosts_file + begin + self.static_hostnames.parse_hosts_file + rescue StandardError => e + @logger.error 'Failed to parse the hosts file, ignoring it' + # if the hosts file is corrupted, just use a default instance with any specified hostnames + self.static_hostnames = StaticHostnames.new(hostnames: static_hosts) + end end # # Provides current proxy setting if configured