|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | + |
| 4 | +from os import listdir |
| 5 | +from os.path import isfile, join |
| 6 | +try: |
| 7 | + from googlesearch import search # external package |
| 8 | +except ImportError: |
| 9 | + print("No module named 'google' found") |
| 10 | +import urllib |
| 11 | +import config_params |
| 12 | +from common_utils import menu_utils |
| 13 | + |
| 14 | +VERSION = '1.0' |
| 15 | + |
| 16 | +""" This module uses a Google hacking databases to facilitate dorks """ |
| 17 | + |
| 18 | + |
| 19 | +def load_google_hacks_list(): |
| 20 | + """loading the list of google hacks""" |
| 21 | + google_hacks = [f for f in listdir(config_params.GOOGLE_HACKS_FOLDER) |
| 22 | + if isfile(join(config_params.GOOGLE_HACKS_FOLDER, f))] |
| 23 | + return google_hacks |
| 24 | + |
| 25 | + |
| 26 | +def get_strings(src_file): |
| 27 | + """getting strings from file""" |
| 28 | + res = [] |
| 29 | + try: |
| 30 | + res = open(src_file,'r').readlines() |
| 31 | + res = [x.strip() for x in res] |
| 32 | + except: |
| 33 | + res = [] |
| 34 | + return res |
| 35 | + |
| 36 | + |
| 37 | +def append_sitename(strs, site): |
| 38 | + """adding site name to strings, and testing if the query returns some response""" |
| 39 | + google_hacks = [] |
| 40 | + for x in strs: |
| 41 | + google_hack = x+ ' site:'+site |
| 42 | + nres = results_in_google(google_hack) |
| 43 | + print("[+] %s results in: %s" % (nres, google_hack)) |
| 44 | + if nres > 0: |
| 45 | + google_hacks.append(google_hack) |
| 46 | + return google_hacks |
| 47 | + |
| 48 | + |
| 49 | +def save_output(strs): |
| 50 | + """printing results""" |
| 51 | + res = "\n".join(strs) |
| 52 | + print(res) |
| 53 | + |
| 54 | + |
| 55 | +def from_site(site_name, google_hack): |
| 56 | + |
| 57 | + """This creates and saves a list of Google dorks for a given site""" |
| 58 | + |
| 59 | + source_file = join(config_params.GOOGLE_HACKS_FOLDER, google_hack) |
| 60 | + menu_utils.header(source_file) |
| 61 | + |
| 62 | + if not isfile(source_file): |
| 63 | + menu_utils.error('Could not find source file!') |
| 64 | + strs = [line.rstrip('\n') for line in open(source_file)] |
| 65 | + if not strs: |
| 66 | + menu_utils.error("Can't get data from source file!") |
| 67 | + exit() |
| 68 | + |
| 69 | + if site_name: |
| 70 | + strs = append_sitename(strs,site_name) |
| 71 | + |
| 72 | + save_output(strs) |
| 73 | + |
| 74 | + |
| 75 | +def results_in_google(query): |
| 76 | + |
| 77 | + """This will return the number of results found in google using the given query""" |
| 78 | + |
| 79 | + counter = 0 |
| 80 | + try: |
| 81 | + for j in search(query, tld="com", num=1, stop=1, pause=2): |
| 82 | + counter += 1 |
| 83 | + except urllib.error.HTTPError as e: |
| 84 | + menu_utils.error(e) |
| 85 | + |
| 86 | + return counter |
0 commit comments