Censys module and Bing draft
This commit is contained in:
parent
65a8744060
commit
45a26b6db9
@ -3,4 +3,10 @@ import censys
|
|||||||
import bong
|
import bong
|
||||||
|
|
||||||
r = ripe.Ripe()
|
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)
|
@ -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
BIN
bong/__init__.pyc
Normal file
Binary file not shown.
@ -1,15 +1,47 @@
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
class Censys:
|
class Censys:
|
||||||
def __init__(self, login, secret):
|
def __init__(self, uid, secret):
|
||||||
self.login = login
|
self.url = 'https://censys.io/api/v1'
|
||||||
self.gin = secret
|
self.uid = uid
|
||||||
|
self.secret = secret
|
||||||
|
self.login()
|
||||||
|
self.ipv4 = []
|
||||||
|
|
||||||
def login(self):
|
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
|
return True
|
||||||
|
|
||||||
def build_query(self, targets):
|
def build_query_ipv4(self, targets):
|
||||||
return True
|
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
|
return True
|
@ -8,8 +8,9 @@ class Ripe:
|
|||||||
def search(self, target):
|
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"})
|
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()
|
data = r.json()
|
||||||
|
self.parse(data)
|
||||||
total = data['result']['numFound']
|
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"})
|
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())
|
self.parse(r.json())
|
||||||
return self.ranges
|
return self.ranges
|
||||||
|
0
webtech/__init__.py
Normal file
0
webtech/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user