First working rel

This commit is contained in:
Giulio 2018-11-09 00:30:20 +01:00
parent 36e8ead932
commit 8a0e31a66a
6 changed files with 53 additions and 19 deletions

View File

@ -1,12 +1,27 @@
import ripe import ripe
import censys import censys
import bong import bong
import sys
import json
r = ripe.Ripe() r = ripe.Ripe()
c = censys.Censys_WEB("dummyuser", "dummypass") 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") print("Found " + str(len(targets)) + " ranges from Ripe")
hosts = c.search_ipv4(c.build_query_ipv4(targets)) hosts = c.search_ipv4(c.build_query_ipv4(targets))
print("Found " + str(len(hosts)) + " hosts from Censys") print("Found " + str(len(hosts)) + " hosts from Censys")
hosts_bing = b.search_hosts(hosts)
result = []
for host in hosts: for host in hosts:
print(host) 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))

View File

@ -2,29 +2,42 @@ import requests
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
class Bing: class Bing:
def __init__(self): def __init__(self):
self.url = 'https://www.bing.com/search' self.url = 'https://www.bing.com/search'
''' self.hosts = []
def search_hosts(self, hosts): def search_hosts(self, hosts):
for host in 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,): #print({'ip': ip, 'vhosts': vhosts, 'urls': urls})
r = requests.get(self.url, params={'q': 'ip:' + ip, 'format': 'rss', 'first': first}); self.hosts.append({'ip': ip, 'vhosts': vhosts, 'urls': urls})
tree = ET.fromstring(r.content)
return tree
def parse(self, tree): def parse(self, tree):
urls = []
vhosts = []
count = 0 count = 0
for i in tree[0]: for i in tree[0]:
if i.tag == 'item': if i.tag == 'item':
count += 1 count += 1
print(i[1].text) url = i[1].text
if url not in urls:
urls.append(url)
if count == 10: return urls
return 1
else:
return 0
'''

Binary file not shown.

View File

@ -88,15 +88,21 @@ class Censys_WEB:
def parse_ipv4(self, data): def parse_ipv4(self, data):
html = BeautifulSoup(data, "lxml") html = BeautifulSoup(data, "lxml")
vhosts = []
protocols = []
results = html.find_all('div', {'class': 'SearchResult result'}) results = html.find_all('div', {'class': 'SearchResult result'})
for raw in results: for raw in results:
vhosts = []
urls = []
protocols = []
ip = raw.find_all('span', {'class': 'dns'})[0].get('id') ip = raw.find_all('span', {'class': 'dns'})[0].get('id')
vhosts_html = raw.find_all('i', {'title': 'names on certificate'}) vhosts_html = raw.find_all('i', {'title': 'names on certificate'})
if vhosts_html: if vhosts_html:
l = vhosts_html[0].next_sibling.replace(' ', '') l = vhosts_html[0].next_sibling.replace(' ', '')
for vhost in l.split(','): for vhost in l.split(','):
vhosts.append(vhost) vhosts.append(vhost)
self.ipv4.append({'ip': ip, 'protocols': protocols, 'vhosts': vhosts}) 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 return True

Binary file not shown.

Binary file not shown.