Skip to content

Commit 0063933

Browse files
committed
Add conditions to check healthy shodan results
1 parent 3281781 commit 0063933

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

modules/auxiliary/gather/shodan_search.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def shodan_query(query, apikey, page)
6161
request = Net::HTTP::Get.new(uri.request_uri)
6262
res = http.request(request)
6363

64+
if res and res.body =~ /<title>401 Unauthorized<\/title>/
65+
fail_with(Failure::BadConfig, '401 Unauthorized. Your SHODAN_APIKEY is invalid')
66+
end
67+
6468
# Check if we can resolve host, got a response,
6569
# then parse the JSON, and return it
6670
if res
@@ -104,7 +108,7 @@ def run
104108
results = []
105109
results[page] = shodan_query(query, apikey, page)
106110

107-
if results[page]['total'] == 0
111+
if results[page]['total'].nil? || results[page]['total'] == 0
108112
print_error('No Results Found!')
109113
end
110114

0 commit comments

Comments
 (0)