forked from iobush/aws-s3-bruteforce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_comb_perm_search.py
executable file
·92 lines (75 loc) · 3.15 KB
/
run_comb_perm_search.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
#!/usr/bin/env python
import threading
import Queue
import itertools
import random, time
from progressbar import ProgressBar
from constants import *
from check_bucket import *
from logger import *
def createStringGenerator(string_options, num_chars):
for item in itertools.product(string_options, repeat=num_chars):
yield "".join(item)
def run_comb_perm_search(search):
#Create progressbar to show how many searches have been done, removing eta
search.progressbar = ProgressBar(total_items=get_num_comb_perm(string_options=search.string_options, num_chars=search.num_chars))
search.progressbar.fmt = '''%(percent)3d%% %(bar)s %(current)s/%(total_items)s %(items_per_sec)s ETA: %(eta)s'''
#Get all public butets that have been found so far
search.buckets_found = get_buckets_found(search.output_file)
#Create a string generator
search.string_generator = createStringGenerator(search.string_options, search.num_chars)
#Check and see if a start after value was provided
if search.start_after_value:
search.start_after_found = False
else:
search.start_after_found = True
#See if a stop at value is seen
if search.stop_at_value:
search.stop_at_found = False
else:
search.stop_at_found = False
my_queue = Queue.Queue()
for i in range(search.threads):
t = threading.Thread(target=search_instance, args=(search, ))
my_queue.put(t)
#Run all of the threads
while not my_queue.empty():
my_queue.get().start()
def search_instance(search):
#Run the search across all combinations/permutations
while True:
try:
bucket_name = search.string_generator.next()
#Check and see if you're at the stopping point
if search.stop_at_value == bucket_name:
search.stop_at_found = True
if search.stop_at_value and search.stop_at_found:
break
#Check and see if the starting point exists or has been found
if not search.start_after_found:
if bucket_name == search.start_after_value:
search.start_after_found = True
search.progressbar.total_items -= 1
continue
#Check the bucket
check_s3_bucket(bucket_name=bucket_name, access_key=search.access_key, secret_key=search.secret_key, output_file=search.output_file)
#Increment progress and sleep
search.progressbar()
if search.print_bucket_names:
print bucket_name
time.sleep(sleep_sec_between_attempts)
#Generator is empty...done
except StopIteration:
break
#Generator is already running for another thread
except ValueError:
pass
#Catchall for other issues
except:
pass
def get_num_comb_perm(string_options, num_chars):
"""Gets the number of combintions/permutations for the given string and number of chars"""
num_comb_perm = 0
for item in itertools.product(string_options, repeat=num_chars):
num_comb_perm += 1
return num_comb_perm