Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
host = self.shodanApi.host(IP)
if len(host) != 0:
# Print host info
print('IP: %s' % host.get('ip_str'))
print('Country: %s' % host.get('country_name','Unknown'))
print('City: %s' % host.get('city','Unknown'))
print('Latitude: %s' % host.get('latitude'))
print('Longitude: %s' % host.get('longitude'))
print('Hostnames: %s' % host.get('hostnames'))
for i in host['data']:
print('Port: %s' % i['port'])
return host
except shodan.APIError as e:
print(' Error: %s' % e)
return host
done = 3
print "[+] Possible username: "+backgroundColor.OKGREEN+line+backgroundColor.ENDC
elif done == 3:
done = 4
print "[+] Possible password: "+backgroundColor.OKGREEN+line+backgroundColor.ENDC
elif done == 4:
done = 0
print "[+] Following line.. \n\n"+backgroundColor.OKGREEN+line+backgroundColor.ENDC
else:
pass
signal.pause()
except:
print (backgroundColor.FAIL+"[-] Victim isnt vulnerable for a memory leak, exiting.."+backgroundColor.ENDC)
print(backgroundColor.OKGREEN + "[+] Done!" + backgroundColor.ENDC)
return True
except shodan.APIError as e:
print(backgroundColor.FAIL + "[-] Error: %s" % (e) + backgroundColor.ENDC)
sys.exit(0)
except urllib.error.URLError as e:
if e.code == 404:
print ('\n[!] Data not found. Possible reasons:')
print ('[!] Target e-mail is mistyped or doesn\'t exist.\n[!] There aren\'t any data breaches for your target.\n[!] There aren\'t any data pastes results for your target.')
elif e.code == 403:
print ('\n[!] Bad request. Possible reasons:')
print ('[!] Your Pipl API key is mistyped.\n[!] Your OpenCnam Account SID or Auth Token are mistyped.')
else:
print (str(e))
except urllib.error.HTTPError as e:
print (tr(e) + '\n\nPossible reasons:\n[!] Bad Internet connection.\n[!] Resource doesn\'t exist')
except shodan.APIError as e:
print ('[!] Shodan: ' + str(e))
except phonenumbers.phonenumberutil.NumberParseException as e:
print (e)
except KeyboardInterrupt:
sys.exit()
def alert_enable_trigger(alert_id, trigger):
"""Enable a trigger for the alert"""
key = get_api_key()
# Get the list
api = shodan.Shodan(key)
try:
api.enable_alert_trigger(alert_id, trigger)
except shodan.APIError as e:
raise click.ClickException(e.value)
click.secho('Successfully enabled the trigger: {}'.format(trigger), fg='green')
def shodan_query(query, device,page):
print("----------------" + Fore.LIGHTRED_EX + 'Shodan ' + device + Fore.RESET + "----------------")
try:
api = shodan.Shodan(SHODAN_API_KEY)
result = api.search(query, page)
except shodan.APIError as e:
print(Fore.RED + e.value + Fore.RESET)
return False
ics_results = {'matches':[]}
if len(result['matches']) > 0:
print('Found ' + str(len(result['matches'])) + " results")
if device == "ics":
for match in result['matches']:
if "tags" in match:
if 'ics' in match['tags']:
print("IP: " + Fore.GREEN + match['ip_str'] + Fore.RESET)
print("Coordinates: " + Fore.BLUE + str(match['location']['latitude']) + "," + Fore.BLUE + str(
match['location']['longitude']) + Fore.RESET)
ics_results['matches'].append(match)
for item in host['data']:
hostinfo.append([item['ip_str'], item['org'], str(item['data'].replace(',',' ').strip('\t\n\r')), item['port']])
print("""
Port: %s
Banner: %s
""" % (item['port'], item['data']))
title = "shodanOutput-" + searchHost + ".csv"
with open(title,"w") as csvfile:
header = ["Host IP", "FQDN", "Banner", "Ports"]
writer = csv.writer(csvfile, delimiter=",")
writer.writerow(header)
for i in range(len(hostinfo)):
writer.writerow(hostinfo[i])
print(title + " created in script directory")
except shodan.APIError as e:
print("Error: %s" % e)
print("""
IP: {}
Organization: {}
Operating System: {}
""".format(search['ip_str'], search.get('org', 'n/a'), search.get('os', 'n/a')))
# Print all banners
for item in search['data']:
print("""
Port: {}
Banner: {}
""".format(item['port'], item['data']))
oops = [str(search['ip_str'], "\n", str(search['data'], "\n"))]
Albert_api.write_file(''.join(oops))
return target
except shodan.APIError as e:
os.system('cls')
print('[✘] Shodan Scanner Failure: {} [✘]\n\n'.format(e))
option = input('[*] Shieeeet you wanna chagne that API Key? : ').lower()
if option == ('y'):
file = open('../../../api_keys/api.py', 'w')
SHODAN_API_KEY = input('[*] Hey! Hey! Hey! Enter A Valid Shodan.io API Key: ')
oppsie = ["apikey= ", "\"", str(SHODAN_API_KEY), "\""]
file.write(''.join(oppsie))
print('[~] File Dropped Nigga: ./api.py')
file.close()
return target
def scan_protocols():
"""List the protocols that you can scan with using Shodan."""
key = get_api_key()
api = shodan.Shodan(key)
try:
protocols = api.protocols()
for name, description in iter(protocols.items()):
click.echo(click.style('{0:<30}'.format(name), fg='cyan') + description)
except shodan.APIError as e:
raise click.ClickException(e.value)
"Checking IoT device: {0} if under Shodan range".format(self.ip),
logtype="info"
)
try:
results = self.shodan_obj.host(self.ip)
if results:
self.logger.log(
"IP: {0} under Shodan range (risk)".format(self.ip),
logtype="warning"
)
else:
self.logger.log(
"IP: {0} not under Shodan range (safe)".format(self.ip),
logtype="info"
)
except shodan.APIError:
self.logger.log(
"IP: {0} not under Shodan range (safe)".format(self.ip),
logtype="info"
)
else:
self.logger.log(
"Configuration parameters not set.",
logtype="error"
)
def run_shodan_lookup(self, target):
"""Collect information Shodan has for target IP address. This uses the Shodan host lookup
instead of search and returns the target results dictionary from Shodan.
A Shodan API key is required.
"""
if self.shodan_api is None:
pass
else:
# click.secho("[+] Performing Shodan IP lookup for {}.".format(target), fg="green")
try:
target_results = self.shodan_api.host(target)
return target_results
except shodan.APIError as error:
click.secho("\n[!] No Shodan data for {}!".format(target), fg=+"red")
click.secho("L.. Details: {}".format(error), fg="red")