forked from opsdisk/pagodo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagodo.py
114 lines (87 loc) · 4.63 KB
/
pagodo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
# GPL v 3.0 License
# Opsdisk LLC | opsdisk.com
from __future__ import print_function
import argparse
import os
import random
import sys
import time
import numpy
import google # google >= 1.9.3, https://pypi.python.org/pypi/google
class Pagodo:
def __init__(self, domain, google_dorks, search_max, save_links, delay, jitter):
self.domain = domain
with open(google_dorks) as self.fp:
self.google_dorks = self.fp.read().splitlines()
self.search_max = search_max
self.save_links = save_links
if save_links:
self.log_file = 'pagodo_results_' + get_timestamp() + '.txt'
self.delay = delay
# Create an array of jitter values to add to delay, favoring longer search times.
self.jitter = numpy.random.uniform(low=self.delay, high=jitter * self.delay, size=(50,))
self.total_dorks = 0
def go(self):
i = 1
for dork in self.google_dorks:
try:
dork = dork.strip()
self.links = [] # Stores URLs with files, clear out for each dork
# Search for the links to collect
if self.domain:
query = dork + " site:" + self.domain
else:
query = dork
pause_time = self.delay + random.choice(self.jitter)
print("[*] Search ( " + str(i) + " / " + str(len(self.google_dorks)) + " ) for Google dork [ " + query + " ] and waiting " + str(pause_time) + " seconds between searches")
for url in google.search(query, start=0, stop=self.search_max, num=100, pause=pause_time, extra_params={'filter': '0'}, user_agent=google.get_random_user_agent()):
self.links.append(url)
# Since google.search method retreives URLs in batches of 100, ensure the file list only contains the requested amount
if len(self.links) > self.search_max:
self.links = self.links[:-(len(self.links) - self.search_max)]
print("[*] Results: " + str(len(self.links)) + " sites found for Google dork: " + dork)
for foundDork in self.links:
print(foundDork)
self.total_dorks += len(self.links)
# Only save links with valid results to an output file
if self.save_links and (self.links):
f = open(self.log_file, 'a')
f.write('#: ' + dork + "\n")
for link in self.links:
f.write(link + "\n")
f.write("=" * 50 + "\n")
f.close
except:
print("[-] ERROR with dork: " + dork)
i += 1
self.fp.close
print("[*] Total dorks found: " + str(self.total_dorks))
def get_timestamp():
now = time.localtime()
timestamp = time.strftime('%Y%m%d_%H%M%S', now)
return timestamp
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Passive Google Dork - pagodo')
parser.add_argument('-d', dest='domain', action='store', required=False, help='Domain to search for Google dork hits.')
parser.add_argument('-g', dest='google_dorks', action='store', required=True, help='File containing Google dorks, 1 per line.')
parser.add_argument('-j', dest='jitter', action='store', type=float, default=.75, help='jitter factor (multipled times delay value) added to randomize lookups times. Default: 1.50')
parser.add_argument('-l', dest='search_max', action='store', type=int, default=100, help='Maximum results to search (default 100).')
parser.add_argument('-s', dest='save_links', action='store_true', default=False, help='Save the html links to pagodo_results__<TIMESTAMP>.txt file.')
parser.add_argument('-e', dest='delay', action='store', type=float, default=30.0, help='Minimum delay (in seconds) between searches...jitter (up to [jitter X delay] value) is added to this value to randomize lookups. If it\'s too small Google may block your IP, too big and your search may take a while. Default: 30.0')
args = parser.parse_args()
if not os.path.exists(args.google_dorks):
print("[!] Specify a valid file containing Google dorks with -g")
sys.exit()
if args.delay < 0:
print("[!] Delay must be greater than 0")
sys.exit()
'''if args.jitter < 0:
print("[!] Jitter must be greater than 0")
sys.exit()'''
#print(vars(args))
print("[*] Initiation timestamp: " + get_timestamp())
pgd = Pagodo(**vars(args))
pgd.go()
print("[*] Completion timestamp: " + get_timestamp())
print("[+] Done!")