From 03e0404cb368b3e7aa4c982b8b1254383e671d06 Mon Sep 17 00:00:00 2001 From: Jay Townsend Date: Sat, 3 Aug 2019 14:27:31 +0100 Subject: [PATCH] WIP crtsh.py --- theHarvester/discovery/crtsh.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/theHarvester/discovery/crtsh.py b/theHarvester/discovery/crtsh.py index 3eac6736..efc2ecab 100644 --- a/theHarvester/discovery/crtsh.py +++ b/theHarvester/discovery/crtsh.py @@ -1,26 +1,26 @@ -import psycopg2 +from theHarvester.lib.core import * +import json +import requests class SearchCrtsh: def __init__(self, word): self.word = word - self.db_server = 'crt.sh' - self.db_database = 'certwatch' - self.db_user = 'guest' def do_search(self): - try: - conn = psycopg2.connect('dbname={0} user={1} host={2}'.format(self.db_database, self.db_user, self.db_server)) - conn.autocommit = True - cursor = conn.cursor() - cursor.execute( - "SELECT ci.NAME_VALUE NAME_VALUE FROM certificate_identity ci WHERE ci.NAME_TYPE = 'dNSName' AND reverse(lower(ci.NAME_VALUE)) LIKE reverse(lower('%{}'));".format( - self.word)) - except ConnectionError: - print('[!] Unable to connect to the database') - return cursor + url = f'https://crt.sh/?q=%{self.word}&output=json' + request = requests.get(url, headers={'User-Agent': Core.get_user_agent()}) + + if request.ok: + try: + content = request.content.decode('utf-8') + data = json.loads(content) + return data + except ValueError as error: + print(f'Error when requesting data from crt.sh: {error}') def process(self): self.do_search() print('\tSearching results.') +