Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shodan Fixes #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/scripts/shodan.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,49 @@

SHODAN_API_KEY = process.env.SHODAN_API_KEY

api_url = "http://www.shodanhq.com"
api_url = "https://api.shodan.io"

module.exports = (robot) ->
robot.respond /shodan (.*)/i, (msg) ->

if SHODAN_API_KEY?
shodan_term = msg.match[1].toLowerCase()

request_url = api_url + "/api/host?key=#{SHODAN_API_KEY}&ip=#{shodan_term}"
# request_url = api_url + "/api/host?key=#{SHODAN_API_KEY}&ip=#{shodan_term}"
request_url = api_url + "/shodan/host/search?key=#{SHODAN_API_KEY}&query=#{shodan_term}" # &facets={facets}"

robot.http(request_url)
.get() (err, res, body) ->

if res.statusCode is 200
shodan_json = JSON.parse body
shodan_link = "https://www.shodan.io/search?query=#{shodan_term}"

if shodan_json.error
shodan_profile = "No Shodan information found for #{shodan_term}"

else

shodan_profile = """Shodan Result for #{shodan_term}
--------------------------------------------
- IP: #{shodan_json.ip}
- Geo: #{shodan_json.city}, #{shodan_json.region_name}, #{shodan_json.country_name}
if shodan_json.total > 10
msg.send "That's gonna be a bunch of data, you might want to go check it out on Shodan.io"
else

"""
response = "Yeah ok... here's what Shodan knows about #{shodan_term}:"

for host in shodan_json.data
banner_array = host.banner.split "\r\n"
for match in shodan_json.matches
response += "\n- #{match.title} (#{match.ip_str}) ASN: #{match.asn} ISP: #{match.isp} \n"
response += "\t- Hostnames:\n"
for hostname in match.hostnames
response += "\t\t#{hostname}\n"
response += "\t- Domains:\n"
for domain in match.domains
response += "\t\t#{domain}\n"

banner_string = ""
banner_string += " - #{banner_item}\n" for banner_item in banner_array when banner_item != ''
shodan_profile += "\n~ #{host.ip}\n------\n- Hostname: #{host.hostnames.toString()}\n- Organization: #{host.org}\n- Port: #{host.port}\n- Banner: \n#{banner_string}"

msg.send shodan_profile
response += "\nOr you can just go to #{shodan_link}"

msg.send response

else
msg.send "Error: Couldn't access #{api_url}. Error Message: #{err}. Status Code: #{res.statusCode}"

Expand Down