Skip to content

Commit f6bc693

Browse files
author
Brent Cook
committed
Land rapid7#4767: @wchen-r7 fixes DNS lookups for Shodan search module
2 parents 7b7a634 + fd441d2 commit f6bc693

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

modules/auxiliary/gather/shodan_search.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,22 @@ def save_output(data)
8484
end
8585

8686
# Check to see if api.shodan.io resolves properly
87-
def shodan_rhost
88-
@res = Net::DNS::Resolver.new
89-
dns_query = @res.query('api.shodan.io', 'A')
90-
if dns_query.answer.length == 0
91-
print_error('Could not resolve api.shodan.io')
92-
raise ::Rex::ConnectError('api.shodan.io', '443')
87+
def shodan_resolvable?
88+
begin
89+
Rex::Socket.resolv_to_dotted("api.shodan.io")
90+
rescue RuntimeError, SocketError
91+
return false
9392
end
94-
dns_query.answer[0].to_s.split(/[\s,]+/)[4]
93+
94+
true
9595
end
9696

9797
def run
9898
# check to ensure api.shodan.io is resolvable
99-
shodan_rhost
99+
unless shodan_resolvable?
100+
print_error("Unable to resolve api.shodan.io")
101+
return
102+
end
100103

101104
# create our Shodan request parameters
102105
query = datastore['QUERY']

0 commit comments

Comments
 (0)