Skip to content

Commit

Permalink
Updated exception handling around censys calls
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbharath committed Feb 12, 2018
1 parent d3b9394 commit ead5c3a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions censys_enumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
else:
print("[!] No environmental variable with name CENSYS_API_ID. \
Please add you Censys API ID to env variables")
sys.exit(1)
if "CENSYS_API_SECRET" in os.environ:
CENSYS_API_SECRET = os.environ['CENSYS_API_SECRET'] # Add CENSYS_API_SECRET as env variable
else:
print("[!] No environmental variable with name CENSYS_API_SECRET. \
Please add you Censys API Secret to env variables")
Please add you Censys API Secret 1to env variables")
sys.exit(1)

try:
import censys.certificates
Expand Down Expand Up @@ -84,7 +86,11 @@ def get_subdomains(domain, certificates):
def get_emails(domain, certificates):
del emails_found[:]
logging.info("[+] Extracting emails belonging to {} from SSL/TLS certificates".format(domain.rstrip()))
certificate_query = 'parsed.names: {}'.format(domain)
try:
certificate_query = 'parsed.names: {}'.format(domain)
except CensysException:
logging.info('\033[93m[!] Error while fetching results from Censys.\n\033[1;m')
sys.exit(1)
try:
certificates_search_results = certificates.search(certificate_query, fields=['parsed.subject.email_address'])
except KeyError:
Expand Down

0 comments on commit ead5c3a

Please sign in to comment.