-
Notifications
You must be signed in to change notification settings - Fork 7
/
domain_censys.py
executable file
·79 lines (61 loc) · 2.41 KB
/
domain_censys.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
import sys
import re
import requests
import json
import config as cfg
import time
def censys_search(domain):
pages = float('inf')
page = 1
while page <= pages:
print "Parsed and collected results from page %s" % (str(page))
time.sleep(0.5)
params = {'query' : domain, 'page' : page}
res = requests.post("https://www.censys.io/api/v1/search/ipv4", json = params, auth = (cfg.censysio_id, cfg.censysio_secret))
payload = res.json()
if 'error' not in payload.keys():
if 'results' in payload.keys():
for r in payload['results']:
temp_dict = {}
ip = r["ip"]
proto = r["protocols"]
proto = [p.split("/")[0] for p in proto]
proto.sort(key=float)
protoList = ','.join(map(str, proto))
temp_dict["ip"] = ip
temp_dict["protocols"] = protoList
#print '[%s] IP: %s - aaProtocols: %s' % (colored('*', 'red'), ip, protoList)
if '80' in protoList:
new_dict = view(ip, temp_dict)
censys_list.append(new_dict)
else:
censys_list.append(temp_dict)
pages = payload['metadata']['pages']
page += 1
else:
print "X"
return None
break
def view(server, temp_dict):
res = requests.get("https://www.censys.io/api/v1/view/ipv4/%s" % (server), auth = (cfg.censysio_id, cfg.censysio_secret))
payload = res.json()
try:
if 'title' in payload['80']['http']['get'].keys():
#print "[+] Title: %s" % payload['80']['http']['get']['title']
title = payload['80']['http']['get']['title']
temp_dict['title'] = title
if 'server' in payload['80']['http']['get']['headers'].keys():
header = "[+] Server: %s" % payload['80']['http']['get']['headers']['server']
temp_dict["server_header"] = payload['80']['http']['get']['headers']['server']
return temp_dict
except Exception as error:
print error
censys_list = []
def main():
domain = sys.argv[1]
censys_search(domain)
for x in censys_list:
print x
if __name__ == "__main__":
main()