Skip to content

Commit

Permalink
Code refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
OSINT-TECHNOLOGIES authored Oct 15, 2024
1 parent 662b665 commit 5c8ad66
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions dorking/dorking_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import sys
sys.path.append('service')
from config_processing import read_config
from logs_processing import logging

try:
import requests.exceptions
Expand All @@ -7,6 +10,7 @@
import re
import requests
import sqlite3
import time
import os
except ImportError as e:
print(Fore.RED + "Import error appeared. Reason: {}".format(e) + Style.RESET_ALL)
Expand All @@ -30,41 +34,51 @@ def get_columns_amount(dorking_db_path, table):
conn.close()
return row_count

def solid_google_dorking(query, pages=100):
def solid_google_dorking(query, dorking_delay, delay_step, pages=100):
try:
browser = mechanicalsoup.StatefulBrowser()
browser.open("https://www.google.com/")
browser.select_form('form[action="/search"]')
browser["q"] = str(query)
browser.submit_selected(btnName="btnG")
result_query = []
request_count = 0
for page in range(pages):
for link in browser.links():
target = link.attrs['href']
if (target.startswith('/url?') and not
target.startswith("/url?q=http://webcache.googleusercontent.com")):
target = re.sub(r"^/url\?q=([^&]*)&.*", r"\1", target)
result_query.append(target)
request_count += 1
if request_count % delay_step == 0:
time.sleep(dorking_delay)
try:
browser.follow_link(nr=page + 1)
except mechanicalsoup.LinkNotFoundError:
break

del result_query[-2:]
return result_query
except requests.exceptions.ConnectionError as e:
print(Fore.RED + "Error while establishing connection with domain. No results will appear. Reason: {}".format(e) + Style.RESET_ALL)
print(Fore.RED + "Error while establishing connection with domain. No results will appear. See journal for details" + Style.RESET_ALL)
logging.error(f'DORKING PROCESSING: ERROR. REASON: {e}')

def save_results_to_txt(folderpath, table, queries, pages=10):
try:
config_values = read_config()
dorking_delay = int(config_values['dorking_delay (secs)'])
delay_step = int(config_values['delay_step'])
txt_writepath = folderpath + '//04-dorking_results.txt'
total_results = []
total_dorks_amount = len(queries)
with open(txt_writepath, 'w') as f:
print(Fore.GREEN + "Started Google Dorking. Please, be patient, it may take some time")
print(Fore.GREEN + f"{dorking_delay} seconds delay after each {delay_step} dorking requests was configured" + Style.RESET_ALL)
dorked_query_counter = 0
for i, query in enumerate(queries, start=1):
f.write(f"QUERY #{i}: {query}\n")
results = solid_google_dorking(query, pages)
results = solid_google_dorking(query, dorking_delay, delay_step, pages)
if not results:
f.write("=> NO RESULT FOUND\n")
total_results.append((query, 0))
Expand All @@ -82,12 +96,17 @@ def save_results_to_txt(folderpath, table, queries, pages=10):
count = 'no results'
print(Fore.GREEN + f"[+] Found results for " + Fore.LIGHTCYAN_EX + f'{query}' + Fore.GREEN + ' query: ' + Fore.LIGHTCYAN_EX + f'{count}' + Style.RESET_ALL)
return f'Successfully dorked domain with {table.upper()} dorks table', txt_writepath
except Exception:
except Exception as e:
print(Fore.RED + 'Error appeared while trying to dork target. See journal for details')
logging.error(f'DORKING PROCESSING: ERROR. REASON: {e}')
return 'Domain dorking failed. See journal for details', txt_writepath

def transfer_results_to_xlsx(table, queries, pages=10):
config_values = read_config()
dorking_delay = int(config_values['dorking_delay (secs)'])
delay_step = int(config_values['delay_step'])
print(Fore.GREEN + "Started Google Dorking. Please, be patient, it may take some time")
print(Fore.GREEN + f"{dorking_delay} seconds delay after each {delay_step} dorking requests was configured" + Style.RESET_ALL)
dorked_query_counter = 0
total_dorks_amount = len(queries)
dorking_return_list = []
Expand All @@ -107,15 +126,15 @@ def transfer_results_to_xlsx(table, queries, pages=10):

def dorks_files_check():
dorks_path = 'dorking//'
dorks_files = ['iot_dorking.db', 'files_dorking.db', 'basic_dorking.db']
dorks_files = ['iot_dorking.db', 'files_dorking.db', 'basic_dorking.db', 'adminpanels_dorking.db', 'webstructure_dorking.db']
dorks_files_counter = 0
for dork_files in dorks_files:
files_path = os.path.join(dorks_path, dork_files)
if os.path.isfile(files_path):
dorks_files_counter += 1
else:
pass
if dorks_files_counter == 3:
if dorks_files_counter == 5:
print(Fore.GREEN + "Dorks databases presence: OK" + Style.RESET_ALL)
else:
print(Fore.RED + "Dorks databases presence: NOT OK\nSome files may not be in folder. Please compare dorking folder with the same folder on the official repository\n" + Style.RESET_ALL)
Expand Down

0 comments on commit 5c8ad66

Please sign in to comment.