Created
November 28, 2015 00:51
-
-
Save lamenezes/ace1dd23560a0f509827 to your computer and use it in GitHub Desktop.
ssh connection when you don't know the target IP using brute force
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent import futures | |
import paramiko | |
ssh = paramiko.SSHClient() | |
def attempt_ssh_connection(ip, timeout=5): | |
print('Attemp connection on {}'.format(ip)) | |
try: | |
ssh.connect(ip, username='pi', password='raspberry', timeout=timeout) | |
return ip | |
except: | |
return None | |
def brute_force(ips, max_workers=20, block_size=500, timeout=5): | |
total_ips = len(ips) | |
ips_blocks = [ips[block_start:block_start + block_size] | |
for block_start in range(0, total_ips, block_size)] | |
for block in ips_blocks: | |
with futures.ThreadPoolExecutor(max_workers=max_workers) as executor: | |
to_do_map = {} | |
print('ready') | |
for ip in block: | |
future = executor.submit(attempt_ssh_connection, ip) | |
to_do_map[future] = ip | |
print('steady') | |
done_iter = futures.as_completed(to_do_map) | |
print('go') | |
for future in done_iter: | |
try: | |
ip = future.result() | |
except: | |
import traceback | |
print(traceback.print_exc()) | |
continue | |
if ip: | |
print('ACHOU: {}'.format(ip)) | |
exit(1) | |
if __name__ == '__main__': | |
ips = ['10.125.{}.{}'.format(i, j) for i in range(1, 255) for j in range(1, 255)] | |
brute_force(ips) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment