diff --git a/acasown.py b/acasown.py index 60d64c0..4662586 100644 --- a/acasown.py +++ b/acasown.py @@ -1,12 +1,27 @@ import ripe import censys import bong +import sys +import json r = ripe.Ripe() c = censys.Censys_WEB("dummyuser", "dummypass") -targets = r.search("trenitalia") +b = bong.Bing() +targets = r.search(sys.argv[1]) 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") +hosts_bing = b.search_hosts(hosts) +result = [] for host in hosts: - print(host) \ No newline at end of file + result_ip = host['ip'] + result_vhosts = host['vhosts'] + result_urls = [] + for host_bing in hosts_bing: + if host_bing['ip'] == result_ip: + result_urls = host_bing['urls'] + for vhost in host_bing['vhosts']: + if vhost not in result_vhosts: + result_vhosts.append(vhost) + result.append({'ip': result_ip, 'urls': result_urls, 'vhosts': result_vhosts, 'protocols': host['protocols']}) +print(json.dumps(result)) \ No newline at end of file diff --git a/bong/__init__.py b/bong/__init__.py index badb7ec..e032bca 100644 --- a/bong/__init__.py +++ b/bong/__init__.py @@ -2,29 +2,42 @@ import requests import xml.etree.ElementTree as ET class Bing: - def __init__(self): self.url = 'https://www.bing.com/search' -''' + self.hosts = [] + + def search_hosts(self, hosts): for host in hosts: - parse(search(host['ip'])) + self.search(host['ip'], 1) + return self.hosts + def search(self, ip, first): + for first in range(1, 200, 10): + urls = [] + vhosts = [] + r = requests.get(self.url, params={'q': 'ip:' + ip, 'format': 'rss', 'first': first}) + tree = ET.fromstring(r.content) + urls = self.parse(tree) + if len(urls) < 10: + break + for u in urls: + vhost = u.rsplit('/')[2] + if vhost not in vhosts: + vhosts.append(vhost) - def search(self, ip,): - r = requests.get(self.url, params={'q': 'ip:' + ip, 'format': 'rss', 'first': first}); - tree = ET.fromstring(r.content) - return tree + #print({'ip': ip, 'vhosts': vhosts, 'urls': urls}) + self.hosts.append({'ip': ip, 'vhosts': vhosts, 'urls': urls}) def parse(self, tree): + urls = [] + vhosts = [] count = 0 for i in tree[0]: if i.tag == 'item': count += 1 - print(i[1].text) + url = i[1].text + if url not in urls: + urls.append(url) - if count == 10: - return 1 - else: - return 0 -''' \ No newline at end of file + return urls \ No newline at end of file diff --git a/bong/__init__.pyc b/bong/__init__.pyc deleted file mode 100644 index fc5a926..0000000 Binary files a/bong/__init__.pyc and /dev/null differ diff --git a/censys/__init__.py b/censys/__init__.py index 03580ca..59e0d8a 100644 --- a/censys/__init__.py +++ b/censys/__init__.py @@ -88,15 +88,21 @@ class Censys_WEB: def parse_ipv4(self, data): html = BeautifulSoup(data, "lxml") - vhosts = [] - protocols = [] results = html.find_all('div', {'class': 'SearchResult result'}) for raw in results: + vhosts = [] + urls = [] + protocols = [] ip = raw.find_all('span', {'class': 'dns'})[0].get('id') vhosts_html = raw.find_all('i', {'title': 'names on certificate'}) if vhosts_html: l = vhosts_html[0].next_sibling.replace(' ', '') for vhost in l.split(','): vhosts.append(vhost) - self.ipv4.append({'ip': ip, 'protocols': protocols, 'vhosts': vhosts}) - return True \ No newline at end of file + protocols_html = raw.find_all('i', {'title': 'public protocols'}) + if protocols_html: + l = protocols_html[0].next_sibling.replace(' ', '') + for protocol in l.split(','): + protocols.append(protocol) + self.ipv4.append({'ip': ip, 'protocols': protocols, 'vhosts': vhosts, 'urls': urls}) + return True diff --git a/censys/__init__.pyc b/censys/__init__.pyc deleted file mode 100644 index 5ab086f..0000000 Binary files a/censys/__init__.pyc and /dev/null differ diff --git a/ripe/__init__.pyc b/ripe/__init__.pyc deleted file mode 100644 index 85bbdde..0000000 Binary files a/ripe/__init__.pyc and /dev/null differ