forked from AhrimanSefid/bitcoin-bruteforce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bruteforce.py
180 lines (150 loc) · 5.9 KB
/
bruteforce.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from bit import Key
from multiprocessing import cpu_count, Process
from requests import get
from time import sleep
with open('wallets.txt', 'r') as file:
wallets = set(file.read().split('\n'))
if '' in wallets:
wallets.remove('')
max_p = 115792089237316195423570985008687907852837564279074904382605163141518161494336
# random bruteforce
# Will randomly generate addresses
def RBF(r, sep_p):
print(f'Instance: {r + 1} - Generating random addresses...')
while True:
pk = Key()
if pk.address in wallets:
print(f'Instance: {r + 1} - Found: {pk.address}')
with open('found.txt', 'a') as result:
result.write(f'{pk.to_wif()}')
# random bruteforce output
def debug_RBF(r, sep_p):
print(f'Instance: {r + 1} - Generating random addresses...')
while True:
pk = Key()
print(f'Instance: {r + 1} - Generated: {pk.address}')
if pk.address in wallets:
print(f'Instance: {r + 1} - Found: {pk.address}')
with open('found.txt', 'a') as result:
result.write(f'{pk.to_wif()}')
# traditional bruteforce (slowest)
# Will try every INT from 0 to max possible
def TBF(r, sep_p):
sint = sep_p * r if sep_p * r != 0 else 1
mint = sep_p * (r + 1)
print(f'Instance: {r + 1} - Generating addresses...')
while sint < mint:
pk = Key.from_int(sint)
if pk.address in wallets:
print(f'Instance: {r + 1} - Found: {pk.address}')
with open('found.txt', 'a') as result:
result.write(f'{pk.to_wif()}\n')
sint += 1
print(f'Instance: {r + 1} - Done')
# online bruteforce (randomized)
def OBF():
print('Instance: 1 - Generating random addresses...')
while True:
pk = Key()
print(f'Instance: 1 - Generated: {pk.address} wif: {pk.to_wif()}')
print('Instance: 1 - Checking balance...')
try:
balance = int(get(f'https://blockchain.info/q/addressbalance/{pk.address}/').text)
except ValueError:
print(f'Instance: 1 - Error reading balance from: {pk.address}')
continue
print(f'Instance: 1 - {pk.address} has balance: {balance}')
if balance > 0:
with open('found.txt', 'a') as result:
result.write(f'{pk.to_wif()}')
print(f'Instance: 1 - Added address to found.txt')
print('Sleeping for 10 seconds...')
sleep(10)
# traditional bruteforce output
def debug_TBF(r, sep_p):
sint = sep_p * r if sep_p * r != 0 else 1
mint = sep_p * (r + 1)
print(f'Instance: {r + 1} - Generating addresses...')
while sint < mint:
pk = Key.from_int(sint)
print(f'Instance: {r + 1} - Generated: {pk.address}')
if pk.address in wallets:
print(f'Instance: {r + 1} - Found: {pk.address}')
with open('found.txt', 'a') as result:
result.write(f'{pk.to_wif()}\n')
sint += 1
print(f'Instance: {r + 1} - Done')
# optimized traditional bruteforce
# Will try every INT between 10**75 and max possibility.
# This methode is based on the best practice to get the safest address possible.
def OTBF(r, sep_p):
sint = (sep_p * r) + 10 ** 75 if r == 0 else (sep_p * r)
mint = (sep_p * (r + 1))
print(f'Instance: {r + 1} - Generating addresses...')
while sint < mint:
pk = Key.from_int(sint)
if pk.address in wallets:
print(f'Instance: {r + 1} - Found: {pk.address}')
with open('found.txt', 'a') as result:
result.write(f'{pk.to_wif()}\n')
sint += 1
print(f'Instance: {r + 1} - Done')
# optimized traditional bruteforce ouput
def debug_OTBF(r, sep_p):
sint = (sep_p * r) + 10 ** 75 if r == 0 else (sep_p * r)
mint = (sep_p * (r + 1))
print(f'Instance: {r + 1} - Generating addresses...')
while sint < mint:
pk = Key.from_int(sint)
print(f'Instance: {r + 1} - Generated: {pk.address}')
if pk.address in wallets:
print(f'Instance: {r + 1} - Found: {pk.address}')
with open('found.txt', 'a') as result:
result.write(f'{pk.to_wif()}\n')
sint += 1
print(f'Instance: {r + 1} - Done')
def main():
# set bruteforce mode
mode = (None, RBF, TBF, OTBF, OBF, debug_RBF, debug_TBF, debug_OTBF)
# print menu
menu_string = 'Select bruteforce mode:\n'
for count, function in enumerate(mode):
try:
if 'debug' in function.__name__:
menu_string += f'{count} - {function.__name__} (Prints output)\n'
else:
menu_string += f'{count} - {function.__name__}\n'
except AttributeError:
menu_string += f'{count} - Exit\n'
print(menu_string)
try:
choice = int(input('> '))
if choice == 4:
option = 4
cpu_cores = 1
elif choice != 0:
print(f'How many cores do you want to use ({cpu_count()} available)')
cpu_cores = int(input('> '))
cpu_cores = cpu_cores if 0 < cpu_cores < cpu_count() else cpu_count()
option = choice if 0 < choice <= len(mode) - 1 else 0
else:
option = 0
cpu_cores = 0
except ValueError:
option = 0
cpu_cores = 0
if mode[option] and mode[option].__name__ != 'OBF':
print(f'Starting bruteforce instances in mode: {mode[option].__name__} with {cpu_cores} core(s)\n')
instances = []
for i in range(cpu_cores):
instance = Process(target=mode[option], args=(i, round(max_p / cpu_cores)))
instances.append(instance)
instance.start()
for instance in instances:
instance.join()
elif mode[option].__name__ == 'OBF':
print(f'Starting bruteforce in mode: {mode[option].__name__} (6 per minute to respect API rate limit)\n')
OBF()
print('Stopping...')
if __name__ == '__main__':
main()