diff --git a/acasown.py b/acasown.py index f10bcde..60d64c0 100644 --- a/acasown.py +++ b/acasown.py @@ -3,10 +3,10 @@ import censys import bong r = ripe.Ripe() -c = censys.Censys("dummy", "dummy") +c = censys.Censys_WEB("dummyuser", "dummypass") 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) \ No newline at end of file +for host in hosts: + print(host) \ No newline at end of file diff --git a/bong/__init__.pyc b/bong/__init__.pyc index b05a3d3..fc5a926 100644 Binary files a/bong/__init__.pyc and b/bong/__init__.pyc differ diff --git a/censys/__init__.py b/censys/__init__.py index dc37667..03580ca 100644 --- a/censys/__init__.py +++ b/censys/__init__.py @@ -1,6 +1,8 @@ import requests +from bs4 import BeautifulSoup +import re -class Censys: +class Censys_API: def __init__(self, uid, secret): self.url = 'https://censys.io/api/v1' self.uid = uid @@ -44,4 +46,57 @@ class Censys: except: vhosts = [] self.ipv4.append({'ip': host['ip'], 'protocols': host['protocols'], 'vhosts': vhosts}) + return True + +class Censys_WEB: + def __init__(self, username, password): + self.url = 'https://censys.io/' + self.username = username + self.password = password + if self.login(): + self.session = self.login() + self.ipv4 = [] + + def login(self): + s = requests.session() + requests.get(self.url) + return s + + 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_ipv4(self, query): + r = self.session.get(self.url + "ipv4/_search?q=", params={"q": query, "page": 1}) + data = r.text + '''Per usare etree bisogna fixare l'html rotto + data = "" + data + "" + data = re.sub("\.*\<\/a\>", "", data)''' + self.parse_ipv4(data) + html = BeautifulSoup(data, "lxml") + spans = html.find_all('span', {'class': 'SearchResultSectionHeader__statistic'}) + pages = int(spans[0].text.split('/')[1].strip()) + count = spans[1].text + for page in range(2, pages + 1): + r = self.session.get(self.url + "ipv4/_search?q=", params={"q": query, "page": page}) + data = r.text + self.parse_ipv4(data) + return self.ipv4 + + def parse_ipv4(self, data): + html = BeautifulSoup(data, "lxml") + vhosts = [] + protocols = [] + results = html.find_all('div', {'class': 'SearchResult result'}) + for raw in results: + 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 diff --git a/censys/__init__.pyc b/censys/__init__.pyc new file mode 100644 index 0000000..5ab086f Binary files /dev/null and b/censys/__init__.pyc differ diff --git a/ripe/__init__.pyc b/ripe/__init__.pyc new file mode 100644 index 0000000..85bbdde Binary files /dev/null and b/ripe/__init__.pyc differ