Skip to content

Commit 0a27a18

Browse files
committed
Committing changes from r7 comments
1 parent 1959f7a commit 0a27a18

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

modules/auxiliary/gather/shodan_search.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def shodan_query(query, apikey, page)
7373

7474
# save output to file
7575
def save_output(data)
76-
f = ::File.open(datastore['OUTFILE'], 'wb')
77-
f.write(data)
78-
f.close
79-
print_status("Save results in #{datastore['OUTFILE']}")
76+
::File.open(datastore['OUTFILE'], 'wb') do |f|
77+
f.write(data)
78+
print_status("Saved results in #{datastore['OUTFILE']}")
79+
end
8080
end
8181

8282
# Check to see if api.shodan.io resolves properly
@@ -141,9 +141,14 @@ def run
141141

142142
# Organize results and put them into the table and database
143143
page = 1
144+
#my_filter = Regexp.new(datastore['FILTER'], true) if datastore['FILTER']
144145
my_filter = datastore['FILTER']
145-
for i in page..tpages
146-
next if results[i].nil? || results[i]['matches'].nil?
146+
print_status("page: #{page}")
147+
print_status("tpages: #{tpages}")
148+
pages = page..tpages
149+
pages.each do |i|
150+
next if results[i].nil? or results[i]['matches'].nil?
151+
print_status("i is: #{i}")
147152
results[i]['matches'].each do |host|
148153

149154
city = host['location']['city'] || 'N/A'
@@ -164,20 +169,21 @@ def run
164169
:info => 'Added from Shodan'
165170
) if datastore['DATABASE']
166171

167-
if ip =~ /#{my_filter}/ ||
168-
city =~ /#{my_filter}/i ||
169-
country =~ /#{my_filter}/i ||
170-
hostname =~ /#{my_filter}/i ||
171-
data =~ /#{my_filter}/i
172-
# Unfortunately we cannot display the banner properly,
173-
# because it messes with our output format
174-
tbl << ["#{ip}:#{port}", city, country, hostname]
172+
if ip =~ /#{my_filter}/ or
173+
city =~ /#{my_filter}/i or
174+
country =~ /#{my_filter}/i or
175+
hostname =~ /#{my_filter}/i or
176+
data =~ /#{my_filter}/i
177+
# Unfortunately we cannot display the banner properly,
178+
# because it messes with our output format
179+
tbl << ["#{ip}:#{port}", city, country, hostname]
175180
end
176181
end
177182
end
178183

179184
# Show data and maybe save it if needed
180-
print_line("\n#{tbl.to_s}")
181-
save_output(tbl.to_s) if not datastore['OUTFILE'].nil?
185+
print_line
186+
print_line("#{tbl}")
187+
save_output(tbl) if not datastore['OUTFILE'].nil?
182188
end
183189
end

0 commit comments

Comments
 (0)