Censys module and Bing draft

This commit is contained in:
Giulio 2018-11-08 15:55:24 +01:00
parent 65a8744060
commit 45a26b6db9
6 changed files with 77 additions and 8 deletions

View File

@ -3,4 +3,10 @@ import censys
import bong
r = ripe.Ripe()
print(r.search("trenitalia"))
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)

View File

@ -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
'''

BIN
bong/__init__.pyc Normal file

Binary file not shown.

View File

@ -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

View File

@ -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

0
webtech/__init__.py Normal file
View File