Created
August 18, 2020 19:19
-
-
Save achillean/442d56fda13de85b4870a89dab1a85ff to your computer and use it in GitHub Desktop.
Subdomain Discovery in Crystal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "shodan" | |
module Subs | |
VERSION = "0.1.0" | |
# Basic input validation | |
if ARGV.size != 2 | |
puts "Usage: subs <api key> <domain>" | |
exit | |
end | |
# Setup the API wrapper | |
client = Shodan::Client.new(ARGV[0]) | |
begin | |
# Grab the list of subdomains | |
domain_info = client.domain(ARGV[1]) | |
if domain_info.data | |
# Create a unique list of subdomains | |
# We need to tell the compiler that this value will never be nil | |
info = domain_info.data.not_nil!.uniq { |item| item.subdomain } | |
# Print the information | |
info.each do |item| | |
if item.subdomain != nil && item.subdomain != "" | |
puts "#{item.subdomain}.#{ARGV[1]}" | |
end | |
end | |
else | |
puts "No data available" | |
end | |
rescue ex: Shodan::ShodanClientException | |
puts ex.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment