diff --git a/acasown.py b/acasown.py index 6dff5c0..f10bcde 100644 --- a/acasown.py +++ b/acasown.py @@ -3,4 +3,10 @@ import censys import bong r = ripe.Ripe() -print(r.search("trenitalia")) \ No newline at end of file +c = censys.Censys("dummy", "dummy") +targets = r.search("trenitalia") +print("Found " + str(len(targets)) + " ranges from Ripe") +hosts = c.search_ipv4(c.build_query_ipv4(targets)) +print("Found " + str(len(hosts)) + " hosts from Censys") +for i in hosts: + print(i) \ No newline at end of file diff --git a/bong/__init__.py b/bong/__init__.py index e69de29..badb7ec 100644 --- a/bong/__init__.py +++ b/bong/__init__.py @@ -0,0 +1,30 @@ +import requests +import xml.etree.ElementTree as ET + +class Bing: + + def __init__(self): + self.url = 'https://www.bing.com/search' +''' + def search_hosts(self, hosts): + for host in hosts: + parse(search(host['ip'])) + + + def search(self, ip,): + r = requests.get(self.url, params={'q': 'ip:' + ip, 'format': 'rss', 'first': first}); + tree = ET.fromstring(r.content) + return tree + + def parse(self, tree): + count = 0 + for i in tree[0]: + if i.tag == 'item': + count += 1 + print(i[1].text) + + if count == 10: + return 1 + else: + return 0 +''' \ No newline at end of file diff --git a/bong/__init__.pyc b/bong/__init__.pyc new file mode 100644 index 0000000..b05a3d3 Binary files /dev/null and b/bong/__init__.pyc differ diff --git a/censys/__init__.py b/censys/__init__.py index fc7dc34..dc37667 100644 --- a/censys/__init__.py +++ b/censys/__init__.py @@ -1,15 +1,47 @@ import requests class Censys: - def __init__(self, login, secret): - self.login = login - self.gin = secret + def __init__(self, uid, secret): + self.url = 'https://censys.io/api/v1' + self.uid = uid + self.secret = secret + self.login() + self.ipv4 = [] def login(self): + r = requests.get(self.url + "/data", auth=(self.uid, self.secret)) + if r.status_code != 200: + print("Wrong creds for Censys") + sys.exit(1) return True - def build_query(self, targets): - return True + def build_query_ipv4(self, targets): + query = "" + for t in targets: + query += "ip:[" + t['start'] + " TO " + t['end'] + "]" + query += " OR " + return query[:-4] - def search(self, query): + def search_ipv4(self, query): + r = requests.post(self.url + "/search/ipv4", json={'query': query}, auth=(self.uid, self.secret)) + data = r.json() + self.parse_ipv4(data) + if data['status'] == 'ok': + count = data['metadata']['count'] + pages = data['metadata']['pages'] + for page in range(2, pages + 1): + r = requests.post(self.url + "/search/ipv4", json={'query': query, 'page' : page}, auth=(self.uid, self.secret)) + data = r.json() + self.parse_ipv4(data) + return self.ipv4 + + def parse_ipv4(self, data): + for host in data['results']: + r = requests.get(self.url + "/view/ipv4/" + host['ip'], auth=(self.uid, self.secret)) + data = r.json() + try: + vhosts = data['443']['https']['tls']['certificate']['parsed']['names'] + except: + vhosts = [] + self.ipv4.append({'ip': host['ip'], 'protocols': host['protocols'], 'vhosts': vhosts}) return True \ No newline at end of file diff --git a/ripe/__init__.py b/ripe/__init__.py index 018d0c8..28cbc7b 100644 --- a/ripe/__init__.py +++ b/ripe/__init__.py @@ -8,8 +8,9 @@ class Ripe: def search(self, target): r = requests.get("https://apps.db.ripe.net/db-web-ui/api/rest/fulltextsearch/select?facet=true&format=xml&hl=true&q=(" + target +")+AND+(object-type:inetnum)&start=0&wt=json", headers={"Accept": "application/json"}) data = r.json() + self.parse(data) total = data['result']['numFound'] - for i in range(0, total, 10): + for i in range(10, total, 10): r = requests.get("https://apps.db.ripe.net/db-web-ui/api/rest/fulltextsearch/select?facet=true&format=xml&hl=true&q=(" + target +")+AND+(object-type:inetnum)&start=" + str(i) + "&wt=json", headers={"Accept": "application/json"}) self.parse(r.json()) return self.ranges diff --git a/webtech/__init__.py b/webtech/__init__.py new file mode 100644 index 0000000..e69de29