2018-12-28 08:49:56 +08:00
|
|
|
from discovery.constants import *
|
2019-01-06 17:50:07 +08:00
|
|
|
from lib.core import *
|
2019-01-11 10:09:47 +08:00
|
|
|
from parsers import myparser
|
|
|
|
import requests
|
|
|
|
import time
|
2018-12-28 08:49:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
class search_crtsh:
|
|
|
|
|
|
|
|
def __init__(self, word):
|
|
|
|
self.word = word.replace(' ', '%20')
|
|
|
|
self.results = ""
|
|
|
|
self.totalresults = ""
|
|
|
|
self.server = "https://crt.sh/?q="
|
|
|
|
self.quantity = "100"
|
|
|
|
self.counter = 0
|
|
|
|
|
|
|
|
def do_search(self):
|
|
|
|
try:
|
|
|
|
urly = self.server + self.word
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
try:
|
2019-01-06 17:50:07 +08:00
|
|
|
params = {'User-Agent': Core.get_user_agent()}
|
|
|
|
r=requests.get(urly, headers=params)
|
2018-12-28 08:49:56 +08:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
links = self.get_info(r.text)
|
|
|
|
for link in links:
|
2019-01-06 17:50:07 +08:00
|
|
|
params = {'User-Agent': Core.get_user_agent()}
|
2018-12-28 08:49:56 +08:00
|
|
|
r = requests.get(link, headers=params)
|
|
|
|
time.sleep(getDelay())
|
|
|
|
self.results = r.text
|
|
|
|
self.totalresults += self.results
|
|
|
|
|
|
|
|
"""
|
|
|
|
Function goes through text from base request and parses it for links
|
|
|
|
@param text requests text
|
|
|
|
@return list of links
|
|
|
|
"""
|
2019-01-06 17:50:07 +08:00
|
|
|
def get_info(self, text):
|
2018-12-28 08:49:56 +08:00
|
|
|
lines = []
|
|
|
|
for line in str(text).splitlines():
|
|
|
|
line = line.strip()
|
|
|
|
if 'id=' in line:
|
|
|
|
lines.append(line)
|
|
|
|
links = []
|
|
|
|
for i in range(len(lines)):
|
2019-01-11 10:09:47 +08:00
|
|
|
if i % 2 == 0: # Way html is formatted only care about every other one.
|
2018-12-28 08:49:56 +08:00
|
|
|
current = lines[i]
|
2019-01-11 10:09:47 +08:00
|
|
|
current = current[43:] # 43 is not an arbitrary number, the id number always starts at 43rd index.
|
2018-12-28 08:49:56 +08:00
|
|
|
link = ''
|
|
|
|
for ch in current:
|
|
|
|
if ch == '"':
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
link += ch
|
|
|
|
links.append(('https://crt.sh?id=' + str(link)))
|
|
|
|
return links
|
|
|
|
|
|
|
|
def get_hostnames(self):
|
2019-01-06 17:50:07 +08:00
|
|
|
rawres = myparser.Parser(self.totalresults, self.word)
|
2018-12-28 08:49:56 +08:00
|
|
|
return rawres.hostnames()
|
|
|
|
|
|
|
|
def process(self):
|
|
|
|
self.do_search()
|
2019-01-11 10:09:47 +08:00
|
|
|
print("\tSearching CRT.sh results.")
|