Browse Source

First working rel

Giulio 5 years ago
parent
commit
8a0e31a66a
6 changed files with 53 additions and 19 deletions
  1. 17 2
      acasown.py
  2. 26 13
      bong/__init__.py
  3. BIN
      bong/__init__.pyc
  4. 10 4
      censys/__init__.py
  5. BIN
      censys/__init__.pyc
  6. BIN
      ripe/__init__.pyc

+ 17 - 2
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)
+	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))

+ 26 - 13
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
-'''
+		return urls

BIN
bong/__init__.pyc


+ 10 - 4
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
+			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

BIN
censys/__init__.pyc


BIN
ripe/__init__.pyc