-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathcensys_search.py
46 lines (40 loc) · 1.54 KB
/
censys_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import print_function
from urllib.parse import urlsplit
import censys.certificates
import configparser
import censys.ipv4
import re
config = configparser.ConfigParser()
config.read("api.conf")
TOKEN = config.get('censys', 'token')
UID = config.get('censys', 'uid')
def split_url(url):
if re.match(r'http(s?)\:', url):
parsed = urlsplit(url)
return parsed.netloc
else:
return url
def censys_search(title):
try:
api = censys.ipv4.CensysIPv4(api_id=UID, api_secret=TOKEN)
query = api.search('80.http.get.title: "{0}"'.format(title))
title_result = set([host['ip'] for host in query])
if title_result:
return title_result
except:
print("[-] We got an error here, maybe with your credentials!")
exit(1)
def censys_search_certs(host):
try:
certificates = censys.certificates.CensysCertificates(api_id=UID, api_secret=TOKEN)
cert_query = certificates.search("parsed.names: {0} AND tags.raw: trusted AND NOT parsed.names: cloudflaressl.com".format(host))
result = set([cert['parsed.fingerprint_sha256'] for cert in cert_query])
hosts_query = censys.ipv4.CensysIPv4(api_id=UID, api_secret=TOKEN)
hosts = ' OR '.join(result)
if hosts:
searching = hosts_query.search(hosts)
host_result = set([ search_result['ip'] for search_result in searching ])
return host_result
except:
print("[-] We got an error here, maybe with your credentials!")
exit(1)